From 44eb989281cbfc39db669c037865347c631e9427 Mon Sep 17 00:00:00 2001 From: iusmac Date: Wed, 22 May 2024 17:54:27 +0200 Subject: [PATCH] Get the background restriction option faster Launch battery settings instead of details screen about app. Also, launch the activity at the top of the task stack instead of clearing the whole task while we're at it. Signed-off-by: iusmac --- .../github/iusmac/sevensim/ApplicationInfo.java | 15 +++++++++------ .../iusmac/sevensim/NotificationManager.java | 2 +- .../iusmac/sevensim/ui/sim/SimListFragment.java | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/com/github/iusmac/sevensim/ApplicationInfo.java b/src/com/github/iusmac/sevensim/ApplicationInfo.java index f65271d..f924c5b 100644 --- a/src/com/github/iusmac/sevensim/ApplicationInfo.java +++ b/src/com/github/iusmac/sevensim/ApplicationInfo.java @@ -83,13 +83,16 @@ public boolean isSystemApplication() { } /** - * Get the activity intent to show screen of details about this application within the built-in - * Settings app. + * Get the activity intent to show screen of battery settings for this application within the + * built-in Settings app. */ - public Intent getAppDetailsSettingsActivityIntent() { - final Intent i = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, - Uri.parse("package:" + mPackageName)); - i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); + public Intent getAppBatterySettingsActivityIntent() { + final String action = Utils.IS_AT_LEAST_S ? Settings.ACTION_VIEW_ADVANCED_POWER_USAGE_DETAIL + : "android.settings.APP_BATTERY_SETTINGS"; + final Intent i = new Intent(action, Uri.parse("package:" + mPackageName)); + // Highlight the preference fragment when launched + i.putExtra("request_ignore_background_restriction", true); + i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); return i; } diff --git a/src/com/github/iusmac/sevensim/NotificationManager.java b/src/com/github/iusmac/sevensim/NotificationManager.java index c29773f..ce94295 100644 --- a/src/com/github/iusmac/sevensim/NotificationManager.java +++ b/src/com/github/iusmac/sevensim/NotificationManager.java @@ -70,7 +70,7 @@ Notification buildForegroundServiceNotification() { */ void showBackgroundRestrictedNotification() { final PendingIntent pIntent = PendingIntent.getActivityAsUser(mContext, /*requestCode=*/ 0, - mApplicationInfo.getAppDetailsSettingsActivityIntent(), + mApplicationInfo.getAppBatterySettingsActivityIntent(), PendingIntent.FLAG_IMMUTABLE, /*options=*/ null, UserHandle.CURRENT); final String text = mResources.getString(R.string.background_restricted_notification_text); diff --git a/src/com/github/iusmac/sevensim/ui/sim/SimListFragment.java b/src/com/github/iusmac/sevensim/ui/sim/SimListFragment.java index ea590d1..feab20a 100644 --- a/src/com/github/iusmac/sevensim/ui/sim/SimListFragment.java +++ b/src/com/github/iusmac/sevensim/ui/sim/SimListFragment.java @@ -82,7 +82,7 @@ private void setupBackgroundRestrictedBanner() { .setAttentionLevel(BannerMessagePreference.AttentionLevel.HIGH) .setPositiveButtonText(R.string.background_restricted_button_prioritize_app) .setPositiveButtonOnClickListener((view) -> - startActivity(mApplicationInfoLazy.get().getAppDetailsSettingsActivityIntent())); + startActivity(mApplicationInfoLazy.get().getAppBatterySettingsActivityIntent())); } private void setupDisclaimerBanner() {