blob: 41bcab53f8e915058a9ac16e4098d45291065345 [file] [log] [blame]
John Spurlock3332ba52014-03-10 17:44:07 -04001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.systemui.power;
18
Sherry Huangce02ed32019-01-17 20:37:29 +080019import android.app.KeyguardManager;
John Spurlock3332ba52014-03-10 17:44:07 -040020import android.app.Notification;
21import android.app.NotificationManager;
22import android.app.PendingIntent;
Makoto Onukie8bbf952018-04-20 14:04:50 -070023import android.content.ActivityNotFoundException;
John Spurlock3332ba52014-03-10 17:44:07 -040024import android.content.BroadcastReceiver;
John Spurlock3332ba52014-03-10 17:44:07 -040025import android.content.Context;
John Spurlock3332ba52014-03-10 17:44:07 -040026import android.content.Intent;
27import android.content.IntentFilter;
John Spurlock1bb480a2014-08-02 17:12:43 -040028import android.media.AudioAttributes;
Makoto Onukie8bbf952018-04-20 14:04:50 -070029import android.net.Uri;
John Spurlock3332ba52014-03-10 17:44:07 -040030import android.os.Handler;
Geoffrey Pitsch4a7931d2016-09-15 13:11:47 -040031import android.os.Looper;
John Spurlock8d4e6cb2014-09-14 11:10:22 -040032import android.os.PowerManager;
John Spurlock3332ba52014-03-10 17:44:07 -040033import android.os.UserHandle;
Makoto Onukie8bbf952018-04-20 14:04:50 -070034import android.text.Annotation;
35import android.text.Layout;
36import android.text.SpannableString;
37import android.text.SpannableStringBuilder;
38import android.text.TextPaint;
39import android.text.TextUtils;
40import android.text.method.LinkMovementMethod;
41import android.text.style.URLSpan;
42import android.util.Log;
John Spurlock3332ba52014-03-10 17:44:07 -040043import android.util.Slog;
Makoto Onukie8bbf952018-04-20 14:04:50 -070044import android.view.View;
Sherry Huangce02ed32019-01-17 20:37:29 +080045import android.view.WindowManager;
Gus Prevasab336792018-11-14 13:52:20 -050046
Makoto Onukie8bbf952018-04-20 14:04:50 -070047import androidx.annotation.VisibleForTesting;
John Spurlock3332ba52014-03-10 17:44:07 -040048
Chris Wren5e6c0ff2017-01-05 12:57:06 -050049import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
Jason Monk58be7a62017-02-01 20:17:51 -050050import com.android.settingslib.Utils;
Makoto Onuki16a0dd22018-03-20 10:40:37 -070051import com.android.settingslib.fuelgauge.BatterySaverUtils;
Salvador Martinezeb9ab292018-01-19 17:50:24 -080052import com.android.settingslib.utils.PowerUtil;
Sherry Huangce02ed32019-01-17 20:37:29 +080053import com.android.systemui.Dependency;
John Spurlock3332ba52014-03-10 17:44:07 -040054import com.android.systemui.R;
Adrian Roose25c18d2016-06-17 15:59:49 -070055import com.android.systemui.SystemUI;
Sherry Huangce02ed32019-01-17 20:37:29 +080056import com.android.systemui.plugins.ActivityStarter;
John Spurlock1bb480a2014-08-02 17:12:43 -040057import com.android.systemui.statusbar.phone.SystemUIDialog;
Dan Sandler8e032e12017-01-25 13:41:38 -050058import com.android.systemui.util.NotificationChannels;
Sherry Huangce02ed32019-01-17 20:37:29 +080059import com.android.systemui.volume.Events;
John Spurlock3332ba52014-03-10 17:44:07 -040060
61import java.io.PrintWriter;
Elliott Hughes88d25512014-10-03 12:06:17 -070062import java.text.NumberFormat;
Makoto Onukie8bbf952018-04-20 14:04:50 -070063import java.util.Locale;
64import java.util.Objects;
John Spurlock3332ba52014-03-10 17:44:07 -040065
Jason Monk196d6392018-12-20 13:25:34 -050066import javax.inject.Inject;
67import javax.inject.Singleton;
68
69/**
70 */
71@Singleton
John Spurlock3332ba52014-03-10 17:44:07 -040072public class PowerNotificationWarnings implements PowerUI.WarningsUI {
73 private static final String TAG = PowerUI.TAG + ".Notification";
74 private static final boolean DEBUG = PowerUI.DEBUG;
75
Chris Wren5e6c0ff2017-01-05 12:57:06 -050076 private static final String TAG_BATTERY = "low_battery";
77 private static final String TAG_TEMPERATURE = "high_temp";
Makoto Onuki52c62952018-03-22 10:43:03 -070078 private static final String TAG_AUTO_SAVER = "auto_saver";
John Spurlock3332ba52014-03-10 17:44:07 -040079
80 private static final int SHOWING_NOTHING = 0;
81 private static final int SHOWING_WARNING = 1;
John Spurlock3332ba52014-03-10 17:44:07 -040082 private static final int SHOWING_INVALID_CHARGER = 3;
Makoto Onuki52c62952018-03-22 10:43:03 -070083 private static final int SHOWING_AUTO_SAVER_SUGGESTION = 4;
John Spurlock3332ba52014-03-10 17:44:07 -040084 private static final String[] SHOWING_STRINGS = {
85 "SHOWING_NOTHING",
86 "SHOWING_WARNING",
87 "SHOWING_SAVER",
88 "SHOWING_INVALID_CHARGER",
Makoto Onuki52c62952018-03-22 10:43:03 -070089 "SHOWING_AUTO_SAVER_SUGGESTION",
John Spurlock3332ba52014-03-10 17:44:07 -040090 };
91
John Spurlock3332ba52014-03-10 17:44:07 -040092 private static final String ACTION_SHOW_BATTERY_SETTINGS = "PNW.batterySettings";
93 private static final String ACTION_START_SAVER = "PNW.startSaver";
John Spurlock42bfc9a2014-10-29 11:13:01 -040094 private static final String ACTION_DISMISSED_WARNING = "PNW.dismissedWarning";
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -080095 private static final String ACTION_CLICKED_TEMP_WARNING = "PNW.clickedTempWarning";
96 private static final String ACTION_DISMISSED_TEMP_WARNING = "PNW.dismissedTempWarning";
Salvador Martineza6f7b252017-04-10 10:46:15 -070097 private static final String ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING =
98 "PNW.clickedThermalShutdownWarning";
99 private static final String ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING =
100 "PNW.dismissedThermalShutdownWarning";
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700101 private static final String ACTION_SHOW_START_SAVER_CONFIRMATION =
102 BatterySaverUtils.ACTION_SHOW_START_SAVER_CONFIRMATION;
Makoto Onuki52c62952018-03-22 10:43:03 -0700103 private static final String ACTION_SHOW_AUTO_SAVER_SUGGESTION =
104 BatterySaverUtils.ACTION_SHOW_AUTO_SAVER_SUGGESTION;
105 private static final String ACTION_DISMISS_AUTO_SAVER_SUGGESTION =
106 "PNW.dismissAutoSaverSuggestion";
107
108 private static final String ACTION_ENABLE_AUTO_SAVER =
109 "PNW.enableAutoSaver";
110 private static final String ACTION_AUTO_SAVER_NO_THANKS =
111 "PNW.autoSaverNoThanks";
112
113 private static final String SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING =
114 "android.settings.BATTERY_SAVER_SETTINGS";
John Spurlock1bb480a2014-08-02 17:12:43 -0400115
Makoto Onukie8bbf952018-04-20 14:04:50 -0700116 private static final String BATTERY_SAVER_DESCRIPTION_URL_KEY = "url";
117
John Spurlock1bb480a2014-08-02 17:12:43 -0400118 private static final AudioAttributes AUDIO_ATTRIBUTES = new AudioAttributes.Builder()
119 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
120 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
121 .build();
John Spurlock3332ba52014-03-10 17:44:07 -0400122
123 private final Context mContext;
John Spurlock3332ba52014-03-10 17:44:07 -0400124 private final NotificationManager mNoMan;
John Spurlock8d4e6cb2014-09-14 11:10:22 -0400125 private final PowerManager mPowerMan;
Sherry Huangce02ed32019-01-17 20:37:29 +0800126 private final KeyguardManager mKeyguard;
Geoffrey Pitsch4a7931d2016-09-15 13:11:47 -0400127 private final Handler mHandler = new Handler(Looper.getMainLooper());
John Spurlock3332ba52014-03-10 17:44:07 -0400128 private final Receiver mReceiver = new Receiver();
129 private final Intent mOpenBatterySettings = settings(Intent.ACTION_POWER_USAGE_SUMMARY);
John Spurlock3332ba52014-03-10 17:44:07 -0400130
131 private int mBatteryLevel;
132 private int mBucket;
133 private long mScreenOffTime;
134 private int mShowing;
135
Salvador Martinezf9e47502018-01-04 13:45:48 -0800136 private long mWarningTriggerTimeMs;
John Spurlock3332ba52014-03-10 17:44:07 -0400137 private boolean mWarning;
Makoto Onuki52c62952018-03-22 10:43:03 -0700138 private boolean mShowAutoSaverSuggestion;
John Spurlock3332ba52014-03-10 17:44:07 -0400139 private boolean mPlaySound;
140 private boolean mInvalidCharger;
John Spurlock1bb480a2014-08-02 17:12:43 -0400141 private SystemUIDialog mSaverConfirmation;
Makoto Onuki52c62952018-03-22 10:43:03 -0700142 private SystemUIDialog mSaverEnabledConfirmation;
Salvador Martineza6f7b252017-04-10 10:46:15 -0700143 private boolean mHighTempWarning;
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800144 private SystemUIDialog mHighTempDialog;
Salvador Martineza6f7b252017-04-10 10:46:15 -0700145 private SystemUIDialog mThermalShutdownDialog;
Sherry Huangce02ed32019-01-17 20:37:29 +0800146 @VisibleForTesting SystemUIDialog mUsbHighTempDialog;
Salvador Martinez4387bd52019-02-21 16:16:28 -0800147 private BatteryStateSnapshot mCurrentBatterySnapshot;
John Spurlock3332ba52014-03-10 17:44:07 -0400148
Jason Monk196d6392018-12-20 13:25:34 -0500149 /**
150 */
151 @Inject
Jason Monkd819c312017-08-11 12:53:36 -0400152 public PowerNotificationWarnings(Context context) {
John Spurlock3332ba52014-03-10 17:44:07 -0400153 mContext = context;
Jason Monkd819c312017-08-11 12:53:36 -0400154 mNoMan = mContext.getSystemService(NotificationManager.class);
John Spurlock8d4e6cb2014-09-14 11:10:22 -0400155 mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
Sherry Huangce02ed32019-01-17 20:37:29 +0800156 mKeyguard = mContext.getSystemService(KeyguardManager.class);
John Spurlock3332ba52014-03-10 17:44:07 -0400157 mReceiver.init();
158 }
159
160 @Override
161 public void dump(PrintWriter pw) {
John Spurlock3332ba52014-03-10 17:44:07 -0400162 pw.print("mWarning="); pw.println(mWarning);
163 pw.print("mPlaySound="); pw.println(mPlaySound);
164 pw.print("mInvalidCharger="); pw.println(mInvalidCharger);
165 pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]);
John Spurlock1bb480a2014-08-02 17:12:43 -0400166 pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null);
Makoto Onuki52c62952018-03-22 10:43:03 -0700167 pw.print("mSaverEnabledConfirmation=");
168 pw.println(mSaverEnabledConfirmation != null ? "not null" : null);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700169 pw.print("mHighTempWarning="); pw.println(mHighTempWarning);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800170 pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700171 pw.print("mThermalShutdownDialog=");
172 pw.println(mThermalShutdownDialog != null ? "not null" : null);
Sherry Huangce02ed32019-01-17 20:37:29 +0800173 pw.print("mUsbHighTempDialog=");
174 pw.println(mUsbHighTempDialog != null ? "not null" : null);
John Spurlock3332ba52014-03-10 17:44:07 -0400175 }
176
Makoto Onuki52c62952018-03-22 10:43:03 -0700177 private int getLowBatteryAutoTriggerDefaultLevel() {
178 return mContext.getResources().getInteger(
179 com.android.internal.R.integer.config_lowBatteryAutoTriggerDefaultLevel);
180 }
181
John Spurlock3332ba52014-03-10 17:44:07 -0400182 @Override
183 public void update(int batteryLevel, int bucket, long screenOffTime) {
184 mBatteryLevel = batteryLevel;
Christoph Studer65fa0a92014-06-26 16:50:09 +0200185 if (bucket >= 0) {
Salvador Martinezf9e47502018-01-04 13:45:48 -0800186 mWarningTriggerTimeMs = 0;
Christoph Studer65fa0a92014-06-26 16:50:09 +0200187 } else if (bucket < mBucket) {
Salvador Martinezf9e47502018-01-04 13:45:48 -0800188 mWarningTriggerTimeMs = System.currentTimeMillis();
Christoph Studer65fa0a92014-06-26 16:50:09 +0200189 }
John Spurlock3332ba52014-03-10 17:44:07 -0400190 mBucket = bucket;
191 mScreenOffTime = screenOffTime;
John Spurlock3332ba52014-03-10 17:44:07 -0400192 }
193
Salvador Martinezf9e47502018-01-04 13:45:48 -0800194 @Override
Salvador Martinez4387bd52019-02-21 16:16:28 -0800195 public void updateSnapshot(BatteryStateSnapshot snapshot) {
196 mCurrentBatterySnapshot = snapshot;
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800197 }
198
John Spurlock3332ba52014-03-10 17:44:07 -0400199 private void updateNotification() {
John Spurlock86c3de82014-08-19 13:37:44 -0400200 if (DEBUG) Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mPlaySound="
Jason Monkc06fbb12016-01-08 14:12:18 -0500201 + mPlaySound + " mInvalidCharger=" + mInvalidCharger);
John Spurlock3332ba52014-03-10 17:44:07 -0400202 if (mInvalidCharger) {
John Spurlock3332ba52014-03-10 17:44:07 -0400203 showInvalidChargerNotification();
204 mShowing = SHOWING_INVALID_CHARGER;
205 } else if (mWarning) {
John Spurlock3332ba52014-03-10 17:44:07 -0400206 showWarningNotification();
207 mShowing = SHOWING_WARNING;
Makoto Onuki52c62952018-03-22 10:43:03 -0700208 } else if (mShowAutoSaverSuggestion) {
Makoto Onuki60b8f182018-05-07 13:56:40 -0700209 // Once we showed the notification, don't show it again until it goes SHOWING_NOTHING.
210 // This shouldn't be needed, because we have a delete intent on this notification
211 // so when it's dismissed we should notice it and clear mShowAutoSaverSuggestion,
212 // However we double check here just in case the dismiss intent broadcast is delayed.
213 if (mShowing != SHOWING_AUTO_SAVER_SUGGESTION) {
214 showAutoSaverSuggestionNotification();
215 }
Makoto Onuki52c62952018-03-22 10:43:03 -0700216 mShowing = SHOWING_AUTO_SAVER_SUGGESTION;
John Spurlock3332ba52014-03-10 17:44:07 -0400217 } else {
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500218 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL);
219 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, UserHandle.ALL);
Makoto Onuki52c62952018-03-22 10:43:03 -0700220 mNoMan.cancelAsUser(TAG_AUTO_SAVER,
221 SystemMessage.NOTE_AUTO_SAVER_SUGGESTION, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400222 mShowing = SHOWING_NOTHING;
223 }
224 }
225
226 private void showInvalidChargerNotification() {
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500227 final Notification.Builder nb =
228 new Notification.Builder(mContext, NotificationChannels.ALERTS)
229 .setSmallIcon(R.drawable.ic_power_low)
230 .setWhen(0)
231 .setShowWhen(false)
232 .setOngoing(true)
233 .setContentTitle(mContext.getString(R.string.invalid_charger_title))
234 .setContentText(mContext.getString(R.string.invalid_charger_text))
235 .setColor(mContext.getColor(
236 com.android.internal.R.color.system_notification_accent_color));
Julia Reynolds037d8082018-03-18 15:25:19 -0400237 SystemUI.overrideNotificationAppName(mContext, nb, false);
John Spurlock3332ba52014-03-10 17:44:07 -0400238 final Notification n = nb.build();
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500239 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, UserHandle.ALL);
240 mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, n, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400241 }
242
Salvador Martinezf9e47502018-01-04 13:45:48 -0800243 protected void showWarningNotification() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800244 final String percentage = NumberFormat.getPercentInstance()
Salvador Martinez4387bd52019-02-21 16:16:28 -0800245 .format((double) mCurrentBatterySnapshot.getBatteryLevel() / 100.0);
Beverly334bc5f2017-07-31 10:37:17 -0400246
Salvador Martinez4387bd52019-02-21 16:16:28 -0800247 // get shared standard notification copy
Salvador Martinezf9e47502018-01-04 13:45:48 -0800248 String title = mContext.getString(R.string.battery_low_title);
Salvador Martinez4387bd52019-02-21 16:16:28 -0800249 String contentText;
Salvador Martinezf9e47502018-01-04 13:45:48 -0800250
Salvador Martinez4387bd52019-02-21 16:16:28 -0800251 // get correct content text if notification is hybrid or not
252 if (mCurrentBatterySnapshot.isHybrid()) {
Salvador Martinezeb9ab292018-01-19 17:50:24 -0800253 contentText = getHybridContentString(percentage);
Salvador Martinez4387bd52019-02-21 16:16:28 -0800254 } else {
255 contentText = mContext.getString(R.string.battery_low_percent_format, percentage);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800256 }
257
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500258 final Notification.Builder nb =
Beverly334bc5f2017-07-31 10:37:17 -0400259 new Notification.Builder(mContext, NotificationChannels.BATTERY)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500260 .setSmallIcon(R.drawable.ic_power_low)
261 // Bump the notification when the bucket dropped.
Salvador Martinezf9e47502018-01-04 13:45:48 -0800262 .setWhen(mWarningTriggerTimeMs)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500263 .setShowWhen(false)
Salvador Martinezf9e47502018-01-04 13:45:48 -0800264 .setContentText(contentText)
Salvador Martinez086ab742018-04-03 13:05:39 -0700265 .setContentTitle(title)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500266 .setOnlyAlertOnce(true)
267 .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
Salvador Martinez086ab742018-04-03 13:05:39 -0700268 .setStyle(new Notification.BigTextStyle().bigText(contentText))
Salvador Martinezf9e47502018-01-04 13:45:48 -0800269 .setVisibility(Notification.VISIBILITY_PUBLIC);
John Spurlock3332ba52014-03-10 17:44:07 -0400270 if (hasBatterySettings()) {
271 nb.setContentIntent(pendingBroadcast(ACTION_SHOW_BATTERY_SETTINGS));
272 }
Salvador Martinezf9e47502018-01-04 13:45:48 -0800273 // Make the notification red if the percentage goes below a certain amount or the time
274 // remaining estimate is disabled
Salvador Martinez4387bd52019-02-21 16:16:28 -0800275 if (!mCurrentBatterySnapshot.isHybrid() || mBucket < 0
276 || mCurrentBatterySnapshot.getTimeRemainingMillis()
277 < mCurrentBatterySnapshot.getSevereThresholdMillis()) {
Jason Changb4e879d2018-04-11 11:17:58 +0800278 nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError));
Salvador Martinezf9e47502018-01-04 13:45:48 -0800279 }
Salvador Martinezc25604b2018-08-03 14:07:44 -0700280
281 if (!mPowerMan.isPowerSaveMode()) {
282 nb.addAction(0,
283 mContext.getString(R.string.battery_saver_start_action),
284 pendingBroadcast(ACTION_START_SAVER));
285 }
Beverly334bc5f2017-07-31 10:37:17 -0400286 nb.setOnlyAlertOnce(!mPlaySound);
287 mPlaySound = false;
Julia Reynolds037d8082018-03-18 15:25:19 -0400288 SystemUI.overrideNotificationAppName(mContext, nb, false);
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500289 final Notification n = nb.build();
290 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL);
291 mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400292 }
293
Makoto Onuki52c62952018-03-22 10:43:03 -0700294 private void showAutoSaverSuggestionNotification() {
295 final Notification.Builder nb =
296 new Notification.Builder(mContext, NotificationChannels.HINTS)
297 .setSmallIcon(R.drawable.ic_power_saver)
298 .setWhen(0)
299 .setShowWhen(false)
300 .setContentTitle(mContext.getString(R.string.auto_saver_title))
301 .setContentText(mContext.getString(R.string.auto_saver_text,
302 getLowBatteryAutoTriggerDefaultLevel()));
303 nb.setContentIntent(pendingBroadcast(ACTION_ENABLE_AUTO_SAVER));
304 nb.setDeleteIntent(pendingBroadcast(ACTION_DISMISS_AUTO_SAVER_SUGGESTION));
305 nb.addAction(0,
306 mContext.getString(R.string.no_auto_saver_action),
307 pendingBroadcast(ACTION_AUTO_SAVER_NO_THANKS));
308
309 SystemUI.overrideNotificationAppName(mContext, nb, false);
310
311 final Notification n = nb.build();
312 mNoMan.notifyAsUser(
313 TAG_AUTO_SAVER, SystemMessage.NOTE_AUTO_SAVER_SUGGESTION, n, UserHandle.ALL);
314 }
315
Salvador Martinezeb9ab292018-01-19 17:50:24 -0800316 private String getHybridContentString(String percentage) {
317 return PowerUtil.getBatteryRemainingStringFormatted(
Salvador Martinez4387bd52019-02-21 16:16:28 -0800318 mContext,
319 mCurrentBatterySnapshot.getTimeRemainingMillis(),
320 percentage,
321 mCurrentBatterySnapshot.isBasedOnUsage());
Salvador Martinezf9e47502018-01-04 13:45:48 -0800322 }
323
John Spurlock3332ba52014-03-10 17:44:07 -0400324 private PendingIntent pendingBroadcast(String action) {
Makoto Onuki52c62952018-03-22 10:43:03 -0700325 return PendingIntent.getBroadcastAsUser(mContext, 0,
Makoto Onuki60b8f182018-05-07 13:56:40 -0700326 new Intent(action).setPackage(mContext.getPackageName())
327 .setFlags(Intent.FLAG_RECEIVER_FOREGROUND),
328 0, UserHandle.CURRENT);
John Spurlock3332ba52014-03-10 17:44:07 -0400329 }
330
331 private static Intent settings(String action) {
332 return new Intent(action).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
333 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
334 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
335 | Intent.FLAG_ACTIVITY_NO_HISTORY
336 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
337 }
338
339 @Override
340 public boolean isInvalidChargerWarningShowing() {
341 return mInvalidCharger;
342 }
343
344 @Override
Salvador Martineza6f7b252017-04-10 10:46:15 -0700345 public void dismissHighTemperatureWarning() {
346 if (!mHighTempWarning) {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800347 return;
348 }
Salvador Martineza6f7b252017-04-10 10:46:15 -0700349 mHighTempWarning = false;
350 dismissHighTemperatureWarningInternal();
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800351 }
352
353 /**
Salvador Martineza6f7b252017-04-10 10:46:15 -0700354 * Internal only version of {@link #dismissHighTemperatureWarning()} that simply dismisses
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800355 * the notification. As such, the notification will not show again until
Salvador Martineza6f7b252017-04-10 10:46:15 -0700356 * {@link #dismissHighTemperatureWarning()} is called.
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800357 */
Salvador Martineza6f7b252017-04-10 10:46:15 -0700358 private void dismissHighTemperatureWarningInternal() {
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800359 mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800360 }
361
362 @Override
Salvador Martineza6f7b252017-04-10 10:46:15 -0700363 public void showHighTemperatureWarning() {
364 if (mHighTempWarning) {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800365 return;
366 }
Salvador Martineza6f7b252017-04-10 10:46:15 -0700367 mHighTempWarning = true;
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500368 final Notification.Builder nb =
369 new Notification.Builder(mContext, NotificationChannels.ALERTS)
370 .setSmallIcon(R.drawable.ic_device_thermostat_24)
371 .setWhen(0)
372 .setShowWhen(false)
373 .setContentTitle(mContext.getString(R.string.high_temp_title))
374 .setContentText(mContext.getString(R.string.high_temp_notif_message))
375 .setVisibility(Notification.VISIBILITY_PUBLIC)
376 .setContentIntent(pendingBroadcast(ACTION_CLICKED_TEMP_WARNING))
377 .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_TEMP_WARNING))
Jason Changb4e879d2018-04-11 11:17:58 +0800378 .setColor(Utils.getColorAttrDefaultColor(mContext,
379 android.R.attr.colorError));
Julia Reynolds037d8082018-03-18 15:25:19 -0400380 SystemUI.overrideNotificationAppName(mContext, nb, false);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800381 final Notification n = nb.build();
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500382 mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800383 }
384
Salvador Martineza6f7b252017-04-10 10:46:15 -0700385 private void showHighTemperatureDialog() {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800386 if (mHighTempDialog != null) return;
387 final SystemUIDialog d = new SystemUIDialog(mContext);
Andrew Sappersteine26dc3d2017-01-04 11:25:20 -0800388 d.setIconAttribute(android.R.attr.alertDialogIcon);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800389 d.setTitle(R.string.high_temp_title);
390 d.setMessage(R.string.high_temp_dialog_message);
391 d.setPositiveButton(com.android.internal.R.string.ok, null);
392 d.setShowForAllUsers(true);
393 d.setOnDismissListener(dialog -> mHighTempDialog = null);
394 d.show();
395 mHighTempDialog = d;
396 }
397
Salvador Martineza6f7b252017-04-10 10:46:15 -0700398 @VisibleForTesting
399 void dismissThermalShutdownWarning() {
400 mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, UserHandle.ALL);
401 }
402
403 private void showThermalShutdownDialog() {
404 if (mThermalShutdownDialog != null) return;
405 final SystemUIDialog d = new SystemUIDialog(mContext);
406 d.setIconAttribute(android.R.attr.alertDialogIcon);
407 d.setTitle(R.string.thermal_shutdown_title);
408 d.setMessage(R.string.thermal_shutdown_dialog_message);
409 d.setPositiveButton(com.android.internal.R.string.ok, null);
410 d.setShowForAllUsers(true);
411 d.setOnDismissListener(dialog -> mThermalShutdownDialog = null);
412 d.show();
413 mThermalShutdownDialog = d;
414 }
415
416 @Override
417 public void showThermalShutdownWarning() {
418 final Notification.Builder nb =
419 new Notification.Builder(mContext, NotificationChannels.ALERTS)
420 .setSmallIcon(R.drawable.ic_device_thermostat_24)
421 .setWhen(0)
422 .setShowWhen(false)
423 .setContentTitle(mContext.getString(R.string.thermal_shutdown_title))
424 .setContentText(mContext.getString(R.string.thermal_shutdown_message))
425 .setVisibility(Notification.VISIBILITY_PUBLIC)
426 .setContentIntent(pendingBroadcast(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING))
427 .setDeleteIntent(
428 pendingBroadcast(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING))
Jason Changb4e879d2018-04-11 11:17:58 +0800429 .setColor(Utils.getColorAttrDefaultColor(mContext,
430 android.R.attr.colorError));
Julia Reynolds037d8082018-03-18 15:25:19 -0400431 SystemUI.overrideNotificationAppName(mContext, nb, false);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700432 final Notification n = nb.build();
433 mNoMan.notifyAsUser(
434 TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, n, UserHandle.ALL);
435 }
436
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800437 @Override
Sherry Huangce02ed32019-01-17 20:37:29 +0800438 public void showUsbHighTemperatureAlarm() {
439 mHandler.post(() -> showUsbHighTemperatureAlarmInternal());
440 }
441
442 private void showUsbHighTemperatureAlarmInternal() {
443 if (mUsbHighTempDialog != null) {
444 return;
445 }
446
447 final SystemUIDialog d = new SystemUIDialog(mContext, R.style.Theme_SystemUI_Dialog_Alert);
448 d.setCancelable(false);
449 d.setIconAttribute(android.R.attr.alertDialogIcon);
450 d.setTitle(R.string.high_temp_alarm_title);
451 d.setShowForAllUsers(true);
452 d.setMessage(mContext.getString(R.string.high_temp_alarm_notify_message, ""));
453 d.setPositiveButton((com.android.internal.R.string.ok),
454 (dialogInterface, which) -> mUsbHighTempDialog = null);
455 d.setNegativeButton((R.string.high_temp_alarm_help_care_steps),
456 (dialogInterface, which) -> {
457 final String contextString = mContext.getString(
458 R.string.high_temp_alarm_help_url);
459 final Intent helpIntent = new Intent();
460 helpIntent.setClassName("com.android.settings",
461 "com.android.settings.HelpTrampoline");
462 helpIntent.putExtra(Intent.EXTRA_TEXT, contextString);
463 Dependency.get(ActivityStarter.class).startActivity(helpIntent,
464 true /* dismissShade */, resultCode -> {
465 mUsbHighTempDialog = null;
466 });
467 });
468 d.setOnDismissListener(dialogInterface -> {
469 mUsbHighTempDialog = null;
470 Events.writeEvent(mContext, Events.EVENT_DISMISS_USB_OVERHEAT_ALARM,
471 Events.DISMISS_REASON_USB_OVERHEAD_ALARM_CHANGED,
472 mKeyguard.isKeyguardLocked());
473 });
474 d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
475 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
476 d.show();
477 mUsbHighTempDialog = d;
478
479 Events.writeEvent(mContext, Events.EVENT_SHOW_USB_OVERHEAT_ALARM,
480 Events.SHOW_REASON_USB_OVERHEAD_ALARM_CHANGED,
481 mKeyguard.isKeyguardLocked());
482 }
483
484 @Override
John Spurlock3332ba52014-03-10 17:44:07 -0400485 public void updateLowBatteryWarning() {
486 updateNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400487 }
488
489 @Override
490 public void dismissLowBatteryWarning() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400491 if (DEBUG) Slog.d(TAG, "dismissing low battery warning: level=" + mBatteryLevel);
John Spurlock3332ba52014-03-10 17:44:07 -0400492 dismissLowBatteryNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400493 }
494
495 private void dismissLowBatteryNotification() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400496 if (mWarning) Slog.i(TAG, "dismissing low battery notification");
John Spurlock3332ba52014-03-10 17:44:07 -0400497 mWarning = false;
498 updateNotification();
499 }
500
501 private boolean hasBatterySettings() {
502 return mOpenBatterySettings.resolveActivity(mContext.getPackageManager()) != null;
503 }
504
John Spurlock3332ba52014-03-10 17:44:07 -0400505 @Override
506 public void showLowBatteryWarning(boolean playSound) {
507 Slog.i(TAG,
508 "show low battery warning: level=" + mBatteryLevel
Beverly334bc5f2017-07-31 10:37:17 -0400509 + " [" + mBucket + "] playSound=" + playSound);
John Spurlock3332ba52014-03-10 17:44:07 -0400510 mPlaySound = playSound;
511 mWarning = true;
512 updateNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400513 }
514
John Spurlock3332ba52014-03-10 17:44:07 -0400515 @Override
516 public void dismissInvalidChargerWarning() {
John Spurlockeb44a7d2014-06-12 13:00:55 -0400517 dismissInvalidChargerNotification();
John Spurlockeb44a7d2014-06-12 13:00:55 -0400518 }
519
520 private void dismissInvalidChargerNotification() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400521 if (mInvalidCharger) Slog.i(TAG, "dismissing invalid charger notification");
John Spurlock3332ba52014-03-10 17:44:07 -0400522 mInvalidCharger = false;
523 updateNotification();
524 }
525
526 @Override
527 public void showInvalidChargerWarning() {
528 mInvalidCharger = true;
529 updateNotification();
530 }
531
Makoto Onuki52c62952018-03-22 10:43:03 -0700532 private void showAutoSaverSuggestion() {
533 mShowAutoSaverSuggestion = true;
534 updateNotification();
535 }
536
537 private void dismissAutoSaverSuggestion() {
538 mShowAutoSaverSuggestion = false;
539 updateNotification();
540 }
541
John Spurlockecbc5e82014-10-22 09:05:51 -0400542 @Override
543 public void userSwitched() {
544 updateNotification();
545 }
546
John Spurlock3332ba52014-03-10 17:44:07 -0400547 private void showStartSaverConfirmation() {
John Spurlock1bb480a2014-08-02 17:12:43 -0400548 if (mSaverConfirmation != null) return;
549 final SystemUIDialog d = new SystemUIDialog(mContext);
550 d.setTitle(R.string.battery_saver_confirmation_title);
Makoto Onukie8bbf952018-04-20 14:04:50 -0700551 d.setMessage(getBatterySaverDescription());
552
553 // Sad hack for http://b/78261259 and http://b/78298335. Otherwise "Battery" may be split
554 // into "Bat-tery".
555 if (isEnglishLocale()) {
556 d.setMessageHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE);
557 }
558 // We need to set LinkMovementMethod to make the link clickable.
559 d.setMessageMovementMethod(LinkMovementMethod.getInstance());
560
John Spurlock1bb480a2014-08-02 17:12:43 -0400561 d.setNegativeButton(android.R.string.cancel, null);
Makoto Onuki52c62952018-03-22 10:43:03 -0700562 d.setPositiveButton(R.string.battery_saver_confirmation_ok,
563 (dialog, which) -> setSaverMode(true, false));
John Spurlock1bb480a2014-08-02 17:12:43 -0400564 d.setShowForAllUsers(true);
Makoto Onuki52c62952018-03-22 10:43:03 -0700565 d.setOnDismissListener((dialog) -> mSaverConfirmation = null);
John Spurlock3332ba52014-03-10 17:44:07 -0400566 d.show();
John Spurlock1bb480a2014-08-02 17:12:43 -0400567 mSaverConfirmation = d;
John Spurlock3332ba52014-03-10 17:44:07 -0400568 }
569
Makoto Onukie8bbf952018-04-20 14:04:50 -0700570 private boolean isEnglishLocale() {
571 return Objects.equals(Locale.getDefault().getLanguage(),
572 Locale.ENGLISH.getLanguage());
573 }
574
575 /**
576 * Generates the message for the "want to start battery saver?" dialog with a "learn more" link.
577 */
578 private CharSequence getBatterySaverDescription() {
579 final String learnMoreUrl = mContext.getText(
580 R.string.help_uri_battery_saver_learn_more_link_target).toString();
581
582 // If there's no link, use the string with no "learn more".
583 if (TextUtils.isEmpty(learnMoreUrl)) {
584 return mContext.getText(
585 com.android.internal.R.string.battery_saver_description);
586 }
587
588 // If we have a link, use the string with the "learn more" link.
589 final CharSequence rawText = mContext.getText(
590 com.android.internal.R.string.battery_saver_description_with_learn_more);
591 final SpannableString message = new SpannableString(rawText);
592 final SpannableStringBuilder builder = new SpannableStringBuilder(message);
593
594 // Look for the "learn more" part of the string, and set a URL span on it.
595 // We use a customized URLSpan to add FLAG_RECEIVER_FOREGROUND to the intent, and
596 // also to close the dialog.
597 for (Annotation annotation : message.getSpans(0, message.length(), Annotation.class)) {
598 final String key = annotation.getValue();
599
600 if (!BATTERY_SAVER_DESCRIPTION_URL_KEY.equals(key)) {
601 continue;
602 }
603 final int start = message.getSpanStart(annotation);
604 final int end = message.getSpanEnd(annotation);
605
606 // Replace the "learn more" with a custom URL span, with
607 // - No underline.
608 // - When clicked, close the dialog and the notification shade.
609 final URLSpan urlSpan = new URLSpan(learnMoreUrl) {
610 @Override
611 public void updateDrawState(TextPaint ds) {
612 super.updateDrawState(ds);
613 ds.setUnderlineText(false);
614 }
615
616 @Override
617 public void onClick(View widget) {
618 // Close the parent dialog.
619 if (mSaverConfirmation != null) {
620 mSaverConfirmation.dismiss();
621 }
622 // Also close the notification shade, if it's open.
623 mContext.sendBroadcast(
624 new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
625 .setFlags(Intent.FLAG_RECEIVER_FOREGROUND));
626
627 final Uri uri = Uri.parse(getURL());
628 Context context = widget.getContext();
629 Intent intent = new Intent(Intent.ACTION_VIEW, uri)
630 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
631 try {
632 context.startActivity(intent);
633 } catch (ActivityNotFoundException e) {
634 Log.w(TAG, "Activity was not found for intent, " + intent.toString());
635 }
636 }
637 };
638 builder.setSpan(urlSpan, start, end, message.getSpanFlags(urlSpan));
639 }
640 return builder;
641 }
642
Makoto Onuki52c62952018-03-22 10:43:03 -0700643 private void showAutoSaverEnabledConfirmation() {
644 if (mSaverEnabledConfirmation != null) return;
645
646 // Open the Battery Saver setting page.
647 final Intent actionBatterySaverSetting =
648 new Intent(SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING)
649 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
650
651 final SystemUIDialog d = new SystemUIDialog(mContext);
652 d.setTitle(R.string.auto_saver_enabled_title);
653 d.setMessage(mContext.getString(R.string.auto_saver_enabled_text,
654 getLowBatteryAutoTriggerDefaultLevel()));
655
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700656 // "Got it". Just close the dialog. Automatic battery has been enabled already.
657 d.setPositiveButton(R.string.auto_saver_okay_action,
658 (dialog, which) -> onAutoSaverEnabledConfirmationClosed());
659
660 // "Settings" -> Opens the battery saver settings activity.
661 d.setNeutralButton(R.string.open_saver_setting_action, (dialog, which) -> {
662 mContext.startActivity(actionBatterySaverSetting);
663 onAutoSaverEnabledConfirmationClosed();
664 });
Makoto Onuki52c62952018-03-22 10:43:03 -0700665 d.setShowForAllUsers(true);
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700666 d.setOnDismissListener((dialog) -> onAutoSaverEnabledConfirmationClosed());
Makoto Onuki52c62952018-03-22 10:43:03 -0700667 d.show();
668 mSaverEnabledConfirmation = d;
669 }
670
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700671 private void onAutoSaverEnabledConfirmationClosed() {
672 mSaverEnabledConfirmation = null;
673 }
Makoto Onuki52c62952018-03-22 10:43:03 -0700674
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700675 private void setSaverMode(boolean mode, boolean needFirstTimeWarning) {
676 BatterySaverUtils.setPowerSaveMode(mContext, mode, needFirstTimeWarning);
John Spurlock3332ba52014-03-10 17:44:07 -0400677 }
678
Makoto Onuki52c62952018-03-22 10:43:03 -0700679 private void scheduleAutoBatterySaver() {
680 int autoTriggerThreshold = mContext.getResources().getInteger(
681 com.android.internal.R.integer.config_lowBatteryWarningLevel);
682 if (autoTriggerThreshold == 0) {
683 autoTriggerThreshold = 15;
684 }
685
Makoto Onuki59727732018-04-04 12:44:05 -0700686 BatterySaverUtils.ensureAutoBatterySaver(mContext, autoTriggerThreshold);
Makoto Onuki52c62952018-03-22 10:43:03 -0700687 showAutoSaverEnabledConfirmation();
688 }
689
John Spurlock3332ba52014-03-10 17:44:07 -0400690 private final class Receiver extends BroadcastReceiver {
691
692 public void init() {
693 IntentFilter filter = new IntentFilter();
John Spurlock3332ba52014-03-10 17:44:07 -0400694 filter.addAction(ACTION_SHOW_BATTERY_SETTINGS);
695 filter.addAction(ACTION_START_SAVER);
John Spurlock42bfc9a2014-10-29 11:13:01 -0400696 filter.addAction(ACTION_DISMISSED_WARNING);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800697 filter.addAction(ACTION_CLICKED_TEMP_WARNING);
698 filter.addAction(ACTION_DISMISSED_TEMP_WARNING);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700699 filter.addAction(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING);
700 filter.addAction(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING);
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700701 filter.addAction(ACTION_SHOW_START_SAVER_CONFIRMATION);
Makoto Onuki52c62952018-03-22 10:43:03 -0700702 filter.addAction(ACTION_SHOW_AUTO_SAVER_SUGGESTION);
703 filter.addAction(ACTION_ENABLE_AUTO_SAVER);
704 filter.addAction(ACTION_AUTO_SAVER_NO_THANKS);
Makoto Onuki5ac8d5e2018-04-13 15:53:57 -0700705 filter.addAction(ACTION_DISMISS_AUTO_SAVER_SUGGESTION);
John Spurlock05e07052015-06-01 10:56:42 -0400706 mContext.registerReceiverAsUser(this, UserHandle.ALL, filter,
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700707 android.Manifest.permission.DEVICE_POWER, mHandler);
John Spurlock3332ba52014-03-10 17:44:07 -0400708 }
709
710 @Override
711 public void onReceive(Context context, Intent intent) {
712 final String action = intent.getAction();
John Spurlockeb44a7d2014-06-12 13:00:55 -0400713 Slog.i(TAG, "Received " + action);
John Spurlock86c3de82014-08-19 13:37:44 -0400714 if (action.equals(ACTION_SHOW_BATTERY_SETTINGS)) {
John Spurlock3332ba52014-03-10 17:44:07 -0400715 dismissLowBatteryNotification();
716 mContext.startActivityAsUser(mOpenBatterySettings, UserHandle.CURRENT);
717 } else if (action.equals(ACTION_START_SAVER)) {
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700718 setSaverMode(true, true);
719 dismissLowBatteryNotification();
720 } else if (action.equals(ACTION_SHOW_START_SAVER_CONFIRMATION)) {
John Spurlock3332ba52014-03-10 17:44:07 -0400721 dismissLowBatteryNotification();
722 showStartSaverConfirmation();
John Spurlock42bfc9a2014-10-29 11:13:01 -0400723 } else if (action.equals(ACTION_DISMISSED_WARNING)) {
724 dismissLowBatteryWarning();
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800725 } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) {
Salvador Martineza6f7b252017-04-10 10:46:15 -0700726 dismissHighTemperatureWarningInternal();
727 showHighTemperatureDialog();
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800728 } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) {
Salvador Martineza6f7b252017-04-10 10:46:15 -0700729 dismissHighTemperatureWarningInternal();
730 } else if (ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING.equals(action)) {
731 dismissThermalShutdownWarning();
732 showThermalShutdownDialog();
733 } else if (ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING.equals(action)) {
734 dismissThermalShutdownWarning();
Makoto Onuki52c62952018-03-22 10:43:03 -0700735 } else if (ACTION_SHOW_AUTO_SAVER_SUGGESTION.equals(action)) {
736 showAutoSaverSuggestion();
737 } else if (ACTION_DISMISS_AUTO_SAVER_SUGGESTION.equals(action)) {
738 dismissAutoSaverSuggestion();
739 } else if (ACTION_ENABLE_AUTO_SAVER.equals(action)) {
740 dismissAutoSaverSuggestion();
741 scheduleAutoBatterySaver();
742 } else if (ACTION_AUTO_SAVER_NO_THANKS.equals(action)) {
743 dismissAutoSaverSuggestion();
744 BatterySaverUtils.suppressAutoBatterySaver(context);
John Spurlock3332ba52014-03-10 17:44:07 -0400745 }
746 }
747 }
John Spurlock3332ba52014-03-10 17:44:07 -0400748}