Loading core/java/android/os/IPowerManager.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -55,6 +55,7 @@ interface IPowerManager void rebootSafeMode(boolean confirm, boolean wait); void rebootSafeMode(boolean confirm, boolean wait); void shutdown(boolean confirm, String reason, boolean wait); void shutdown(boolean confirm, String reason, boolean wait); void crash(String message); void crash(String message); int getLastShutdownReason(); void setStayOnSetting(int val); void setStayOnSetting(int val); void boostScreenBrightness(long time); void boostScreenBrightness(long time); Loading core/java/android/os/PowerManager.java +62 −0 Original line number Original line Diff line number Diff line Loading @@ -16,10 +16,13 @@ package android.os; package android.os; import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.annotation.SystemApi; import android.content.Context; import android.content.Context; import android.util.Log; import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** /** * This class gives you control of the power state of the device. * This class gives you control of the power state of the device. Loading Loading @@ -432,6 +435,49 @@ public final class PowerManager { */ */ public static final String SHUTDOWN_USER_REQUESTED = "userrequested"; public static final String SHUTDOWN_USER_REQUESTED = "userrequested"; /** * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ SHUTDOWN_REASON_UNKNOWN, SHUTDOWN_REASON_SHUTDOWN, SHUTDOWN_REASON_REBOOT, SHUTDOWN_REASON_USER_REQUESTED, SHUTDOWN_REASON_THERMAL_SHUTDOWN }) public @interface ShutdownReason {} /** * constant for shutdown reason being unknown. * @hide */ public static final int SHUTDOWN_REASON_UNKNOWN = 0; /** * constant for shutdown reason being normal shutdown. * @hide */ public static final int SHUTDOWN_REASON_SHUTDOWN = 1; /** * constant for shutdown reason being reboot. * @hide */ public static final int SHUTDOWN_REASON_REBOOT = 2; /** * constant for shutdown reason being user requested. * @hide */ public static final int SHUTDOWN_REASON_USER_REQUESTED = 3; /** * constant for shutdown reason being overheating. * @hide */ public static final int SHUTDOWN_REASON_THERMAL_SHUTDOWN = 4; final Context mContext; final Context mContext; final IPowerManager mService; final IPowerManager mService; final Handler mHandler; final Handler mHandler; Loading Loading @@ -1084,6 +1130,22 @@ public final class PowerManager { com.android.internal.R.bool.config_sustainedPerformanceModeSupported); com.android.internal.R.bool.config_sustainedPerformanceModeSupported); } } /** * Returns the reason the phone was last shutdown. Calling app must have the * {@link android.Manifest.permission#DEVICE_POWER} permission to request this information. * @return Reason for shutdown as an int, {@link #SHUTDOWN_REASON_UNKNOWN} if the file could * not be accessed. * @hide */ @ShutdownReason public int getLastShutdownReason() { try { return mService.getLastShutdownReason(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** /** * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. * This broadcast is only sent to registered receivers. * This broadcast is only sent to registered receivers. Loading packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +69 −17 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.util.Slog; import android.util.Slog; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; Loading Loading @@ -71,6 +72,10 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private static final String ACTION_DISMISSED_WARNING = "PNW.dismissedWarning"; private static final String ACTION_DISMISSED_WARNING = "PNW.dismissedWarning"; private static final String ACTION_CLICKED_TEMP_WARNING = "PNW.clickedTempWarning"; private static final String ACTION_CLICKED_TEMP_WARNING = "PNW.clickedTempWarning"; private static final String ACTION_DISMISSED_TEMP_WARNING = "PNW.dismissedTempWarning"; private static final String ACTION_DISMISSED_TEMP_WARNING = "PNW.dismissedTempWarning"; private static final String ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING = "PNW.clickedThermalShutdownWarning"; private static final String ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING = "PNW.dismissedThermalShutdownWarning"; private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder() private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) Loading @@ -95,8 +100,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private boolean mPlaySound; private boolean mPlaySound; private boolean mInvalidCharger; private boolean mInvalidCharger; private SystemUIDialog mSaverConfirmation; private SystemUIDialog mSaverConfirmation; private boolean mTempWarning; private boolean mHighTempWarning; private SystemUIDialog mHighTempDialog; private SystemUIDialog mHighTempDialog; private SystemUIDialog mThermalShutdownDialog; public PowerNotificationWarnings(Context context, NotificationManager notificationManager, public PowerNotificationWarnings(Context context, NotificationManager notificationManager, StatusBar statusBar) { StatusBar statusBar) { Loading @@ -113,8 +119,10 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { pw.print("mInvalidCharger="); pw.println(mInvalidCharger); pw.print("mInvalidCharger="); pw.println(mInvalidCharger); pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]); pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]); pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null); pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null); pw.print("mTempWarning="); pw.println(mTempWarning); pw.print("mHighTempWarning="); pw.println(mHighTempWarning); pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null); pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null); pw.print("mThermalShutdownDialog="); pw.println(mThermalShutdownDialog != null ? "not null" : null); } } @Override @Override Loading Loading @@ -212,29 +220,29 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } } @Override @Override public void dismissTemperatureWarning() { public void dismissHighTemperatureWarning() { if (!mTempWarning) { if (!mHighTempWarning) { return; return; } } mTempWarning = false; mHighTempWarning = false; dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); } } /** /** * Internal only version of {@link #dismissTemperatureWarning()} that simply dismisses * Internal only version of {@link #dismissHighTemperatureWarning()} that simply dismisses * the notification. As such, the notification will not show again until * the notification. As such, the notification will not show again until * {@link #dismissTemperatureWarning()} is called. * {@link #dismissHighTemperatureWarning()} is called. */ */ private void dismissTemperatureWarningInternal() { private void dismissHighTemperatureWarningInternal() { mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL); mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL); } } @Override @Override public void showTemperatureWarning() { public void showHighTemperatureWarning() { if (mTempWarning) { if (mHighTempWarning) { return; return; } } mTempWarning = true; mHighTempWarning = true; final Notification.Builder nb = final Notification.Builder nb = new Notification.Builder(mContext, NotificationChannels.ALERTS) new Notification.Builder(mContext, NotificationChannels.ALERTS) .setSmallIcon(R.drawable.ic_device_thermostat_24) .setSmallIcon(R.drawable.ic_device_thermostat_24) Loading @@ -249,10 +257,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { SystemUI.overrideNotificationAppName(mContext, nb); SystemUI.overrideNotificationAppName(mContext, nb); final Notification n = nb.build(); final Notification n = nb.build(); mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL); mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL); } } private void showTemperatureDialog() { private void showHighTemperatureDialog() { if (mHighTempDialog != null) return; if (mHighTempDialog != null) return; final SystemUIDialog d = new SystemUIDialog(mContext); final SystemUIDialog d = new SystemUIDialog(mContext); d.setIconAttribute(android.R.attr.alertDialogIcon); d.setIconAttribute(android.R.attr.alertDialogIcon); Loading @@ -265,6 +272,44 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mHighTempDialog = d; mHighTempDialog = d; } } @VisibleForTesting void dismissThermalShutdownWarning() { mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, UserHandle.ALL); } private void showThermalShutdownDialog() { if (mThermalShutdownDialog != null) return; final SystemUIDialog d = new SystemUIDialog(mContext); d.setIconAttribute(android.R.attr.alertDialogIcon); d.setTitle(R.string.thermal_shutdown_title); d.setMessage(R.string.thermal_shutdown_dialog_message); d.setPositiveButton(com.android.internal.R.string.ok, null); d.setShowForAllUsers(true); d.setOnDismissListener(dialog -> mThermalShutdownDialog = null); d.show(); mThermalShutdownDialog = d; } @Override public void showThermalShutdownWarning() { final Notification.Builder nb = new Notification.Builder(mContext, NotificationChannels.ALERTS) .setSmallIcon(R.drawable.ic_device_thermostat_24) .setWhen(0) .setShowWhen(false) .setContentTitle(mContext.getString(R.string.thermal_shutdown_title)) .setContentText(mContext.getString(R.string.thermal_shutdown_message)) .setVisibility(Notification.VISIBILITY_PUBLIC) .setContentIntent(pendingBroadcast(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING)) .setDeleteIntent( pendingBroadcast(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING)) .setColor(Utils.getColorAttr(mContext, android.R.attr.colorError)); SystemUI.overrideNotificationAppName(mContext, nb); final Notification n = nb.build(); mNoMan.notifyAsUser( TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, n, UserHandle.ALL); } @Override @Override public void updateLowBatteryWarning() { public void updateLowBatteryWarning() { updateNotification(); updateNotification(); Loading Loading @@ -380,6 +425,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { filter.addAction(ACTION_DISMISSED_WARNING); filter.addAction(ACTION_DISMISSED_WARNING); filter.addAction(ACTION_CLICKED_TEMP_WARNING); filter.addAction(ACTION_CLICKED_TEMP_WARNING); filter.addAction(ACTION_DISMISSED_TEMP_WARNING); filter.addAction(ACTION_DISMISSED_TEMP_WARNING); filter.addAction(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING); filter.addAction(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING); mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, android.Manifest.permission.STATUS_BAR_SERVICE, mHandler); android.Manifest.permission.STATUS_BAR_SERVICE, mHandler); } } Loading @@ -397,10 +444,15 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } else if (action.equals(ACTION_DISMISSED_WARNING)) { } else if (action.equals(ACTION_DISMISSED_WARNING)) { dismissLowBatteryWarning(); dismissLowBatteryWarning(); } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); showTemperatureDialog(); showHighTemperatureDialog(); } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) { } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) { dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); } else if (ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING.equals(action)) { dismissThermalShutdownWarning(); showThermalShutdownDialog(); } else if (ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING.equals(action)) { dismissThermalShutdownWarning(); } } } } } } Loading packages/SystemUI/src/com/android/systemui/power/PowerUI.java +17 −4 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.DateUtils; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; Loading Loading @@ -93,6 +94,10 @@ public class PowerUI extends SystemUI { updateBatteryWarningLevels(); updateBatteryWarningLevels(); mReceiver.init(); mReceiver.init(); // Check to see if we need to let the user know that the phone previously shut down due // to the temperature being too high. showThermalShutdownDialog(); initTemperatureWarning(); initTemperatureWarning(); } } Loading Loading @@ -256,6 +261,13 @@ public class PowerUI extends SystemUI { updateTemperatureWarning(); updateTemperatureWarning(); } } private void showThermalShutdownDialog() { if (mPowerManager.getLastShutdownReason() == PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN) { mWarnings.showThermalShutdownWarning(); } } private void updateTemperatureWarning() { private void updateTemperatureWarning() { float[] temps = mHardwarePropertiesManager.getDeviceTemperatures( float[] temps = mHardwarePropertiesManager.getDeviceTemperatures( HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, Loading @@ -268,9 +280,9 @@ public class PowerUI extends SystemUI { if (statusBar != null && !statusBar.isDeviceInVrMode() if (statusBar != null && !statusBar.isDeviceInVrMode() && temp >= mThresholdTemp) { && temp >= mThresholdTemp) { logAtTemperatureThreshold(temp); logAtTemperatureThreshold(temp); mWarnings.showTemperatureWarning(); mWarnings.showHighTemperatureWarning(); } else { } else { mWarnings.dismissTemperatureWarning(); mWarnings.dismissHighTemperatureWarning(); } } } } Loading Loading @@ -369,8 +381,9 @@ public class PowerUI extends SystemUI { void showInvalidChargerWarning(); void showInvalidChargerWarning(); void updateLowBatteryWarning(); void updateLowBatteryWarning(); boolean isInvalidChargerWarningShowing(); boolean isInvalidChargerWarningShowing(); void dismissTemperatureWarning(); void dismissHighTemperatureWarning(); void showTemperatureWarning(); void showHighTemperatureWarning(); void showThermalShutdownWarning(); void dump(PrintWriter pw); void dump(PrintWriter pw); void userSwitched(); void userSwitched(); } } Loading packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java +20 −6 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; Loading Loading @@ -129,17 +128,32 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { } } @Test @Test public void testShowTemperatureWarning_NotifyAsUser() { public void testShowHighTemperatureWarning_NotifyAsUser() { mPowerNotificationWarnings.showTemperatureWarning(); mPowerNotificationWarnings.showHighTemperatureWarning(); verify(mMockNotificationManager, times(1)) verify(mMockNotificationManager, times(1)) .notifyAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any(), any()); .notifyAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any(), any()); } } @Test @Test public void testDismissTemperatureWarning_CancelAsUser() { public void testDismissHighTemperatureWarning_CancelAsUser() { mPowerNotificationWarnings.showTemperatureWarning(); mPowerNotificationWarnings.showHighTemperatureWarning(); mPowerNotificationWarnings.dismissTemperatureWarning(); mPowerNotificationWarnings.dismissHighTemperatureWarning(); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any()); eq(SystemMessage.NOTE_HIGH_TEMP), any()); } } @Test public void testShowThermalShutdownWarning_NotifyAsUser() { mPowerNotificationWarnings.showThermalShutdownWarning(); verify(mMockNotificationManager, times(1)) .notifyAsUser(anyString(), eq(SystemMessage.NOTE_THERMAL_SHUTDOWN), any(), any()); } @Test public void testDismissThermalShutdownWarning_CancelAsUser() { mPowerNotificationWarnings.showThermalShutdownWarning(); mPowerNotificationWarnings.dismissThermalShutdownWarning(); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), eq(SystemMessage.NOTE_THERMAL_SHUTDOWN), any()); } } } Loading
core/java/android/os/IPowerManager.aidl +1 −0 Original line number Original line Diff line number Diff line Loading @@ -55,6 +55,7 @@ interface IPowerManager void rebootSafeMode(boolean confirm, boolean wait); void rebootSafeMode(boolean confirm, boolean wait); void shutdown(boolean confirm, String reason, boolean wait); void shutdown(boolean confirm, String reason, boolean wait); void crash(String message); void crash(String message); int getLastShutdownReason(); void setStayOnSetting(int val); void setStayOnSetting(int val); void boostScreenBrightness(long time); void boostScreenBrightness(long time); Loading
core/java/android/os/PowerManager.java +62 −0 Original line number Original line Diff line number Diff line Loading @@ -16,10 +16,13 @@ package android.os; package android.os; import android.annotation.IntDef; import android.annotation.SdkConstant; import android.annotation.SdkConstant; import android.annotation.SystemApi; import android.annotation.SystemApi; import android.content.Context; import android.content.Context; import android.util.Log; import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; /** /** * This class gives you control of the power state of the device. * This class gives you control of the power state of the device. Loading Loading @@ -432,6 +435,49 @@ public final class PowerManager { */ */ public static final String SHUTDOWN_USER_REQUESTED = "userrequested"; public static final String SHUTDOWN_USER_REQUESTED = "userrequested"; /** * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef({ SHUTDOWN_REASON_UNKNOWN, SHUTDOWN_REASON_SHUTDOWN, SHUTDOWN_REASON_REBOOT, SHUTDOWN_REASON_USER_REQUESTED, SHUTDOWN_REASON_THERMAL_SHUTDOWN }) public @interface ShutdownReason {} /** * constant for shutdown reason being unknown. * @hide */ public static final int SHUTDOWN_REASON_UNKNOWN = 0; /** * constant for shutdown reason being normal shutdown. * @hide */ public static final int SHUTDOWN_REASON_SHUTDOWN = 1; /** * constant for shutdown reason being reboot. * @hide */ public static final int SHUTDOWN_REASON_REBOOT = 2; /** * constant for shutdown reason being user requested. * @hide */ public static final int SHUTDOWN_REASON_USER_REQUESTED = 3; /** * constant for shutdown reason being overheating. * @hide */ public static final int SHUTDOWN_REASON_THERMAL_SHUTDOWN = 4; final Context mContext; final Context mContext; final IPowerManager mService; final IPowerManager mService; final Handler mHandler; final Handler mHandler; Loading Loading @@ -1084,6 +1130,22 @@ public final class PowerManager { com.android.internal.R.bool.config_sustainedPerformanceModeSupported); com.android.internal.R.bool.config_sustainedPerformanceModeSupported); } } /** * Returns the reason the phone was last shutdown. Calling app must have the * {@link android.Manifest.permission#DEVICE_POWER} permission to request this information. * @return Reason for shutdown as an int, {@link #SHUTDOWN_REASON_UNKNOWN} if the file could * not be accessed. * @hide */ @ShutdownReason public int getLastShutdownReason() { try { return mService.getLastShutdownReason(); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } /** /** * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. * This broadcast is only sent to registered receivers. * This broadcast is only sent to registered receivers. Loading
packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +69 −17 Original line number Original line Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.support.annotation.VisibleForTesting; import android.util.Slog; import android.util.Slog; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; Loading Loading @@ -71,6 +72,10 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private static final String ACTION_DISMISSED_WARNING = "PNW.dismissedWarning"; private static final String ACTION_DISMISSED_WARNING = "PNW.dismissedWarning"; private static final String ACTION_CLICKED_TEMP_WARNING = "PNW.clickedTempWarning"; private static final String ACTION_CLICKED_TEMP_WARNING = "PNW.clickedTempWarning"; private static final String ACTION_DISMISSED_TEMP_WARNING = "PNW.dismissedTempWarning"; private static final String ACTION_DISMISSED_TEMP_WARNING = "PNW.dismissedTempWarning"; private static final String ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING = "PNW.clickedThermalShutdownWarning"; private static final String ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING = "PNW.dismissedThermalShutdownWarning"; private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder() private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) Loading @@ -95,8 +100,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private boolean mPlaySound; private boolean mPlaySound; private boolean mInvalidCharger; private boolean mInvalidCharger; private SystemUIDialog mSaverConfirmation; private SystemUIDialog mSaverConfirmation; private boolean mTempWarning; private boolean mHighTempWarning; private SystemUIDialog mHighTempDialog; private SystemUIDialog mHighTempDialog; private SystemUIDialog mThermalShutdownDialog; public PowerNotificationWarnings(Context context, NotificationManager notificationManager, public PowerNotificationWarnings(Context context, NotificationManager notificationManager, StatusBar statusBar) { StatusBar statusBar) { Loading @@ -113,8 +119,10 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { pw.print("mInvalidCharger="); pw.println(mInvalidCharger); pw.print("mInvalidCharger="); pw.println(mInvalidCharger); pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]); pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]); pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null); pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null); pw.print("mTempWarning="); pw.println(mTempWarning); pw.print("mHighTempWarning="); pw.println(mHighTempWarning); pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null); pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null); pw.print("mThermalShutdownDialog="); pw.println(mThermalShutdownDialog != null ? "not null" : null); } } @Override @Override Loading Loading @@ -212,29 +220,29 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } } @Override @Override public void dismissTemperatureWarning() { public void dismissHighTemperatureWarning() { if (!mTempWarning) { if (!mHighTempWarning) { return; return; } } mTempWarning = false; mHighTempWarning = false; dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); } } /** /** * Internal only version of {@link #dismissTemperatureWarning()} that simply dismisses * Internal only version of {@link #dismissHighTemperatureWarning()} that simply dismisses * the notification. As such, the notification will not show again until * the notification. As such, the notification will not show again until * {@link #dismissTemperatureWarning()} is called. * {@link #dismissHighTemperatureWarning()} is called. */ */ private void dismissTemperatureWarningInternal() { private void dismissHighTemperatureWarningInternal() { mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL); mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL); } } @Override @Override public void showTemperatureWarning() { public void showHighTemperatureWarning() { if (mTempWarning) { if (mHighTempWarning) { return; return; } } mTempWarning = true; mHighTempWarning = true; final Notification.Builder nb = final Notification.Builder nb = new Notification.Builder(mContext, NotificationChannels.ALERTS) new Notification.Builder(mContext, NotificationChannels.ALERTS) .setSmallIcon(R.drawable.ic_device_thermostat_24) .setSmallIcon(R.drawable.ic_device_thermostat_24) Loading @@ -249,10 +257,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { SystemUI.overrideNotificationAppName(mContext, nb); SystemUI.overrideNotificationAppName(mContext, nb); final Notification n = nb.build(); final Notification n = nb.build(); mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL); mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL); } } private void showTemperatureDialog() { private void showHighTemperatureDialog() { if (mHighTempDialog != null) return; if (mHighTempDialog != null) return; final SystemUIDialog d = new SystemUIDialog(mContext); final SystemUIDialog d = new SystemUIDialog(mContext); d.setIconAttribute(android.R.attr.alertDialogIcon); d.setIconAttribute(android.R.attr.alertDialogIcon); Loading @@ -265,6 +272,44 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { mHighTempDialog = d; mHighTempDialog = d; } } @VisibleForTesting void dismissThermalShutdownWarning() { mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, UserHandle.ALL); } private void showThermalShutdownDialog() { if (mThermalShutdownDialog != null) return; final SystemUIDialog d = new SystemUIDialog(mContext); d.setIconAttribute(android.R.attr.alertDialogIcon); d.setTitle(R.string.thermal_shutdown_title); d.setMessage(R.string.thermal_shutdown_dialog_message); d.setPositiveButton(com.android.internal.R.string.ok, null); d.setShowForAllUsers(true); d.setOnDismissListener(dialog -> mThermalShutdownDialog = null); d.show(); mThermalShutdownDialog = d; } @Override public void showThermalShutdownWarning() { final Notification.Builder nb = new Notification.Builder(mContext, NotificationChannels.ALERTS) .setSmallIcon(R.drawable.ic_device_thermostat_24) .setWhen(0) .setShowWhen(false) .setContentTitle(mContext.getString(R.string.thermal_shutdown_title)) .setContentText(mContext.getString(R.string.thermal_shutdown_message)) .setVisibility(Notification.VISIBILITY_PUBLIC) .setContentIntent(pendingBroadcast(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING)) .setDeleteIntent( pendingBroadcast(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING)) .setColor(Utils.getColorAttr(mContext, android.R.attr.colorError)); SystemUI.overrideNotificationAppName(mContext, nb); final Notification n = nb.build(); mNoMan.notifyAsUser( TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, n, UserHandle.ALL); } @Override @Override public void updateLowBatteryWarning() { public void updateLowBatteryWarning() { updateNotification(); updateNotification(); Loading Loading @@ -380,6 +425,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { filter.addAction(ACTION_DISMISSED_WARNING); filter.addAction(ACTION_DISMISSED_WARNING); filter.addAction(ACTION_CLICKED_TEMP_WARNING); filter.addAction(ACTION_CLICKED_TEMP_WARNING); filter.addAction(ACTION_DISMISSED_TEMP_WARNING); filter.addAction(ACTION_DISMISSED_TEMP_WARNING); filter.addAction(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING); filter.addAction(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING); mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, mContext.registerReceiverAsUser(this, UserHandle.ALL, filter, android.Manifest.permission.STATUS_BAR_SERVICE, mHandler); android.Manifest.permission.STATUS_BAR_SERVICE, mHandler); } } Loading @@ -397,10 +444,15 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { } else if (action.equals(ACTION_DISMISSED_WARNING)) { } else if (action.equals(ACTION_DISMISSED_WARNING)) { dismissLowBatteryWarning(); dismissLowBatteryWarning(); } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) { dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); showTemperatureDialog(); showHighTemperatureDialog(); } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) { } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) { dismissTemperatureWarningInternal(); dismissHighTemperatureWarningInternal(); } else if (ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING.equals(action)) { dismissThermalShutdownWarning(); showThermalShutdownDialog(); } else if (ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING.equals(action)) { dismissThermalShutdownWarning(); } } } } } } Loading
packages/SystemUI/src/com/android/systemui/power/PowerUI.java +17 −4 Original line number Original line Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.os.SystemClock; import android.os.UserHandle; import android.os.UserHandle; import android.provider.Settings; import android.provider.Settings; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.DateUtils; import android.util.Log; import android.util.Log; import android.util.Slog; import android.util.Slog; Loading Loading @@ -93,6 +94,10 @@ public class PowerUI extends SystemUI { updateBatteryWarningLevels(); updateBatteryWarningLevels(); mReceiver.init(); mReceiver.init(); // Check to see if we need to let the user know that the phone previously shut down due // to the temperature being too high. showThermalShutdownDialog(); initTemperatureWarning(); initTemperatureWarning(); } } Loading Loading @@ -256,6 +261,13 @@ public class PowerUI extends SystemUI { updateTemperatureWarning(); updateTemperatureWarning(); } } private void showThermalShutdownDialog() { if (mPowerManager.getLastShutdownReason() == PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN) { mWarnings.showThermalShutdownWarning(); } } private void updateTemperatureWarning() { private void updateTemperatureWarning() { float[] temps = mHardwarePropertiesManager.getDeviceTemperatures( float[] temps = mHardwarePropertiesManager.getDeviceTemperatures( HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, Loading @@ -268,9 +280,9 @@ public class PowerUI extends SystemUI { if (statusBar != null && !statusBar.isDeviceInVrMode() if (statusBar != null && !statusBar.isDeviceInVrMode() && temp >= mThresholdTemp) { && temp >= mThresholdTemp) { logAtTemperatureThreshold(temp); logAtTemperatureThreshold(temp); mWarnings.showTemperatureWarning(); mWarnings.showHighTemperatureWarning(); } else { } else { mWarnings.dismissTemperatureWarning(); mWarnings.dismissHighTemperatureWarning(); } } } } Loading Loading @@ -369,8 +381,9 @@ public class PowerUI extends SystemUI { void showInvalidChargerWarning(); void showInvalidChargerWarning(); void updateLowBatteryWarning(); void updateLowBatteryWarning(); boolean isInvalidChargerWarningShowing(); boolean isInvalidChargerWarningShowing(); void dismissTemperatureWarning(); void dismissHighTemperatureWarning(); void showTemperatureWarning(); void showHighTemperatureWarning(); void showThermalShutdownWarning(); void dump(PrintWriter pw); void dump(PrintWriter pw); void userSwitched(); void userSwitched(); } } Loading
packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java +20 −6 Original line number Original line Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.times; Loading Loading @@ -129,17 +128,32 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { } } @Test @Test public void testShowTemperatureWarning_NotifyAsUser() { public void testShowHighTemperatureWarning_NotifyAsUser() { mPowerNotificationWarnings.showTemperatureWarning(); mPowerNotificationWarnings.showHighTemperatureWarning(); verify(mMockNotificationManager, times(1)) verify(mMockNotificationManager, times(1)) .notifyAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any(), any()); .notifyAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any(), any()); } } @Test @Test public void testDismissTemperatureWarning_CancelAsUser() { public void testDismissHighTemperatureWarning_CancelAsUser() { mPowerNotificationWarnings.showTemperatureWarning(); mPowerNotificationWarnings.showHighTemperatureWarning(); mPowerNotificationWarnings.dismissTemperatureWarning(); mPowerNotificationWarnings.dismissHighTemperatureWarning(); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), eq(SystemMessage.NOTE_HIGH_TEMP), any()); eq(SystemMessage.NOTE_HIGH_TEMP), any()); } } @Test public void testShowThermalShutdownWarning_NotifyAsUser() { mPowerNotificationWarnings.showThermalShutdownWarning(); verify(mMockNotificationManager, times(1)) .notifyAsUser(anyString(), eq(SystemMessage.NOTE_THERMAL_SHUTDOWN), any(), any()); } @Test public void testDismissThermalShutdownWarning_CancelAsUser() { mPowerNotificationWarnings.showThermalShutdownWarning(); mPowerNotificationWarnings.dismissThermalShutdownWarning(); verify(mMockNotificationManager, times(1)).cancelAsUser(anyString(), eq(SystemMessage.NOTE_THERMAL_SHUTDOWN), any()); } } }