PhoneStatusListener

This commit is contained in:
Jens 2023-04-13 00:10:21 +02:00
parent 3fc1dd1a26
commit 170dbbc7e8
5 changed files with 24 additions and 19 deletions

View File

@ -69,6 +69,7 @@
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" /> <uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-feature <uses-feature
android:name="android.hardware.telephony" android:name="android.hardware.telephony"

View File

@ -67,6 +67,7 @@
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" /> <uses-permission android:name="android.permission.ANSWER_PHONE_CALLS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-feature <uses-feature
android:name="android.hardware.telephony" android:name="android.hardware.telephony"

View File

@ -65,6 +65,7 @@
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/> <uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@ -485,6 +485,7 @@ public class ActivityPermissions extends Activity
case phoneCall: case phoneCall:
addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions); addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions);
addToArrayListUnique(Manifest.permission.PROCESS_OUTGOING_CALLS, requiredPermissions); addToArrayListUnique(Manifest.permission.PROCESS_OUTGOING_CALLS, requiredPermissions);
addToArrayListUnique(Manifest.permission.READ_CALL_LOG, requiredPermissions);
break; break;
case pointOfInterest: case pointOfInterest:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
@ -877,6 +878,7 @@ public class ActivityPermissions extends Activity
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break; break;
case Manifest.permission.PROCESS_OUTGOING_CALLS: case Manifest.permission.PROCESS_OUTGOING_CALLS:
case Manifest.permission.READ_CALL_LOG:
for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.phoneCall)) for(String ruleName : getRulesUsing(Trigger.Trigger_Enum.phoneCall))
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
break; break;

View File

@ -254,9 +254,9 @@ public class PhoneStatusListener implements AutomationListenerInterface
if(incomingCallsReceiverInstance == null) if(incomingCallsReceiverInstance == null)
{ {
if(Build.VERSION.SDK_INT >= 31) // if(Build.VERSION.SDK_INT >= 31)
incomingCallsReceiverInstance = new IncomingCallsReceiverNew(); // incomingCallsReceiverInstance = new IncomingCallsReceiverNew();
else // else
incomingCallsReceiverInstance = new IncomingCallsReceiverOld(); incomingCallsReceiverInstance = new IncomingCallsReceiverOld();
} }
@ -268,17 +268,17 @@ public class PhoneStatusListener implements AutomationListenerInterface
if(!incomingCallsReceiverActive) if(!incomingCallsReceiverActive)
{ {
Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4); Miscellaneous.logEvent("i", "PhoneStatusListener", "Starting PhoneStatusListener->incomingCallsReceiver", 4);
if(Build.VERSION.SDK_INT >= problematicAndroidLevel) // if(Build.VERSION.SDK_INT >= problematicAndroidLevel)
{ // {
IntentFilter callsFilter = new IntentFilter(); // IntentFilter callsFilter = new IntentFilter();
callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); // callsFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter); // automationService.registerReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance, callsFilter);
} // }
else // else
{ // {
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE); tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_CALL_STATE);
} // }
incomingCallsReceiverActive = true; incomingCallsReceiverActive = true;
} }
@ -302,15 +302,15 @@ public class PhoneStatusListener implements AutomationListenerInterface
if(incomingCallsReceiverActive) if(incomingCallsReceiverActive)
{ {
Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4); Miscellaneous.logEvent("i", "PhoneStatusListener", "Stopping phoneStatusListener", 4);
if(Build.VERSION.SDK_INT >= 31) // if(Build.VERSION.SDK_INT >= 31)
{ // {
automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance); // automationService.unregisterReceiver((IncomingCallsReceiverNew)incomingCallsReceiverInstance);
} // }
else // else
{ // {
TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) automationService.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE); tm.listen((IncomingCallsReceiverOld)incomingCallsReceiverInstance, PhoneStateListener.LISTEN_NONE);
} // }
incomingCallsReceiverActive = false; incomingCallsReceiverActive = false;
} }