Accessibility API
This commit is contained in:
parent
3f76813e80
commit
ac74b52aed
@ -261,6 +261,13 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<service android:name=".MyAccessibilityService"
|
||||||
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -246,6 +246,13 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<service android:name=".MyAccessibilityService"
|
||||||
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -245,6 +245,13 @@
|
|||||||
android:exported="true"
|
android:exported="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<service android:name=".MyAccessibilityService"
|
||||||
|
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.accessibilityservice.AccessibilityService" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -56,6 +56,7 @@ public class Action
|
|||||||
startPhoneCall,
|
startPhoneCall,
|
||||||
stopPhoneCall,
|
stopPhoneCall,
|
||||||
copyToClipboard,
|
copyToClipboard,
|
||||||
|
takeScreenshot,
|
||||||
sendTextMessage;
|
sendTextMessage;
|
||||||
|
|
||||||
public String getFullName(Context context)
|
public String getFullName(Context context)
|
||||||
@ -140,6 +141,9 @@ public class Action
|
|||||||
return context.getResources().getString(R.string.endPhoneCall);
|
return context.getResources().getString(R.string.endPhoneCall);
|
||||||
case copyToClipboard:
|
case copyToClipboard:
|
||||||
return context.getResources().getString(R.string.copyTextToClipboard);
|
return context.getResources().getString(R.string.copyTextToClipboard);
|
||||||
|
case takeScreenshot:
|
||||||
|
return context.getResources().getString(R.string.takeScreenshot);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
@ -307,6 +311,10 @@ public class Action
|
|||||||
break;
|
break;
|
||||||
case copyToClipboard:
|
case copyToClipboard:
|
||||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.copyTextToClipboard));
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.copyTextToClipboard));
|
||||||
|
break;
|
||||||
|
case takeScreenshot:
|
||||||
|
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.takeScreenshot));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
returnString.append(action.toString());
|
returnString.append(action.toString());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.jens.automation2;
|
package com.jens.automation2;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.accessibilityservice.AccessibilityService;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
@ -2339,4 +2340,12 @@ public class Actions
|
|||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void takeScreenshot()
|
||||||
|
{
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||||
|
{
|
||||||
|
MyAccessibilityService.getInstance().performGlobalAction(AccessibilityService.GLOBAL_ACTION_TAKE_SCREENSHOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -2126,6 +2126,8 @@ public class ActivityManageRule extends Activity
|
|||||||
}
|
}
|
||||||
else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString()))
|
else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
|
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));
|
||||||
else
|
else
|
||||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||||
}
|
}
|
||||||
@ -2352,6 +2354,12 @@ public class ActivityManageRule extends Activity
|
|||||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCopyToClipboard.class);
|
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionCopyToClipboard.class);
|
||||||
startActivityForResult(intent, requestCodeActionCopyTextToClipboardAdd);
|
startActivityForResult(intent, requestCodeActionCopyTextToClipboardAdd);
|
||||||
}
|
}
|
||||||
|
else if(Action.getActionTypesAsArray()[which].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||||
|
{
|
||||||
|
newAction.setAction(Action_Enum.takeScreenshot);
|
||||||
|
ruleToEdit.getActionSet().add(newAction);
|
||||||
|
refreshActionList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import android.os.Bundle;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -51,6 +52,7 @@ public class ActivityPermissions extends Activity
|
|||||||
private static final int requestCodeForPermissionsBatteryOptimization = 12048;
|
private static final int requestCodeForPermissionsBatteryOptimization = 12048;
|
||||||
private static final int requestCodeForPermissionNotificationAccessAndroid13 = 12049;
|
private static final int requestCodeForPermissionNotificationAccessAndroid13 = 12049;
|
||||||
private static final int requestCodeForPermissionsManageOverlay = 12050;
|
private static final int requestCodeForPermissionsManageOverlay = 12050;
|
||||||
|
private static final int requestCodeForPermissionsAccessibility = 12051;
|
||||||
protected String[] specificPermissionsToRequest = null;
|
protected String[] specificPermissionsToRequest = null;
|
||||||
|
|
||||||
public static String intentExtraName = "permissionsToBeRequested";
|
public static String intentExtraName = "permissionsToBeRequested";
|
||||||
@ -305,6 +307,10 @@ public class ActivityPermissions extends Activity
|
|||||||
{
|
{
|
||||||
return android.provider.Settings.canDrawOverlays(Miscellaneous.getAnyContext());
|
return android.provider.Settings.canDrawOverlays(Miscellaneous.getAnyContext());
|
||||||
}
|
}
|
||||||
|
else if(s.equals(Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||||
|
{
|
||||||
|
return haveAccessibilityAccess(Miscellaneous.getAnyContext());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int res = context.checkCallingOrSelfPermission(s);
|
int res = context.checkCallingOrSelfPermission(s);
|
||||||
@ -323,11 +329,57 @@ public class ActivityPermissions extends Activity
|
|||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean haveAccessibilityAccess(Context mContext)
|
||||||
|
{
|
||||||
|
int accessibilityEnabled = 0;
|
||||||
|
|
||||||
|
final String service = mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService";
|
||||||
|
|
||||||
|
boolean accessibilityFound = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||||
|
Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
|
||||||
|
}
|
||||||
|
catch (Settings.SettingNotFoundException e)
|
||||||
|
{
|
||||||
|
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) {
|
||||||
|
TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
|
||||||
|
splitter.setString(settingValue);
|
||||||
|
while (splitter.hasNext()) {
|
||||||
|
String accessabilityService = splitter.next();
|
||||||
|
|
||||||
|
if (accessabilityService.equalsIgnoreCase(service)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessibilityFound;
|
||||||
|
}
|
||||||
|
|
||||||
public static void requestOverlay()
|
public static void requestOverlay()
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||||
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsManageOverlay);
|
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsManageOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void requestBindAccessibilityService()
|
||||||
|
{
|
||||||
|
Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
ActivityPermissions.getInstance().startActivityForResult(intent, requestCodeForPermissionsAccessibility);
|
||||||
|
}
|
||||||
|
|
||||||
public static void requestDeviceAdmin()
|
public static void requestDeviceAdmin()
|
||||||
{
|
{
|
||||||
if(!haveDeviceAdmin())
|
if(!haveDeviceAdmin())
|
||||||
@ -722,6 +774,8 @@ public class ActivityPermissions extends Activity
|
|||||||
case stopPhoneCall:
|
case stopPhoneCall:
|
||||||
addToArrayListUnique(Manifest.permission.ANSWER_PHONE_CALLS, requiredPermissions);
|
addToArrayListUnique(Manifest.permission.ANSWER_PHONE_CALLS, requiredPermissions);
|
||||||
break;
|
break;
|
||||||
|
case takeScreenshot:
|
||||||
|
addToArrayListUnique(Manifest.permission.BIND_ACCESSIBILITY_SERVICE, requiredPermissions);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -971,6 +1025,8 @@ public class ActivityPermissions extends Activity
|
|||||||
case Manifest.permission.QUERY_ALL_PACKAGES:
|
case Manifest.permission.QUERY_ALL_PACKAGES:
|
||||||
usingElements.add(getResources().getString(R.string.queryAllPackages));
|
usingElements.add(getResources().getString(R.string.queryAllPackages));
|
||||||
break;
|
break;
|
||||||
|
case Manifest.permission.BIND_ACCESSIBILITY_SERVICE:
|
||||||
|
usingElements.add(getResources().getString(R.string.bindAccessibilityService));
|
||||||
}
|
}
|
||||||
|
|
||||||
return usingElements;
|
return usingElements;
|
||||||
@ -1026,6 +1082,10 @@ public class ActivityPermissions extends Activity
|
|||||||
if (requestCode == requestCodeForPermissionsManageOverlay)
|
if (requestCode == requestCodeForPermissionsManageOverlay)
|
||||||
if(havePermission(Manifest.permission.SYSTEM_ALERT_WINDOW, ActivityPermissions.this))
|
if(havePermission(Manifest.permission.SYSTEM_ALERT_WINDOW, ActivityPermissions.this))
|
||||||
requestPermissions(cachedPermissionsToRequest, true);
|
requestPermissions(cachedPermissionsToRequest, true);
|
||||||
|
|
||||||
|
if (requestCode == requestCodeForPermissionsAccessibility)
|
||||||
|
if(havePermission(Manifest.permission.BIND_ACCESSIBILITY_SERVICE, ActivityPermissions.this))
|
||||||
|
requestPermissions(cachedPermissionsToRequest, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1107,6 +1167,22 @@ public class ActivityPermissions extends Activity
|
|||||||
diag.show();
|
diag.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (s.equalsIgnoreCase(Manifest.permission.BIND_ACCESSIBILITY_SERVICE))
|
||||||
|
{
|
||||||
|
AlertDialog diag = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.accessibilityApiPermissionHint), ActivityPermissions.this);
|
||||||
|
diag.setOnDismissListener(new DialogInterface.OnDismissListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialogInterface)
|
||||||
|
{
|
||||||
|
requiredPermissions.remove(s);
|
||||||
|
cachedPermissionsToRequest = requiredPermissions;
|
||||||
|
requestBindAccessibilityService();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
diag.show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
else if (s.equalsIgnoreCase(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE))
|
else if (s.equalsIgnoreCase(Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE))
|
||||||
{
|
{
|
||||||
if(Build.VERSION.SDK_INT >= 33)
|
if(Build.VERSION.SDK_INT >= 33)
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.jens.automation2;
|
||||||
|
|
||||||
|
import android.accessibilityservice.AccessibilityService;
|
||||||
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
|
|
||||||
|
public class MyAccessibilityService extends AccessibilityService
|
||||||
|
{
|
||||||
|
static MyAccessibilityService instance;
|
||||||
|
|
||||||
|
public static MyAccessibilityService getInstance()
|
||||||
|
{
|
||||||
|
if(instance == null)
|
||||||
|
instance = new MyAccessibilityService();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInterrupt()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -892,4 +892,7 @@
|
|||||||
<string name="method">Method</string>
|
<string name="method">Method</string>
|
||||||
<string name="methodGet" translatable="false">GET</string>
|
<string name="methodGet" translatable="false">GET</string>
|
||||||
<string name="methodPost" translatable="false">POST</string>
|
<string name="methodPost" translatable="false">POST</string>
|
||||||
|
<string name="takeScreenshot">Take screenshot</string>
|
||||||
|
<string name="bindAccessibilityService">Bind to accessibility service</string>
|
||||||
|
<string name="accessibilityApiPermissionHint">After clicking OK you\'ll be sent to a system dialog. Please select Automation there and allow "Allow accessibility API".</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user