Loading packages/SystemUI/src/com/android/systemui/power/BatteryWarningEvents.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.power; import com.android.internal.logging.UiEvent; import com.android.internal.logging.UiEventLogger; /** * Events related to the battery warning. */ public class BatteryWarningEvents { /** Enums for logging low battery warning notification and dialog */ public enum LowBatteryWarningEvent implements UiEventLogger.UiEventEnum { @UiEvent(doc = "Low battery warning notification displayed") LOW_BATTERY_NOTIFICATION(1048), @UiEvent(doc = "Low battery warning notification positive button clicked") LOW_BATTERY_NOTIFICATION_TURN_ON(1049), @UiEvent(doc = "Low battery warning notification negative button clicked") LOW_BATTERY_NOTIFICATION_CANCEL(1050), @UiEvent(doc = "Low battery warning notification content clicked") LOW_BATTERY_NOTIFICATION_SETTINGS(1051), @UiEvent(doc = "Battery saver confirm dialog displayed") SAVER_CONFIRM_DIALOG(1052), @UiEvent(doc = "Battery saver confirm dialog positive button clicked") SAVER_CONFIRM_OK(1053), @UiEvent(doc = "Battery saver confirm dialog negative button clicked") SAVER_CONFIRM_CANCEL(1054), @UiEvent(doc = "Battery saver confirm dialog dismissed") SAVER_CONFIRM_DISMISS(1055); private final int mId; LowBatteryWarningEvent(int id) { mId = id; } @Override public int getId() { return mId; } } } packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +28 −4 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import android.view.WindowManager; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.settingslib.Utils; import com.android.settingslib.fuelgauge.BatterySaverUtils; Loading Loading @@ -169,6 +170,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private BatteryStateSnapshot mCurrentBatterySnapshot; private ActivityStarter mActivityStarter; private final BroadcastSender mBroadcastSender; private final UiEventLogger mUiEventLogger; private final Lazy<BatteryController> mBatteryControllerLazy; private final DialogLaunchAnimator mDialogLaunchAnimator; Loading @@ -178,7 +180,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Inject public PowerNotificationWarnings(Context context, ActivityStarter activityStarter, BroadcastSender broadcastSender, Lazy<BatteryController> batteryControllerLazy, DialogLaunchAnimator dialogLaunchAnimator) { DialogLaunchAnimator dialogLaunchAnimator, UiEventLogger uiEventLogger) { mContext = context; mNoMan = mContext.getSystemService(NotificationManager.class); mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE); Loading @@ -189,6 +191,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mBatteryControllerLazy = batteryControllerLazy; mDialogLaunchAnimator = dialogLaunchAnimator; mUseSevereDialog = mContext.getResources().getBoolean(R.bool.config_severe_battery_dialog); mUiEventLogger = uiEventLogger; } @Override Loading Loading @@ -333,6 +336,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { final Notification n = nb.build(); mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL); mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL); logEvent(BatteryWarningEvents.LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION); } private boolean showSevereLowBatteryDialog() { Loading Loading @@ -692,17 +696,25 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } else { d.setTitle(R.string.battery_saver_confirmation_title); d.setPositiveButton(R.string.battery_saver_confirmation_ok, (dialog, which) -> setSaverMode(true, false)); d.setNegativeButton(android.R.string.cancel, null); (dialog, which) -> { setSaverMode(true, false); logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_OK); }); d.setNegativeButton(android.R.string.cancel, (dialog, which) -> logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_CANCEL)); } d.setShowForAllUsers(true); d.setOnDismissListener((dialog) -> mSaverConfirmation = null); d.setOnDismissListener((dialog) -> { mSaverConfirmation = null; logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_DISMISS); }); WeakReference<View> ref = mBatteryControllerLazy.get().getLastPowerSaverStartView(); if (ref != null && ref.get() != null && ref.get().isAggregatedVisible()) { mDialogLaunchAnimator.showFromView(d, ref.get()); } else { d.show(); } logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_DIALOG); mSaverConfirmation = d; mBatteryControllerLazy.get().clearLastPowerSaverStartView(); } Loading Loading @@ -794,6 +806,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mActivityStarter.startActivity(intent, true /* dismissShade */); } private void logEvent(BatteryWarningEvents.LowBatteryWarningEvent event) { if (mUiEventLogger != null) { mUiEventLogger.log(event); } } private final class Receiver extends BroadcastReceiver { public void init() { Loading @@ -819,15 +837,21 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { final String action = intent.getAction(); Slog.i(TAG, "Received " + action); if (action.equals(ACTION_SHOW_BATTERY_SAVER_SETTINGS)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_SETTINGS); dismissLowBatteryNotification(); mContext.startActivityAsUser(mOpenBatterySaverSettings, UserHandle.CURRENT); } else if (action.equals(ACTION_START_SAVER)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_TURN_ON); setSaverMode(true, true); dismissLowBatteryNotification(); } else if (action.equals(ACTION_SHOW_START_SAVER_CONFIRMATION)) { dismissLowBatteryNotification(); showStartSaverConfirmation(intent.getExtras()); } else if (action.equals(ACTION_DISMISSED_WARNING)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_CANCEL); dismissLowBatteryWarning(); } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { dismissHighTemperatureWarningInternal(); Loading packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; import com.android.internal.logging.UiEventLogger; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.settingslib.fuelgauge.BatterySaverUtils; import com.android.systemui.SysuiTestCase; Loading Loading @@ -79,6 +80,8 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { @Mock private DialogLaunchAnimator mDialogLaunchAnimator; @Mock private UiEventLogger mUiEventLogger; @Mock private View mView; private BroadcastReceiver mReceiver; Loading @@ -101,7 +104,7 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { ActivityStarter starter = mDependency.injectMockDependency(ActivityStarter.class); BroadcastSender broadcastSender = mDependency.injectMockDependency(BroadcastSender.class); mPowerNotificationWarnings = new PowerNotificationWarnings(wrapper, starter, broadcastSender, () -> mBatteryController, mDialogLaunchAnimator); broadcastSender, () -> mBatteryController, mDialogLaunchAnimator, mUiEventLogger); BatteryStateSnapshot snapshot = new BatteryStateSnapshot(100, false, false, 1, BatteryManager.BATTERY_HEALTH_GOOD, 5, 15); mPowerNotificationWarnings.updateSnapshot(snapshot); Loading Loading
packages/SystemUI/src/com/android/systemui/power/BatteryWarningEvents.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.power; import com.android.internal.logging.UiEvent; import com.android.internal.logging.UiEventLogger; /** * Events related to the battery warning. */ public class BatteryWarningEvents { /** Enums for logging low battery warning notification and dialog */ public enum LowBatteryWarningEvent implements UiEventLogger.UiEventEnum { @UiEvent(doc = "Low battery warning notification displayed") LOW_BATTERY_NOTIFICATION(1048), @UiEvent(doc = "Low battery warning notification positive button clicked") LOW_BATTERY_NOTIFICATION_TURN_ON(1049), @UiEvent(doc = "Low battery warning notification negative button clicked") LOW_BATTERY_NOTIFICATION_CANCEL(1050), @UiEvent(doc = "Low battery warning notification content clicked") LOW_BATTERY_NOTIFICATION_SETTINGS(1051), @UiEvent(doc = "Battery saver confirm dialog displayed") SAVER_CONFIRM_DIALOG(1052), @UiEvent(doc = "Battery saver confirm dialog positive button clicked") SAVER_CONFIRM_OK(1053), @UiEvent(doc = "Battery saver confirm dialog negative button clicked") SAVER_CONFIRM_CANCEL(1054), @UiEvent(doc = "Battery saver confirm dialog dismissed") SAVER_CONFIRM_DISMISS(1055); private final int mId; LowBatteryWarningEvent(int id) { mId = id; } @Override public int getId() { return mId; } } }
packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +28 −4 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ import android.view.WindowManager; import androidx.annotation.VisibleForTesting; import com.android.internal.logging.UiEventLogger; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.settingslib.Utils; import com.android.settingslib.fuelgauge.BatterySaverUtils; Loading Loading @@ -169,6 +170,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private BatteryStateSnapshot mCurrentBatterySnapshot; private ActivityStarter mActivityStarter; private final BroadcastSender mBroadcastSender; private final UiEventLogger mUiEventLogger; private final Lazy<BatteryController> mBatteryControllerLazy; private final DialogLaunchAnimator mDialogLaunchAnimator; Loading @@ -178,7 +180,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { @Inject public PowerNotificationWarnings(Context context, ActivityStarter activityStarter, BroadcastSender broadcastSender, Lazy<BatteryController> batteryControllerLazy, DialogLaunchAnimator dialogLaunchAnimator) { DialogLaunchAnimator dialogLaunchAnimator, UiEventLogger uiEventLogger) { mContext = context; mNoMan = mContext.getSystemService(NotificationManager.class); mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE); Loading @@ -189,6 +191,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mBatteryControllerLazy = batteryControllerLazy; mDialogLaunchAnimator = dialogLaunchAnimator; mUseSevereDialog = mContext.getResources().getBoolean(R.bool.config_severe_battery_dialog); mUiEventLogger = uiEventLogger; } @Override Loading Loading @@ -333,6 +336,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { final Notification n = nb.build(); mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL); mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL); logEvent(BatteryWarningEvents.LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION); } private boolean showSevereLowBatteryDialog() { Loading Loading @@ -692,17 +696,25 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } else { d.setTitle(R.string.battery_saver_confirmation_title); d.setPositiveButton(R.string.battery_saver_confirmation_ok, (dialog, which) -> setSaverMode(true, false)); d.setNegativeButton(android.R.string.cancel, null); (dialog, which) -> { setSaverMode(true, false); logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_OK); }); d.setNegativeButton(android.R.string.cancel, (dialog, which) -> logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_CANCEL)); } d.setShowForAllUsers(true); d.setOnDismissListener((dialog) -> mSaverConfirmation = null); d.setOnDismissListener((dialog) -> { mSaverConfirmation = null; logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_DISMISS); }); WeakReference<View> ref = mBatteryControllerLazy.get().getLastPowerSaverStartView(); if (ref != null && ref.get() != null && ref.get().isAggregatedVisible()) { mDialogLaunchAnimator.showFromView(d, ref.get()); } else { d.show(); } logEvent(BatteryWarningEvents.LowBatteryWarningEvent.SAVER_CONFIRM_DIALOG); mSaverConfirmation = d; mBatteryControllerLazy.get().clearLastPowerSaverStartView(); } Loading Loading @@ -794,6 +806,12 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mActivityStarter.startActivity(intent, true /* dismissShade */); } private void logEvent(BatteryWarningEvents.LowBatteryWarningEvent event) { if (mUiEventLogger != null) { mUiEventLogger.log(event); } } private final class Receiver extends BroadcastReceiver { public void init() { Loading @@ -819,15 +837,21 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { final String action = intent.getAction(); Slog.i(TAG, "Received " + action); if (action.equals(ACTION_SHOW_BATTERY_SAVER_SETTINGS)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_SETTINGS); dismissLowBatteryNotification(); mContext.startActivityAsUser(mOpenBatterySaverSettings, UserHandle.CURRENT); } else if (action.equals(ACTION_START_SAVER)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_TURN_ON); setSaverMode(true, true); dismissLowBatteryNotification(); } else if (action.equals(ACTION_SHOW_START_SAVER_CONFIRMATION)) { dismissLowBatteryNotification(); showStartSaverConfirmation(intent.getExtras()); } else if (action.equals(ACTION_DISMISSED_WARNING)) { logEvent(BatteryWarningEvents .LowBatteryWarningEvent.LOW_BATTERY_NOTIFICATION_CANCEL); dismissLowBatteryWarning(); } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { dismissHighTemperatureWarningInternal(); Loading
packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java +4 −1 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; import com.android.internal.logging.UiEventLogger; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.settingslib.fuelgauge.BatterySaverUtils; import com.android.systemui.SysuiTestCase; Loading Loading @@ -79,6 +80,8 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { @Mock private DialogLaunchAnimator mDialogLaunchAnimator; @Mock private UiEventLogger mUiEventLogger; @Mock private View mView; private BroadcastReceiver mReceiver; Loading @@ -101,7 +104,7 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { ActivityStarter starter = mDependency.injectMockDependency(ActivityStarter.class); BroadcastSender broadcastSender = mDependency.injectMockDependency(BroadcastSender.class); mPowerNotificationWarnings = new PowerNotificationWarnings(wrapper, starter, broadcastSender, () -> mBatteryController, mDialogLaunchAnimator); broadcastSender, () -> mBatteryController, mDialogLaunchAnimator, mUiEventLogger); BatteryStateSnapshot snapshot = new BatteryStateSnapshot(100, false, false, 1, BatteryManager.BATTERY_HEALTH_GOOD, 5, 15); mPowerNotificationWarnings.updateSnapshot(snapshot); Loading