From 170dbbc7e8a4e6fa1b768024e6294ba52bef880a Mon Sep 17 00:00:00 2001 From: Jens Date: Thu, 13 Apr 2023 00:10:21 +0200 Subject: [PATCH] PhoneStatusListener --- app/src/apkFlavor/AndroidManifest.xml | 1 + app/src/fdroidFlavor/AndroidManifest.xml | 1 + app/src/googlePlayFlavor/AndroidManifest.xml | 1 + .../jens/automation2/ActivityPermissions.java | 2 + .../receivers/PhoneStatusListener.java | 38 +++++++++---------- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index eb3d75a5..2b9914e5 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -69,6 +69,7 @@ + + + = Build.VERSION_CODES.Q) @@ -877,6 +878,7 @@ public class ActivityPermissions extends Activity usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); break; case Manifest.permission.PROCESS_OUTGOING_CALLS: + case Manifest.permission.READ_CALL_LOG: for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.phoneCall)) usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); break; diff --git a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java index 0addc3ea..be3cc419 100644 --- a/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java +++ b/app/src/main/java/com/jens/automation2/receivers/PhoneStatusListener.java @@ -254,9 +254,9 @@ public class PhoneStatusListener implements AutomationListenerInterface if(incomingCallsReceiverInstance == null) { - if(Build.VERSION.SDK_INT >= 31) - incomingCallsReceiverInstance = new IncomingCallsReceiverNew(); - else +// if(Build.VERSION.SDK_INT >= 31) +// incomingCallsReceiverInstance = new IncomingCallsReceiverNew(); +// else incomingCallsReceiverInstance = new IncomingCallsReceiverOld(); } @@ -268,17 +268,17 @@ public class PhoneStatusListener implements AutomationListenerInterface if(!incomingCallsReceiverActive) { Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4); - if(Build.VERSION.SDK_INT >= problematicAndroidLevel) - { - IntentFilter callsFilter = new IntentFilter(); - callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); - automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter); - } - else - { +// if(Build.VERSION.SDK_INT >= problematicAndroidLevel) +// { +// IntentFilter callsFilter = new IntentFilter(); +// callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); +// automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter); +// } +// else +// { TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE); tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE); - } +// } incomingCallsReceiverActive = true; } @@ -302,15 +302,15 @@ public class PhoneStatusListener implements AutomationListenerInterface if(incomingCallsReceiverActive) { Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4); - if(Build.VERSION.SDK_INT >= 31) - { - automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance); - } - else - { +// if(Build.VERSION.SDK_INT >= 31) +// { +// automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance); +// } +// else +// { TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE); tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE); - } +// } incomingCallsReceiverActive = false; }