Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Snippets Groups Projects
Commit ff854b5f authored by Wesley Wang's avatar Wesley Wang Committed by YK Hung
Browse files

Sets an auto dismiss action for sticky disabled notification

 - Auto dismiss sticky disabled notification after 12 hr

Bug: 232579769
Test: atest com.android.server.power.batterysaver.BatterySaverStateMachineTest
Change-Id: I8d83c73dc48c6907c82a2c69e170aea6ecc39b35
parent 18cbeaaa
Branches
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ import com.android.server.EventLogTags; ...@@ -46,6 +46,7 @@ import com.android.server.EventLogTags;
import com.android.server.power.BatterySaverStateMachineProto; import com.android.server.power.BatterySaverStateMachineProto;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.time.Duration;
/** /**
* Decides when to enable / disable battery saver. * Decides when to enable / disable battery saver.
...@@ -106,6 +107,8 @@ public class BatterySaverStateMachine { ...@@ -106,6 +107,8 @@ public class BatterySaverStateMachine {
/** Turn off adaptive battery saver if the device has charged above this level. */ /** Turn off adaptive battery saver if the device has charged above this level. */
private static final int ADAPTIVE_AUTO_DISABLE_BATTERY_LEVEL = 80; private static final int ADAPTIVE_AUTO_DISABLE_BATTERY_LEVEL = 80;
private static final long STICKY_DISABLED_NOTIFY_TIMEOUT_MS = Duration.ofHours(12).toMillis();
private static final int STATE_OFF = BatterySaverStateMachineProto.STATE_OFF; private static final int STATE_OFF = BatterySaverStateMachineProto.STATE_OFF;
/** Turned on manually by the user. */ /** Turned on manually by the user. */
...@@ -829,7 +832,7 @@ public class BatterySaverStateMachine { ...@@ -829,7 +832,7 @@ public class BatterySaverStateMachine {
buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID, buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID,
R.string.dynamic_mode_notification_title, R.string.dynamic_mode_notification_title,
R.string.dynamic_mode_notification_summary, R.string.dynamic_mode_notification_summary,
Settings.ACTION_BATTERY_SAVER_SETTINGS), Settings.ACTION_BATTERY_SAVER_SETTINGS, 0L),
UserHandle.ALL); UserHandle.ALL);
}); });
} }
...@@ -847,7 +850,8 @@ public class BatterySaverStateMachine { ...@@ -847,7 +850,8 @@ public class BatterySaverStateMachine {
buildNotification(BATTERY_SAVER_NOTIF_CHANNEL_ID, buildNotification(BATTERY_SAVER_NOTIF_CHANNEL_ID,
R.string.battery_saver_off_notification_title, R.string.battery_saver_off_notification_title,
R.string.battery_saver_charged_notification_summary, R.string.battery_saver_charged_notification_summary,
Settings.ACTION_BATTERY_SAVER_SETTINGS), Settings.ACTION_BATTERY_SAVER_SETTINGS,
STICKY_DISABLED_NOTIFY_TIMEOUT_MS),
UserHandle.ALL); UserHandle.ALL);
}); });
} }
...@@ -862,7 +866,7 @@ public class BatterySaverStateMachine { ...@@ -862,7 +866,7 @@ public class BatterySaverStateMachine {
} }
private Notification buildNotification(@NonNull String channelId, @StringRes int titleId, private Notification buildNotification(@NonNull String channelId, @StringRes int titleId,
@StringRes int summaryId, @NonNull String intentAction) { @StringRes int summaryId, @NonNull String intentAction, long timeoutMs) {
Resources res = mContext.getResources(); Resources res = mContext.getResources();
Intent intent = new Intent(intentAction); Intent intent = new Intent(intentAction);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
...@@ -880,6 +884,7 @@ public class BatterySaverStateMachine { ...@@ -880,6 +884,7 @@ public class BatterySaverStateMachine {
.setStyle(new Notification.BigTextStyle().bigText(summary)) .setStyle(new Notification.BigTextStyle().bigText(summary))
.setOnlyAlertOnce(true) .setOnlyAlertOnce(true)
.setAutoCancel(true) .setAutoCancel(true)
.setTimeoutAfter(timeoutMs)
.build(); .build();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment