Skip to content

Commit

Permalink
tweak: get the background restriction option faster (#22)
Browse files Browse the repository at this point in the history
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 <iusico.maxim@libero.it>
  • Loading branch information
iusmac authored May 22, 2024
1 parent 7d5da6d commit c2c64e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/com/github/iusmac/sevensim/ApplicationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/github/iusmac/sevensim/NotificationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/com/github/iusmac/sevensim/ui/sim/SimListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit c2c64e4

Please sign in to comment.