Merge "Avoid lock inversion." into qt-qpr1-dev

This commit is contained in:
TreeHugger Robot
2019-12-17 21:27:34 +00:00
committed by Android (Google) Code Review

View File

@@ -773,9 +773,9 @@ public class BatterySaverStateMachine {
// Handle triggering the notification to show/hide when appropriate // Handle triggering the notification to show/hide when appropriate
if (intReason == BatterySaverController.REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_ON) { if (intReason == BatterySaverController.REASON_DYNAMIC_POWER_SAVINGS_AUTOMATIC_ON) {
runOnBgThread(this::triggerDynamicModeNotification); triggerDynamicModeNotification();
} else if (!enable) { } else if (!enable) {
runOnBgThread(this::hideDynamicModeNotification); hideDynamicModeNotification();
} }
if (DEBUG) { if (DEBUG) {
@@ -787,20 +787,28 @@ public class BatterySaverStateMachine {
@VisibleForTesting @VisibleForTesting
void triggerDynamicModeNotification() { void triggerDynamicModeNotification() {
// The current lock is the PowerManager lock, which sits very low in the service lock
// hierarchy. We shouldn't call out to NotificationManager with the PowerManager lock.
runOnBgThread(() -> {
NotificationManager manager = mContext.getSystemService(NotificationManager.class); NotificationManager manager = mContext.getSystemService(NotificationManager.class);
ensureNotificationChannelExists(manager, DYNAMIC_MODE_NOTIF_CHANNEL_ID, ensureNotificationChannelExists(manager, DYNAMIC_MODE_NOTIF_CHANNEL_ID,
R.string.dynamic_mode_notification_channel_name); R.string.dynamic_mode_notification_channel_name);
manager.notifyAsUser(TAG, DYNAMIC_MODE_NOTIFICATION_ID, manager.notifyAsUser(TAG, DYNAMIC_MODE_NOTIFICATION_ID,
buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID, buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID,
mContext.getResources().getString(R.string.dynamic_mode_notification_title), mContext.getResources().getString(
R.string.dynamic_mode_notification_title),
R.string.dynamic_mode_notification_summary, R.string.dynamic_mode_notification_summary,
Intent.ACTION_POWER_USAGE_SUMMARY), Intent.ACTION_POWER_USAGE_SUMMARY),
UserHandle.ALL); UserHandle.ALL);
});
} }
@VisibleForTesting @VisibleForTesting
void triggerStickyDisabledNotification() { void triggerStickyDisabledNotification() {
// The current lock is the PowerManager lock, which sits very low in the service lock
// hierarchy. We shouldn't call out to NotificationManager with the PowerManager lock.
runOnBgThread(() -> {
NotificationManager manager = mContext.getSystemService(NotificationManager.class); NotificationManager manager = mContext.getSystemService(NotificationManager.class);
ensureNotificationChannelExists(manager, BATTERY_SAVER_NOTIF_CHANNEL_ID, ensureNotificationChannelExists(manager, BATTERY_SAVER_NOTIF_CHANNEL_ID,
R.string.battery_saver_notification_channel_name); R.string.battery_saver_notification_channel_name);
@@ -814,6 +822,7 @@ public class BatterySaverStateMachine {
R.string.battery_saver_off_notification_summary, R.string.battery_saver_off_notification_summary,
Settings.ACTION_BATTERY_SAVER_SETTINGS), Settings.ACTION_BATTERY_SAVER_SETTINGS),
UserHandle.ALL); UserHandle.ALL);
});
} }
private void ensureNotificationChannelExists(NotificationManager manager, private void ensureNotificationChannelExists(NotificationManager manager,
@@ -854,8 +863,12 @@ public class BatterySaverStateMachine {
} }
private void hideNotification(int notificationId) { private void hideNotification(int notificationId) {
// The current lock is the PowerManager lock, which sits very low in the service lock
// hierarchy. We shouldn't call out to NotificationManager with the PowerManager lock.
runOnBgThread(() -> {
NotificationManager manager = mContext.getSystemService(NotificationManager.class); NotificationManager manager = mContext.getSystemService(NotificationManager.class);
manager.cancel(notificationId); manager.cancelAsUser(TAG, notificationId, UserHandle.ALL);
});
} }
private void setStickyActive(boolean active) { private void setStickyActive(boolean active) {