From e60fb1535ae23aba7b581b876a91dd5142fed0dc Mon Sep 17 00:00:00 2001 From: jens Date: Sat, 25 Sep 2021 02:03:44 +0200 Subject: [PATCH] bugspray --- .../java/com/jens/automation2/Actions.java | 69 +++++++++++++------ .../jens/automation2/ActivityPermissions.java | 4 +- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/jens/automation2/Actions.java b/app/src/main/java/com/jens/automation2/Actions.java index a0d3424..c3b83b7 100644 --- a/app/src/main/java/com/jens/automation2/Actions.java +++ b/app/src/main/java/com/jens/automation2/Actions.java @@ -1253,37 +1253,62 @@ public class Actions try { - // Get the current state of the mobile network. - state = isMobileDataEnabled() ? 0 : 1; - // Get the value of the "TRANSACTION_setDataEnabled" field. - String transactionCode = getTransactionCode(context); - // Android 5.1+ (API 22) and later. - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) + if(Build.VERSION.SDK_INT > Build.VERSION_CODES.O_MR1) { + /* + Android 8.1 is the last version on which the transaction code can be determined + with the below method. From 9.0 on the field TRANSACTION_setDataEnabled does not + exist anymore. Usually it was 83 and we'll just try this number hardcoded. + Alternatively the bottom of this might be an approach: + https://stackoverflow.com/questions/26539445/the-setmobiledataenabled-method-is-no-longer-callable-as-of-android-l-and-later + */ SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); // Loop through the subscription list i.e. SIM list. for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) { - if (transactionCode != null && transactionCode.length() > 0) - { - // Get the active subscription ID for a given SIM card. - int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId(); - // Execute the command via `su` to turn off - // mobile network for a subscription service. - command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + desiredState; - Miscellaneous.logEvent("i", "setDataConnectionWithRoot()", "Running command: " + command.toString(), 5); - return executeCommandViaSu(new String[]{command}); - } + // Get the active subscription ID for a given SIM card. + int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId(); + // Execute the command via `su` to turn off + // mobile network for a subscription service. + command = "service call phone " + "83" + " i32 " + subscriptionId + " i32 " + desiredState; + Miscellaneous.logEvent("i", "setDataConnectionWithRoot()", "Running command: " + command.toString(), 5); + return executeCommandViaSu(new String[]{command}); } } - else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) + else { - // Android 5.0 (API 21) only. - if (transactionCode != null && transactionCode.length() > 0) + // Get the current state of the mobile network. + state = isMobileDataEnabled() ? 0 : 1; + // Get the value of the "TRANSACTION_setDataEnabled" field. + String transactionCode = getTransactionCode(context); + // Android 5.1+ (API 22) and later. + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - // Execute the command via `su` to turn off mobile network. - command = "service call phone " + transactionCode + " i32 " + desiredState; - return executeCommandViaSu(new String[]{command}); + SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); + // Loop through the subscription list i.e. SIM list. + for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) + { + if (transactionCode != null && transactionCode.length() > 0) + { + // Get the active subscription ID for a given SIM card. + int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId(); + // Execute the command via `su` to turn off + // mobile network for a subscription service. + command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + desiredState; + Miscellaneous.logEvent("i", "setDataConnectionWithRoot()", "Running command: " + command.toString(), 5); + return executeCommandViaSu(new String[]{command}); + } + } + } + else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) + { + // Android 5.0 (API 21) only. + if (transactionCode != null && transactionCode.length() > 0) + { + // Execute the command via `su` to turn off mobile network. + command = "service call phone " + transactionCode + " i32 " + desiredState; + return executeCommandViaSu(new String[]{command}); + } } } } diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index 4420ab2..17b8aa5 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -411,11 +411,11 @@ public class ActivityPermissions extends Activity addToArrayListUnique(Manifest.permission.ACCESS_NETWORK_STATE, requiredPermissions); break; case charging: - addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions); +// addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions); // addToArrayListUnique("android.permission.BATTERY_STATS", requiredPermissions); break; case headsetPlugged: - addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions); +// addToArrayListUnique(Manifest.permission.READ_PHONE_STATE, requiredPermissions); break; case nfcTag: addToArrayListUnique(Manifest.permission.NFC, requiredPermissions);