package com.farmerbb.taskbar.util;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActivityManager;
}
public static void sendAccessibilityAction(Context context, int action) {
+ sendAccessibilityAction(context, action, null);
+ }
+
+ public static void sendAccessibilityAction(Context context, int action, Runnable onComplete) {
ComponentName component = new ComponentName(context, PowerMenuService.class);
context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
- if(isAccessibilityServiceEnabled(context)) {
+ boolean isAccessibilityServiceEnabled = isAccessibilityServiceEnabled(context);
+
+ if(!isAccessibilityServiceEnabled
+ && hasWriteSecureSettingsPermission(context)) {
+ String notificationServices = Settings.Secure.getString(context.getContentResolver(),
+ Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
+
+ String powerMenuService = new ComponentName(context, PowerMenuService.class).flattenToString();
+
+ if(!notificationServices.contains(powerMenuService)) {
+ try {
+ Settings.Secure.putString(context.getContentResolver(),
+ Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
+ notificationServices.isEmpty()
+ ? powerMenuService
+ : notificationServices + ":" + powerMenuService);
+ } catch (Exception e) { /* Gracefully fail */ }
+ }
+
+ new Handler().postDelayed(() -> {
+ Intent intent = new Intent("com.farmerbb.taskbar.ACCESSIBILITY_ACTION");
+ intent.putExtra("action", action);
+ LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
+
+ try {
+ Settings.Secure.putString(context.getContentResolver(),
+ Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
+ notificationServices);
+ } catch (Exception e) { /* Gracefully fail */ }
+
+ if(onComplete != null) onComplete.run();
+ }, 100);
+ } else if(isAccessibilityServiceEnabled) {
Intent intent = new Intent("com.farmerbb.taskbar.ACCESSIBILITY_ACTION");
intent.putExtra("action", action);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
+
+ if(onComplete != null) onComplete.run();
} else {
launchApp(context, () -> {
Intent intent = new Intent(context, DummyActivity.class);
|| accessibilityServices.contains(component.flattenToShortString()));
}
+ public static boolean hasWriteSecureSettingsPermission(Context context) {
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
+ && context.checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) == PackageManager.PERMISSION_GRANTED;
+ }
+
public static void showToast(Context context, int message) {
showToast(context, context.getString(message), Toast.LENGTH_SHORT);
}
editor.putString("refresh_frequency", "0");
editor.putString("max_num_of_recents", "2147483647");
editor.putString("sort_order", "true");
+ editor.putString("window_size", "phone_size");
editor.putBoolean("full_length", true);
editor.putBoolean("dashboard", true);
editor.putBoolean("app_drawer_icon", true);
editor.putBoolean("button_recents", true);
editor.putBoolean("auto_hide_navbar", true);
editor.putBoolean("bliss_os_prefs", true);
-
- try {
- Settings.Secure.putString(context.getContentResolver(),
- Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
- new ComponentName(context, PowerMenuService.class).flattenToString());
- } catch (Exception e) { /* Gracefully fail */ }
-
editor.apply();
}
.putString("refresh_frequency", "0")
.putString("max_num_of_recents", "2147483647")
.putString("sort_order", "true")
+ .putString("window_size", "phone_size")
.putBoolean("full_length", true)
.putBoolean("dashboard", true)
.putBoolean("android_x86_prefs", true)