Phone Listener changed.

This commit is contained in:
jens 2021-05-13 18:37:34 +02:00
parent cddd8cfac5
commit c926c85dd0
19 changed files with 59 additions and 24 deletions

View File

@ -220,7 +220,7 @@ public class Rule implements Comparable<Rule>
private boolean checkBeforeSaving(Context context, boolean changeExistingRule)
{
if(this.getName() == null | this.getName().length()==0)
if(this.getName() == null || this.getName().length()==0)
{
Toast.makeText(context, context.getResources().getString(R.string.pleaseEnterValidName), Toast.LENGTH_LONG).show();
return false;
@ -415,13 +415,13 @@ public class Rule implements Comparable<Rule>
&&
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0
)
|
||
// Other case, start time higher than end time, timeframe goes over midnight
(
Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), oneTrigger.getTimeFrame().getTriggerTimeStop()) < 0
&&
(Miscellaneous.compareTimes(oneTrigger.getTimeFrame().getTriggerTimeStart(), nowTime) >= 0
|
||
Miscellaneous.compareTimes(nowTime, oneTrigger.getTimeFrame().getTriggerTimeStop()) > 0)
)
@ -601,11 +601,11 @@ public class Rule implements Comparable<Rule>
}
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.phoneCall))
{
if(oneTrigger.getPhoneNumber().equals("any") | oneTrigger.getPhoneNumber().equals(PhoneStatusListener.getLastPhoneNumber()))
if(oneTrigger.getPhoneNumber().equals("any") || PhoneStatusListener.getLastPhoneNumber().matches(oneTrigger.getPhoneNumber()))
{
if(PhoneStatusListener.isInACall() == oneTrigger.getTriggerParameter())
{
if(oneTrigger.getPhoneDirection() == 0 | (oneTrigger.getPhoneDirection() == PhoneStatusListener.getLastPhoneDirection()))
if(oneTrigger.getPhoneDirection() == 0 || (oneTrigger.getPhoneDirection() == PhoneStatusListener.getLastPhoneDirection()))
{
// Everything's allright
}
@ -622,7 +622,10 @@ public class Rule implements Comparable<Rule>
}
}
else
{
Miscellaneous.logEvent("i", "Rule", "Rule doesn't apply. Wrong phone number. Demanded: " + oneTrigger.getPhoneNumber() + ", got: " + PhoneStatusListener.getLastPhoneNumber(), 4);
return false;
}
}
else if(oneTrigger.getTriggerType().equals(Trigger.Trigger_Enum.nfcTag))
{
@ -916,7 +919,7 @@ public class Rule implements Comparable<Rule>
boolean notLastActive = getLastActivatedRule() == null || !getLastActivatedRule().equals(Rule.this);
boolean doToggle = ruleToggle && isActuallyToggable;
if(notLastActive | force | doToggle)
if(notLastActive || force || doToggle)
{
String message;
if(!doToggle)
@ -1069,7 +1072,7 @@ public class Rule implements Comparable<Rule>
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() > oneTrigger.getTimeFrame().getTriggerTimeStop().getTime())
{
Miscellaneous.logEvent("i", "Timeframe search", "Rule goes over midnight.", 5);
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() | searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
if(oneTrigger.getTimeFrame().getTriggerTimeStart().getTime() <= searchTime.getTime() || searchTime.getTime() <= oneTrigger.getTimeFrame().getTriggerTimeStop().getTime()+20000) //add 20 seconds because of delay
{
ruleCandidates.add(oneRule);
break innerloop; //if the poi is found we don't need to search the other triggers in the same rule

View File

@ -39,7 +39,7 @@ public class ActivityManageActionTriggerUrl extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.trigger_url_editor);
this.setContentView(R.layout.activity_manage_action_url_editor);
etTriggerUrl = (EditText)findViewById(R.id.etTriggerUrl);
etTriggerUrlUsername = (EditText)findViewById(R.id.etTriggerUrlUsername);

View File

@ -47,7 +47,7 @@ public class ActivityManagePoi extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.manage_specific_poi);
this.setContentView(R.layout.activity_manage_specific_poi);
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
bGetPosition = (Button)findViewById(R.id.bGetPosition);

View File

@ -82,7 +82,7 @@ public class ActivityManageProfile extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.manage_specific_profile);
this.setContentView(R.layout.activity_manage_specific_profile);
checkBoxChangeSoundMode = (CheckBox)findViewById(R.id.checkBoxChangeSoundMode);
checkBoxChangeVolumeMusicVideoGameMedia = (CheckBox)findViewById(R.id.checkBoxChangeVolumeMusicVideoGameMedia);

View File

@ -1396,13 +1396,16 @@ public class ActivityManageRule extends Activity
{
newAction.setAction(Action_Enum.setUsbTethering);
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1)
Toast.makeText(context, context.getResources().getString(R.string.usbTetheringFailForAboveGingerbread), Toast.LENGTH_LONG).show();
Miscellaneous.messageBox(context.getResources().getString(R.string.warning), context.getResources().getString(R.string.usbTetheringFailForAboveGingerbread), context).show();
getActionParameter1Dialog(ActivityManageRule.this).show();
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setWifiTethering.toString()))
{
newAction.setAction(Action_Enum.setWifiTethering);
getActionParameter1Dialog(ActivityManageRule.this).show();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1)
Miscellaneous.messageBox(context.getResources().getString(R.string.warning), context.getResources().getString(R.string.wifiTetheringFailForAboveNougat), context).show();
else
getActionParameter1Dialog(ActivityManageRule.this).show();
}
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.setDisplayRotation.toString()))
{

View File

@ -29,7 +29,7 @@ public class ActivityManageTriggerBluetooth extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetooth_trigger);
setContentView(R.layout.activity_manage_trigger_bluetooth);
radioAnyBluetoothDevice = (RadioButton)findViewById(R.id.radioAnyBluetoothDevice);
radioNoDevice = (RadioButton)findViewById(R.id.radioNoDevice);

View File

@ -250,7 +250,7 @@ public class ActivityManageTriggerNotification extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.manage_trigger_notification);
setContentView(R.layout.activity_manage_trigger_notification);
etNotificationTitle = (EditText)findViewById(R.id.etNotificationTitle);
etNotificationText = (EditText)findViewById(R.id.etNotificationText);

View File

@ -27,7 +27,7 @@ public class ActivityManageTriggerTimeFrame extends Activity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.manage_trigger_timeframe);
setContentView(R.layout.activity_manage_trigger_timeframe);
startPicker = (TimePicker)findViewById(R.id.tpTimeFrameStart);
stopPicker = (TimePicker)findViewById(R.id.tpTimeFrameStop);

View File

@ -225,7 +225,15 @@ public class ActivityPermissions extends Activity
}
ActivityMainScreen.updateMainScreen();
ActivityMainRules.getInstance().updateListView();
try
{
ActivityMainRules.getInstance().updateListView();
}
catch (IllegalStateException e)
{
// Activity may not have been loaded, yet.
}
}
protected static void addToArrayListUnique(String value, ArrayList<String> list)
@ -538,6 +546,13 @@ public class ActivityPermissions extends Activity
addToArrayListUnique(writeSystemSettingsPermissionName, requiredPermissions);
addToArrayListUnique("android.permission.CHANGE_NETWORK_STATE", requiredPermissions);
addToArrayListUnique("android.permission.ACCESS_NETWORK_STATE", requiredPermissions);
/*
https://stackoverflow.com/questions/46284914/how-to-enable-android-o-wifi-hotspot-programmatically
Unfortunately when requesting this permission it will be rejected automatically.
*/
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
// addToArrayListUnique("android.permission.TETHER_PRIVILEGED", requiredPermissions);
break;
case speakText:
break;
@ -1088,7 +1103,16 @@ public class ActivityPermissions extends Activity
NotificationManager mNotificationManager = (NotificationManager) Miscellaneous.getAnyContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(notificationIdPermissions);
ActivityMainScreen.updateMainScreen();
ActivityMainRules.getInstance().updateListView();
try
{
ActivityMainRules.getInstance().updateListView();
}
catch (IllegalStateException e)
{
// Activity may not have been loaded, yet.
}
this.finish();
}

View File

@ -11,6 +11,6 @@ public class ActivityTriggerPhoneCall extends Activity
protected void onCreate(@Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.trigger_phone_call);
setContentView(R.layout.activity_manage_trigger_phone_call);
}
}

View File

@ -4,6 +4,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telecom.Call;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
@ -128,8 +129,8 @@ public class PhoneStatusListener implements AutomationListenerInterface
// return false;
// case 0:
// return false;
// case 1:
// return true;
case 1:
return true;
case 2:
return true;
// case 3:
@ -166,10 +167,10 @@ public class PhoneStatusListener implements AutomationListenerInterface
return false;
}
private static void setCurrentStateIncoming(int state)
{
// Miscellaneous.logEvent("i", "Call state", "New incoming call state: " + String.valueOf(state), 4);
Miscellaneous.logEvent("i", "Call state", "New incoming call state: " + String.valueOf(state), 4);
if(currentStateIncoming != state)
{
if(lastPhoneDirection != 1)
@ -177,8 +178,10 @@ public class PhoneStatusListener implements AutomationListenerInterface
if(
(state == 0 && currentStateIncoming == 2)
|
||
(state == 2 && (currentStateIncoming == 0 | currentStateIncoming == 1))
||
state == 1 // this will enable incoming calls that have not been answered, yet, so when they are still only ringing
)
{
currentStateIncoming = state;

View File

@ -489,7 +489,8 @@
<string name="errorWritingFile">Error writing settings file.</string>
<string name="unknownError">Unknown error.</string>
<string name="noWritableFolderFound">No writable folder found to store config file.</string>
<string name="usbTetheringFailForAboveGingerbread">This will most likely not work as you\'re above Android 2.3. However you could use wifi tethering instead.</string>
<string name="usbTetheringFailForAboveGingerbread">This will most likely not work as you\'re above Android 2.3. If you\'re below Android 7 you could use wifi tethering instead instead.</string>
<string name="wifiTetheringFailForAboveNougat">This will not work anymore as you\'re above Android 7.</string>
<string name="usingNewThreadForRuleExecution">Using new thread for rule activation.</string>
<string name="startNewThreadForRuleExecution">Start new thread for rule activation.</string>
<string name="newThreadRules">New thread</string>
@ -665,5 +666,6 @@
<string name="openExamplesPage">Open webpage with examples</string>
<string name="packageName">Package name</string>
<string name="activityOrActionName">Activity/action name</string>
<string name="warning">Warning</string>
<!-- <string name="net.kollnig.missioncontrol.permission.ADMIN">Control the app Tracker Control</string>-->
</resources>