From 38644cee28af942352b9a3894d47e4e2a0216528 Mon Sep 17 00:00:00 2001 From: jens Date: Sat, 16 Dec 2023 13:52:18 +0100 Subject: [PATCH] Take screenshot action added --- app/src/apkFlavor/AndroidManifest.xml | 4 ++ app/src/fdroidFlavor/AndroidManifest.xml | 4 ++ app/src/googlePlayFlavor/AndroidManifest.xml | 4 ++ .../java/com/jens/automation2/Action.java | 3 + .../jens/automation2/ActivityManageRule.java | 2 +- .../jens/automation2/ActivityPermissions.java | 52 ++++++++++++++---- .../automation2/MyAccessibilityService.java | 22 ++++++++ app/src/main/res/drawable-hdpi/copier.png | Bin 0 -> 1771 bytes app/src/main/res/values/strings.xml | 2 + .../res/xml/config_accessibility_service.xml | 12 ++++ .../metadata/android/en-US/changelogs/138.txt | 3 +- 11 files changed, 94 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/copier.png create mode 100644 app/src/main/res/xml/config_accessibility_service.xml diff --git a/app/src/apkFlavor/AndroidManifest.xml b/app/src/apkFlavor/AndroidManifest.xml index 6f843ef..41dd23a 100644 --- a/app/src/apkFlavor/AndroidManifest.xml +++ b/app/src/apkFlavor/AndroidManifest.xml @@ -266,6 +266,10 @@ + + diff --git a/app/src/fdroidFlavor/AndroidManifest.xml b/app/src/fdroidFlavor/AndroidManifest.xml index af39e62..e02e028 100644 --- a/app/src/fdroidFlavor/AndroidManifest.xml +++ b/app/src/fdroidFlavor/AndroidManifest.xml @@ -251,6 +251,10 @@ + + diff --git a/app/src/googlePlayFlavor/AndroidManifest.xml b/app/src/googlePlayFlavor/AndroidManifest.xml index 1c67849..cbc088a 100644 --- a/app/src/googlePlayFlavor/AndroidManifest.xml +++ b/app/src/googlePlayFlavor/AndroidManifest.xml @@ -250,6 +250,10 @@ + + diff --git a/app/src/main/java/com/jens/automation2/Action.java b/app/src/main/java/com/jens/automation2/Action.java index 2c3c359..da60524 100644 --- a/app/src/main/java/com/jens/automation2/Action.java +++ b/app/src/main/java/com/jens/automation2/Action.java @@ -640,6 +640,9 @@ public class Action case copyToClipboard: Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context)); break; + case takeScreenshot: + Actions.takeScreenshot(); + break; default: Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3); break; diff --git a/app/src/main/java/com/jens/automation2/ActivityManageRule.java b/app/src/main/java/com/jens/automation2/ActivityManageRule.java index b012e1a..b5c6205 100644 --- a/app/src/main/java/com/jens/automation2/ActivityManageRule.java +++ b/app/src/main/java/com/jens/automation2/ActivityManageRule.java @@ -2127,7 +2127,7 @@ public class ActivityManageRule extends Activity else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString())) items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString())) - items.add(new Item(typesLong[i].toString(), R.drawable.clipboard)); + items.add(new Item(typesLong[i].toString(), R.drawable.copier)); else items.add(new Item(typesLong[i].toString(), R.drawable.placeholder)); } diff --git a/app/src/main/java/com/jens/automation2/ActivityPermissions.java b/app/src/main/java/com/jens/automation2/ActivityPermissions.java index 43a9c2d..87b4716 100644 --- a/app/src/main/java/com/jens/automation2/ActivityPermissions.java +++ b/app/src/main/java/com/jens/automation2/ActivityPermissions.java @@ -333,31 +333,33 @@ public class ActivityPermissions extends Activity { int accessibilityEnabled = 0; - final String service = mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService"; + final String service = mContext.getPackageName() + "/" + BuildConfig.APPLICATION_ID + ".MyAccessibilityService"; boolean accessibilityFound = false; try { accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED); - Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled); +// Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled); } catch (Settings.SettingNotFoundException e) { - Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage()); +// Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage()); } TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); - if (accessibilityEnabled == 1) { - String settingValue = Settings.Secure.getString(mContext - .getApplicationContext().getContentResolver(), - Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); - if (settingValue != null) { + if (accessibilityEnabled == 1) + { + String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); + if (settingValue != null) + { TextUtils.SimpleStringSplitter splitter = mStringColonSplitter; splitter.setString(settingValue); - while (splitter.hasNext()) { - String accessabilityService = splitter.next(); + while (splitter.hasNext()) + { + String accessibilityService = splitter.next(); - if (accessabilityService.equalsIgnoreCase(service)) { + if (accessibilityService.equalsIgnoreCase(service)) + { return true; } } @@ -1026,7 +1028,9 @@ public class ActivityPermissions extends Activity usingElements.add(getResources().getString(R.string.queryAllPackages)); break; case Manifest.permission.BIND_ACCESSIBILITY_SERVICE: - usingElements.add(getResources().getString(R.string.bindAccessibilityService)); + for(String ruleName : getRulesUsing(Action.Action_Enum.takeScreenshot)) + usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); + break; } return usingElements; @@ -1035,6 +1039,15 @@ public class ActivityPermissions extends Activity @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + /* + All of the following permissions need to be "manually" activated by the user in some + buried system menu. + In my opinion by mistake the function will be called when the user has just landed + on one of those screens, not when he exits it again. To compensate for that onResume() + is overridden. This enables the permission screen to automatically close after all + required permissions have been granted. + */ + super.onActivityResult(requestCode, resultCode, data); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) @@ -1665,4 +1678,19 @@ public class ActivityPermissions extends Activity return false; } } + + @Override + protected void onResume() + { + super.onResume(); + + for(String p : getRequiredPermissions(false)) + { + if(!havePermission(p, this)) + return; + } + + // have all + setHaveAllPermissions(); + } } \ No newline at end of file diff --git a/app/src/main/java/com/jens/automation2/MyAccessibilityService.java b/app/src/main/java/com/jens/automation2/MyAccessibilityService.java index 922c91f..79edbd1 100644 --- a/app/src/main/java/com/jens/automation2/MyAccessibilityService.java +++ b/app/src/main/java/com/jens/automation2/MyAccessibilityService.java @@ -1,8 +1,14 @@ package com.jens.automation2; import android.accessibilityservice.AccessibilityService; +import android.os.Build; +import android.util.Log; +import android.view.Display; import android.view.accessibility.AccessibilityEvent; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; + public class MyAccessibilityService extends AccessibilityService { static MyAccessibilityService instance; @@ -10,7 +16,9 @@ public class MyAccessibilityService extends AccessibilityService public static MyAccessibilityService getInstance() { if(instance == null) + { instance = new MyAccessibilityService(); + } return instance; } @@ -26,4 +34,18 @@ public class MyAccessibilityService extends AccessibilityService { } + + @Override + public void onCreate() + { + super.onCreate(); + instance = this; + } + + @Override + protected void onServiceConnected() + { + super.onServiceConnected(); + Miscellaneous.logEvent("i", "Accessibility service", "Service started.", 4); + } } \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/copier.png b/app/src/main/res/drawable-hdpi/copier.png new file mode 100644 index 0000000000000000000000000000000000000000..81257cb09d6514515183e80c4bcc6af091dcfc5c GIT binary patch literal 1771 zcmV;P)004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00009 za7bBm000XT000XT0n*)m`~Uy|2XskIMF-;s4g)3(`?WAh0000QbVXQnQ*UN;cVTj6 z08n9RZgehAMN}YmGcGkQF)%Rna-jeK1}I5HK~!i%?V4>&Q&$*(bxXEnS+f0Dw#>}G z=$zBxoC>;v2%;diAW%ywSSYkwD)L!A6$uOZH<+mTbS~ zN6ezxChDe+k8SeqeUB|uIOX21EF#^TJfVH><(_k%o^yK6y`2I8PBY#SDe;(&S5x{dTI1LoYqYZBk_+8_isDa3dLR`^9E0%=QD1^s2IC;_YWJoJ3t?Gh)C9fCZA z3Q!`%ty&0jpBaO^HVDB@3gK#?i~{7A+;=8qCai(2IeOR0)m!%K zK9r4u26$}{f}0e=m5?u)F=g%2x388M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A;g3;V#Fdw49!9GfFH|0f&?Sed2JAan-oG!j1;2__k}EN zq)Vs*Jz2x)nmjR`)(c?NMh;=wCS^*!A%MwCPs?ck)O==M6RHV@O9W@Xy1h! z(LbMsw3i?l}Zc4Bgv_S>bsd%bRU0dQ|Y*AOtrlgqUzfj95mBF=`_~ z;rGthSk{}iV!6RGET POST Take screenshot + Bind to accessibility service Bind to accessibility service After clicking OK you\'ll be sent to a system dialog. Please select Automation there and allow "Allow accessibility API". + Required for certains actions. \ No newline at end of file diff --git a/app/src/main/res/xml/config_accessibility_service.xml b/app/src/main/res/xml/config_accessibility_service.xml new file mode 100644 index 0000000..b1f0a7e --- /dev/null +++ b/app/src/main/res/xml/config_accessibility_service.xml @@ -0,0 +1,12 @@ + + \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/138.txt b/fastlane/metadata/android/en-US/changelogs/138.txt index 7c8e11a..1ccda42 100644 --- a/fastlane/metadata/android/en-US/changelogs/138.txt +++ b/fastlane/metadata/android/en-US/changelogs/138.txt @@ -1,3 +1,4 @@ * Fixed: Overlay permission for start other program action only required if startByActivity() is selected * Fixed: Broadcast receiver trigger would not trigger anything, but crash -* Added: One can now choose between GET and POST when using triggerURL action \ No newline at end of file +* Added: One can now choose between GET and POST when using triggerURL action +* Added: new action -> take screenshot \ No newline at end of file