package com.farmerbb.taskbar.util;
+import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
-import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.AlertDialog;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Surface;
-import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
}
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);
}
Bundle bundle = getActivityOptionsBundle(context, type, windowSize);
- if(shortcut == null) {
- UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
- if(userId == userManager.getSerialNumberForUser(Process.myUserHandle())) {
- try {
- startActivity(context, intent, bundle);
- } catch (ActivityNotFoundException e) {
+ prepareToStartActivity(context, () -> {
+ if(shortcut == null) {
+ UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ if(userId == userManager.getSerialNumberForUser(Process.myUserHandle())) {
+ try {
+ context.startActivity(intent, bundle);
+ } catch (ActivityNotFoundException e) {
+ launchAndroidForWork(context, intent.getComponent(), bundle, userId);
+ } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
+ } else
launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } catch (IllegalArgumentException | SecurityException e) { /* Gracefully fail */ }
} else
- launchAndroidForWork(context, intent.getComponent(), bundle, userId);
- } else
- launchShortcut(context, shortcut, bundle);
+ launchShortcut(context, shortcut, bundle);
+ });
if(shouldCollapse(context, true))
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
}
}
- private static void startActivity(Context context, Intent intent, Bundle bundle) {
+ private static void prepareToStartActivity(Context context, Runnable runnable) {
boolean shouldLaunchTouchAbsorber =
!FreeformHackHelper.getInstance().isTouchAbsorberActive()
&& isOverridingFreeformHack(context)
&& !isChromeOs(context);
if(!shouldLaunchTouchAbsorber) {
- context.startActivity(intent, bundle);
+ runnable.run();
return;
}
startTouchAbsorberActivity(context);
- new Handler().postDelayed(() -> context.startActivity(intent, bundle), 100);
+ new Handler().postDelayed(runnable, 100);
}
public static void startActivityMaximized(Context context, Intent intent) {
Bundle bundle = launchMode2(context, MAXIMIZED, ApplicationType.CONTEXT_MENU);
- startActivity(context, intent, bundle);
+ prepareToStartActivity(context, () -> context.startActivity(intent, bundle));
}
@TargetApi(Build.VERSION_CODES.N)
return Build.MANUFACTURER.equalsIgnoreCase("Samsung");
}
+ public static boolean isNvidiaDevice() {
+ return Build.MANUFACTURER.equalsIgnoreCase("NVIDIA");
+ }
+
public static boolean isServiceRunning(Context context, Class<? extends Service> cls) {
return isServiceRunning(context, cls.getName());
}
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)
|| (!isChromeOs(context) && getCurrentApiVersion() >= 28.0f));
}
- @SuppressWarnings("unchecked")
- public static <T extends View> T findViewById(Activity target, int id) {
- return (T) target.findViewById(id);
- }
-
- @SuppressWarnings("unchecked")
- public static <T extends View> T findViewById(View target, int id) {
- return (T) target.findViewById(id);
- }
-
public static boolean isPlayStoreInstalled(Context context) {
try {
context.getPackageManager().getPackageInfo("com.android.vending", 0);
public static boolean hasBrokenSetLaunchBoundsApi() {
return getCurrentApiVersion() >= 26.0f
&& getCurrentApiVersion() < 28.0f
- && !isSamsungDevice();
+ && !isSamsungDevice()
+ && !isNvidiaDevice();
}
public static String getSecondScreenPackageName(Context context) {