use of com.farmerbb.taskbar.service.PowerMenuService in project Taskbar by farmerbb.
the class U method sendAccessibilityAction.
public static void sendAccessibilityAction(Context context, int action, Runnable onComplete) {
setComponentEnabled(context, PowerMenuService.class, true);
boolean isAccessibilityServiceEnabled = isAccessibilityServiceEnabled(context);
if (!isAccessibilityServiceEnabled && hasWriteSecureSettingsPermission(context)) {
String services = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
String finalServices = services == null ? "" : services;
String powerMenuService = new ComponentName(context, PowerMenuService.class).flattenToString();
if (!finalServices.contains(powerMenuService)) {
try {
Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, finalServices.isEmpty() ? powerMenuService : finalServices + ":" + powerMenuService);
} catch (Exception ignored) {
}
}
newHandler().postDelayed(() -> {
Intent intent = new Intent(ACTION_ACCESSIBILITY_ACTION);
intent.putExtra(EXTRA_ACTION, action);
sendBroadcast(context, intent);
try {
Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, finalServices);
} catch (Exception ignored) {
}
if (onComplete != null)
onComplete.run();
}, 100);
} else if (isAccessibilityServiceEnabled) {
Intent intent = new Intent(ACTION_ACCESSIBILITY_ACTION);
intent.putExtra(EXTRA_ACTION, action);
sendBroadcast(context, intent);
if (onComplete != null)
onComplete.run();
} else {
launchApp(context, () -> {
Intent intent = new Intent(context, DummyActivity.class);
intent.putExtra("accessibility", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);
try {
context.startActivity(intent, getActivityOptionsBundle(context, ApplicationType.APP_PORTRAIT, null));
} catch (IllegalArgumentException | SecurityException ignored) {
}
});
}
}
Aggregations