blob: fdb0b36ee51e1bb70e9fa5a34766b2c2615b61de [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;
Christoph Studer65fa0a92014-06-26 16:50:09 +0200137
Salvador Martinezf9e47502018-01-04 13:45:48 -0800138 private Estimate mEstimate;
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800139 private long mLowWarningThreshold;
140 private long mSevereWarningThreshold;
John Spurlock3332ba52014-03-10 17:44:07 -0400141 private boolean mWarning;
Makoto Onuki52c62952018-03-22 10:43:03 -0700142 private boolean mShowAutoSaverSuggestion;
John Spurlock3332ba52014-03-10 17:44:07 -0400143 private boolean mPlaySound;
144 private boolean mInvalidCharger;
John Spurlock1bb480a2014-08-02 17:12:43 -0400145 private SystemUIDialog mSaverConfirmation;
Makoto Onuki52c62952018-03-22 10:43:03 -0700146 private SystemUIDialog mSaverEnabledConfirmation;
Salvador Martineza6f7b252017-04-10 10:46:15 -0700147 private boolean mHighTempWarning;
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800148 private SystemUIDialog mHighTempDialog;
Salvador Martineza6f7b252017-04-10 10:46:15 -0700149 private SystemUIDialog mThermalShutdownDialog;
Sherry Huangce02ed32019-01-17 20:37:29 +0800150 @VisibleForTesting SystemUIDialog mUsbHighTempDialog;
John Spurlock3332ba52014-03-10 17:44:07 -0400151
Jason Monk196d6392018-12-20 13:25:34 -0500152 /**
153 */
154 @Inject
Jason Monkd819c312017-08-11 12:53:36 -0400155 public PowerNotificationWarnings(Context context) {
John Spurlock3332ba52014-03-10 17:44:07 -0400156 mContext = context;
Jason Monkd819c312017-08-11 12:53:36 -0400157 mNoMan = mContext.getSystemService(NotificationManager.class);
John Spurlock8d4e6cb2014-09-14 11:10:22 -0400158 mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
Sherry Huangce02ed32019-01-17 20:37:29 +0800159 mKeyguard = mContext.getSystemService(KeyguardManager.class);
John Spurlock3332ba52014-03-10 17:44:07 -0400160 mReceiver.init();
161 }
162
163 @Override
164 public void dump(PrintWriter pw) {
John Spurlock3332ba52014-03-10 17:44:07 -0400165 pw.print("mWarning="); pw.println(mWarning);
166 pw.print("mPlaySound="); pw.println(mPlaySound);
167 pw.print("mInvalidCharger="); pw.println(mInvalidCharger);
168 pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]);
John Spurlock1bb480a2014-08-02 17:12:43 -0400169 pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null);
Makoto Onuki52c62952018-03-22 10:43:03 -0700170 pw.print("mSaverEnabledConfirmation=");
171 pw.println(mSaverEnabledConfirmation != null ? "not null" : null);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700172 pw.print("mHighTempWarning="); pw.println(mHighTempWarning);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800173 pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700174 pw.print("mThermalShutdownDialog=");
175 pw.println(mThermalShutdownDialog != null ? "not null" : null);
Sherry Huangce02ed32019-01-17 20:37:29 +0800176 pw.print("mUsbHighTempDialog=");
177 pw.println(mUsbHighTempDialog != null ? "not null" : null);
John Spurlock3332ba52014-03-10 17:44:07 -0400178 }
179
Makoto Onuki52c62952018-03-22 10:43:03 -0700180 private int getLowBatteryAutoTriggerDefaultLevel() {
181 return mContext.getResources().getInteger(
182 com.android.internal.R.integer.config_lowBatteryAutoTriggerDefaultLevel);
183 }
184
John Spurlock3332ba52014-03-10 17:44:07 -0400185 @Override
186 public void update(int batteryLevel, int bucket, long screenOffTime) {
187 mBatteryLevel = batteryLevel;
Christoph Studer65fa0a92014-06-26 16:50:09 +0200188 if (bucket >= 0) {
Salvador Martinezf9e47502018-01-04 13:45:48 -0800189 mWarningTriggerTimeMs = 0;
Christoph Studer65fa0a92014-06-26 16:50:09 +0200190 } else if (bucket < mBucket) {
Salvador Martinezf9e47502018-01-04 13:45:48 -0800191 mWarningTriggerTimeMs = System.currentTimeMillis();
Christoph Studer65fa0a92014-06-26 16:50:09 +0200192 }
John Spurlock3332ba52014-03-10 17:44:07 -0400193 mBucket = bucket;
194 mScreenOffTime = screenOffTime;
John Spurlock3332ba52014-03-10 17:44:07 -0400195 }
196
Salvador Martinezf9e47502018-01-04 13:45:48 -0800197 @Override
198 public void updateEstimate(Estimate estimate) {
199 mEstimate = estimate;
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800200 if (estimate.estimateMillis <= mLowWarningThreshold) {
Salvador Martinezf9e47502018-01-04 13:45:48 -0800201 mWarningTriggerTimeMs = System.currentTimeMillis();
202 }
203 }
204
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800205 @Override
206 public void updateThresholds(long lowThreshold, long severeThreshold) {
207 mLowWarningThreshold = lowThreshold;
208 mSevereWarningThreshold = severeThreshold;
209 }
210
John Spurlock3332ba52014-03-10 17:44:07 -0400211 private void updateNotification() {
John Spurlock86c3de82014-08-19 13:37:44 -0400212 if (DEBUG) Slog.d(TAG, "updateNotification mWarning=" + mWarning + " mPlaySound="
Jason Monkc06fbb12016-01-08 14:12:18 -0500213 + mPlaySound + " mInvalidCharger=" + mInvalidCharger);
John Spurlock3332ba52014-03-10 17:44:07 -0400214 if (mInvalidCharger) {
John Spurlock3332ba52014-03-10 17:44:07 -0400215 showInvalidChargerNotification();
216 mShowing = SHOWING_INVALID_CHARGER;
217 } else if (mWarning) {
John Spurlock3332ba52014-03-10 17:44:07 -0400218 showWarningNotification();
219 mShowing = SHOWING_WARNING;
Makoto Onuki52c62952018-03-22 10:43:03 -0700220 } else if (mShowAutoSaverSuggestion) {
Makoto Onuki60b8f182018-05-07 13:56:40 -0700221 // Once we showed the notification, don't show it again until it goes SHOWING_NOTHING.
222 // This shouldn't be needed, because we have a delete intent on this notification
223 // so when it's dismissed we should notice it and clear mShowAutoSaverSuggestion,
224 // However we double check here just in case the dismiss intent broadcast is delayed.
225 if (mShowing != SHOWING_AUTO_SAVER_SUGGESTION) {
226 showAutoSaverSuggestionNotification();
227 }
Makoto Onuki52c62952018-03-22 10:43:03 -0700228 mShowing = SHOWING_AUTO_SAVER_SUGGESTION;
John Spurlock3332ba52014-03-10 17:44:07 -0400229 } else {
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500230 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL);
231 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, UserHandle.ALL);
Makoto Onuki52c62952018-03-22 10:43:03 -0700232 mNoMan.cancelAsUser(TAG_AUTO_SAVER,
233 SystemMessage.NOTE_AUTO_SAVER_SUGGESTION, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400234 mShowing = SHOWING_NOTHING;
235 }
236 }
237
238 private void showInvalidChargerNotification() {
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500239 final Notification.Builder nb =
240 new Notification.Builder(mContext, NotificationChannels.ALERTS)
241 .setSmallIcon(R.drawable.ic_power_low)
242 .setWhen(0)
243 .setShowWhen(false)
244 .setOngoing(true)
245 .setContentTitle(mContext.getString(R.string.invalid_charger_title))
246 .setContentText(mContext.getString(R.string.invalid_charger_text))
247 .setColor(mContext.getColor(
248 com.android.internal.R.color.system_notification_accent_color));
Julia Reynolds037d8082018-03-18 15:25:19 -0400249 SystemUI.overrideNotificationAppName(mContext, nb, false);
John Spurlock3332ba52014-03-10 17:44:07 -0400250 final Notification n = nb.build();
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500251 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, UserHandle.ALL);
252 mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, n, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400253 }
254
Salvador Martinezf9e47502018-01-04 13:45:48 -0800255 protected void showWarningNotification() {
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800256 final String percentage = NumberFormat.getPercentInstance()
257 .format((double) mBatteryLevel / 100.0);
Beverly334bc5f2017-07-31 10:37:17 -0400258
Salvador Martinezf9e47502018-01-04 13:45:48 -0800259 // get standard notification copy
260 String title = mContext.getString(R.string.battery_low_title);
261 String contentText = mContext.getString(R.string.battery_low_percent_format, percentage);
262
263 // override notification copy if hybrid notification enabled
264 if (mEstimate != null) {
Salvador Martinezeb9ab292018-01-19 17:50:24 -0800265 contentText = getHybridContentString(percentage);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800266 }
267
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500268 final Notification.Builder nb =
Beverly334bc5f2017-07-31 10:37:17 -0400269 new Notification.Builder(mContext, NotificationChannels.BATTERY)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500270 .setSmallIcon(R.drawable.ic_power_low)
271 // Bump the notification when the bucket dropped.
Salvador Martinezf9e47502018-01-04 13:45:48 -0800272 .setWhen(mWarningTriggerTimeMs)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500273 .setShowWhen(false)
Salvador Martinezf9e47502018-01-04 13:45:48 -0800274 .setContentText(contentText)
Salvador Martinez086ab742018-04-03 13:05:39 -0700275 .setContentTitle(title)
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500276 .setOnlyAlertOnce(true)
277 .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_WARNING))
Salvador Martinez086ab742018-04-03 13:05:39 -0700278 .setStyle(new Notification.BigTextStyle().bigText(contentText))
Salvador Martinezf9e47502018-01-04 13:45:48 -0800279 .setVisibility(Notification.VISIBILITY_PUBLIC);
John Spurlock3332ba52014-03-10 17:44:07 -0400280 if (hasBatterySettings()) {
281 nb.setContentIntent(pendingBroadcast(ACTION_SHOW_BATTERY_SETTINGS));
282 }
Salvador Martinezf9e47502018-01-04 13:45:48 -0800283 // Make the notification red if the percentage goes below a certain amount or the time
284 // remaining estimate is disabled
Salvador Martinezbb902fc2018-01-22 19:46:55 -0800285 if (mEstimate == null || mBucket < 0
286 || mEstimate.estimateMillis < mSevereWarningThreshold) {
Jason Changb4e879d2018-04-11 11:17:58 +0800287 nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError));
Salvador Martinezf9e47502018-01-04 13:45:48 -0800288 }
Salvador Martinezc25604b2018-08-03 14:07:44 -0700289
290 if (!mPowerMan.isPowerSaveMode()) {
291 nb.addAction(0,
292 mContext.getString(R.string.battery_saver_start_action),
293 pendingBroadcast(ACTION_START_SAVER));
294 }
Beverly334bc5f2017-07-31 10:37:17 -0400295 nb.setOnlyAlertOnce(!mPlaySound);
296 mPlaySound = false;
Julia Reynolds037d8082018-03-18 15:25:19 -0400297 SystemUI.overrideNotificationAppName(mContext, nb, false);
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500298 final Notification n = nb.build();
299 mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL);
300 mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL);
John Spurlock3332ba52014-03-10 17:44:07 -0400301 }
302
Makoto Onuki52c62952018-03-22 10:43:03 -0700303 private void showAutoSaverSuggestionNotification() {
304 final Notification.Builder nb =
305 new Notification.Builder(mContext, NotificationChannels.HINTS)
306 .setSmallIcon(R.drawable.ic_power_saver)
307 .setWhen(0)
308 .setShowWhen(false)
309 .setContentTitle(mContext.getString(R.string.auto_saver_title))
310 .setContentText(mContext.getString(R.string.auto_saver_text,
311 getLowBatteryAutoTriggerDefaultLevel()));
312 nb.setContentIntent(pendingBroadcast(ACTION_ENABLE_AUTO_SAVER));
313 nb.setDeleteIntent(pendingBroadcast(ACTION_DISMISS_AUTO_SAVER_SUGGESTION));
314 nb.addAction(0,
315 mContext.getString(R.string.no_auto_saver_action),
316 pendingBroadcast(ACTION_AUTO_SAVER_NO_THANKS));
317
318 SystemUI.overrideNotificationAppName(mContext, nb, false);
319
320 final Notification n = nb.build();
321 mNoMan.notifyAsUser(
322 TAG_AUTO_SAVER, SystemMessage.NOTE_AUTO_SAVER_SUGGESTION, n, UserHandle.ALL);
323 }
324
Salvador Martinezeb9ab292018-01-19 17:50:24 -0800325 private String getHybridContentString(String percentage) {
326 return PowerUtil.getBatteryRemainingStringFormatted(
327 mContext,
328 mEstimate.estimateMillis,
329 percentage,
330 mEstimate.isBasedOnUsage);
Salvador Martinezf9e47502018-01-04 13:45:48 -0800331 }
332
John Spurlock3332ba52014-03-10 17:44:07 -0400333 private PendingIntent pendingBroadcast(String action) {
Makoto Onuki52c62952018-03-22 10:43:03 -0700334 return PendingIntent.getBroadcastAsUser(mContext, 0,
Makoto Onuki60b8f182018-05-07 13:56:40 -0700335 new Intent(action).setPackage(mContext.getPackageName())
336 .setFlags(Intent.FLAG_RECEIVER_FOREGROUND),
337 0, UserHandle.CURRENT);
John Spurlock3332ba52014-03-10 17:44:07 -0400338 }
339
340 private static Intent settings(String action) {
341 return new Intent(action).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
342 | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
343 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
344 | Intent.FLAG_ACTIVITY_NO_HISTORY
345 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
346 }
347
348 @Override
349 public boolean isInvalidChargerWarningShowing() {
350 return mInvalidCharger;
351 }
352
353 @Override
Salvador Martineza6f7b252017-04-10 10:46:15 -0700354 public void dismissHighTemperatureWarning() {
355 if (!mHighTempWarning) {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800356 return;
357 }
Salvador Martineza6f7b252017-04-10 10:46:15 -0700358 mHighTempWarning = false;
359 dismissHighTemperatureWarningInternal();
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800360 }
361
362 /**
Salvador Martineza6f7b252017-04-10 10:46:15 -0700363 * Internal only version of {@link #dismissHighTemperatureWarning()} that simply dismisses
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800364 * the notification. As such, the notification will not show again until
Salvador Martineza6f7b252017-04-10 10:46:15 -0700365 * {@link #dismissHighTemperatureWarning()} is called.
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800366 */
Salvador Martineza6f7b252017-04-10 10:46:15 -0700367 private void dismissHighTemperatureWarningInternal() {
Andrew Sapperstein97bfa0f2017-01-24 16:38:50 -0800368 mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, UserHandle.ALL);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800369 }
370
371 @Override
Salvador Martineza6f7b252017-04-10 10:46:15 -0700372 public void showHighTemperatureWarning() {
373 if (mHighTempWarning) {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800374 return;
375 }
Salvador Martineza6f7b252017-04-10 10:46:15 -0700376 mHighTempWarning = true;
Geoffrey Pitsch1dc93bc2017-01-31 16:38:11 -0500377 final Notification.Builder nb =
378 new Notification.Builder(mContext, NotificationChannels.ALERTS)
379 .setSmallIcon(R.drawable.ic_device_thermostat_24)
380 .setWhen(0)
381 .setShowWhen(false)
382 .setContentTitle(mContext.getString(R.string.high_temp_title))
383 .setContentText(mContext.getString(R.string.high_temp_notif_message))
384 .setVisibility(Notification.VISIBILITY_PUBLIC)
385 .setContentIntent(pendingBroadcast(ACTION_CLICKED_TEMP_WARNING))
386 .setDeleteIntent(pendingBroadcast(ACTION_DISMISSED_TEMP_WARNING))
Jason Changb4e879d2018-04-11 11:17:58 +0800387 .setColor(Utils.getColorAttrDefaultColor(mContext,
388 android.R.attr.colorError));
Julia Reynolds037d8082018-03-18 15:25:19 -0400389 SystemUI.overrideNotificationAppName(mContext, nb, false);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800390 final Notification n = nb.build();
Chris Wren5e6c0ff2017-01-05 12:57:06 -0500391 mNoMan.notifyAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_HIGH_TEMP, n, UserHandle.ALL);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800392 }
393
Salvador Martineza6f7b252017-04-10 10:46:15 -0700394 private void showHighTemperatureDialog() {
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800395 if (mHighTempDialog != null) return;
396 final SystemUIDialog d = new SystemUIDialog(mContext);
Andrew Sappersteine26dc3d2017-01-04 11:25:20 -0800397 d.setIconAttribute(android.R.attr.alertDialogIcon);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800398 d.setTitle(R.string.high_temp_title);
399 d.setMessage(R.string.high_temp_dialog_message);
400 d.setPositiveButton(com.android.internal.R.string.ok, null);
401 d.setShowForAllUsers(true);
402 d.setOnDismissListener(dialog -> mHighTempDialog = null);
403 d.show();
404 mHighTempDialog = d;
405 }
406
Salvador Martineza6f7b252017-04-10 10:46:15 -0700407 @VisibleForTesting
408 void dismissThermalShutdownWarning() {
409 mNoMan.cancelAsUser(TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, UserHandle.ALL);
410 }
411
412 private void showThermalShutdownDialog() {
413 if (mThermalShutdownDialog != null) return;
414 final SystemUIDialog d = new SystemUIDialog(mContext);
415 d.setIconAttribute(android.R.attr.alertDialogIcon);
416 d.setTitle(R.string.thermal_shutdown_title);
417 d.setMessage(R.string.thermal_shutdown_dialog_message);
418 d.setPositiveButton(com.android.internal.R.string.ok, null);
419 d.setShowForAllUsers(true);
420 d.setOnDismissListener(dialog -> mThermalShutdownDialog = null);
421 d.show();
422 mThermalShutdownDialog = d;
423 }
424
425 @Override
426 public void showThermalShutdownWarning() {
427 final Notification.Builder nb =
428 new Notification.Builder(mContext, NotificationChannels.ALERTS)
429 .setSmallIcon(R.drawable.ic_device_thermostat_24)
430 .setWhen(0)
431 .setShowWhen(false)
432 .setContentTitle(mContext.getString(R.string.thermal_shutdown_title))
433 .setContentText(mContext.getString(R.string.thermal_shutdown_message))
434 .setVisibility(Notification.VISIBILITY_PUBLIC)
435 .setContentIntent(pendingBroadcast(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING))
436 .setDeleteIntent(
437 pendingBroadcast(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING))
Jason Changb4e879d2018-04-11 11:17:58 +0800438 .setColor(Utils.getColorAttrDefaultColor(mContext,
439 android.R.attr.colorError));
Julia Reynolds037d8082018-03-18 15:25:19 -0400440 SystemUI.overrideNotificationAppName(mContext, nb, false);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700441 final Notification n = nb.build();
442 mNoMan.notifyAsUser(
443 TAG_TEMPERATURE, SystemMessage.NOTE_THERMAL_SHUTDOWN, n, UserHandle.ALL);
444 }
445
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800446 @Override
Sherry Huangce02ed32019-01-17 20:37:29 +0800447 public void showUsbHighTemperatureAlarm() {
448 mHandler.post(() -> showUsbHighTemperatureAlarmInternal());
449 }
450
451 private void showUsbHighTemperatureAlarmInternal() {
452 if (mUsbHighTempDialog != null) {
453 return;
454 }
455
456 final SystemUIDialog d = new SystemUIDialog(mContext, R.style.Theme_SystemUI_Dialog_Alert);
457 d.setCancelable(false);
458 d.setIconAttribute(android.R.attr.alertDialogIcon);
459 d.setTitle(R.string.high_temp_alarm_title);
460 d.setShowForAllUsers(true);
461 d.setMessage(mContext.getString(R.string.high_temp_alarm_notify_message, ""));
462 d.setPositiveButton((com.android.internal.R.string.ok),
463 (dialogInterface, which) -> mUsbHighTempDialog = null);
464 d.setNegativeButton((R.string.high_temp_alarm_help_care_steps),
465 (dialogInterface, which) -> {
466 final String contextString = mContext.getString(
467 R.string.high_temp_alarm_help_url);
468 final Intent helpIntent = new Intent();
469 helpIntent.setClassName("com.android.settings",
470 "com.android.settings.HelpTrampoline");
471 helpIntent.putExtra(Intent.EXTRA_TEXT, contextString);
472 Dependency.get(ActivityStarter.class).startActivity(helpIntent,
473 true /* dismissShade */, resultCode -> {
474 mUsbHighTempDialog = null;
475 });
476 });
477 d.setOnDismissListener(dialogInterface -> {
478 mUsbHighTempDialog = null;
479 Events.writeEvent(mContext, Events.EVENT_DISMISS_USB_OVERHEAT_ALARM,
480 Events.DISMISS_REASON_USB_OVERHEAD_ALARM_CHANGED,
481 mKeyguard.isKeyguardLocked());
482 });
483 d.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
484 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
485 d.show();
486 mUsbHighTempDialog = d;
487
488 Events.writeEvent(mContext, Events.EVENT_SHOW_USB_OVERHEAT_ALARM,
489 Events.SHOW_REASON_USB_OVERHEAD_ALARM_CHANGED,
490 mKeyguard.isKeyguardLocked());
491 }
492
493 @Override
John Spurlock3332ba52014-03-10 17:44:07 -0400494 public void updateLowBatteryWarning() {
495 updateNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400496 }
497
498 @Override
499 public void dismissLowBatteryWarning() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400500 if (DEBUG) Slog.d(TAG, "dismissing low battery warning: level=" + mBatteryLevel);
John Spurlock3332ba52014-03-10 17:44:07 -0400501 dismissLowBatteryNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400502 }
503
504 private void dismissLowBatteryNotification() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400505 if (mWarning) Slog.i(TAG, "dismissing low battery notification");
John Spurlock3332ba52014-03-10 17:44:07 -0400506 mWarning = false;
507 updateNotification();
508 }
509
510 private boolean hasBatterySettings() {
511 return mOpenBatterySettings.resolveActivity(mContext.getPackageManager()) != null;
512 }
513
John Spurlock3332ba52014-03-10 17:44:07 -0400514 @Override
515 public void showLowBatteryWarning(boolean playSound) {
516 Slog.i(TAG,
517 "show low battery warning: level=" + mBatteryLevel
Beverly334bc5f2017-07-31 10:37:17 -0400518 + " [" + mBucket + "] playSound=" + playSound);
John Spurlock3332ba52014-03-10 17:44:07 -0400519 mPlaySound = playSound;
520 mWarning = true;
521 updateNotification();
John Spurlock3332ba52014-03-10 17:44:07 -0400522 }
523
John Spurlock3332ba52014-03-10 17:44:07 -0400524 @Override
525 public void dismissInvalidChargerWarning() {
John Spurlockeb44a7d2014-06-12 13:00:55 -0400526 dismissInvalidChargerNotification();
John Spurlockeb44a7d2014-06-12 13:00:55 -0400527 }
528
529 private void dismissInvalidChargerNotification() {
John Spurlock3ff2de62014-06-16 13:32:48 -0400530 if (mInvalidCharger) Slog.i(TAG, "dismissing invalid charger notification");
John Spurlock3332ba52014-03-10 17:44:07 -0400531 mInvalidCharger = false;
532 updateNotification();
533 }
534
535 @Override
536 public void showInvalidChargerWarning() {
537 mInvalidCharger = true;
538 updateNotification();
539 }
540
Makoto Onuki52c62952018-03-22 10:43:03 -0700541 private void showAutoSaverSuggestion() {
542 mShowAutoSaverSuggestion = true;
543 updateNotification();
544 }
545
546 private void dismissAutoSaverSuggestion() {
547 mShowAutoSaverSuggestion = false;
548 updateNotification();
549 }
550
John Spurlockecbc5e82014-10-22 09:05:51 -0400551 @Override
552 public void userSwitched() {
553 updateNotification();
554 }
555
John Spurlock3332ba52014-03-10 17:44:07 -0400556 private void showStartSaverConfirmation() {
John Spurlock1bb480a2014-08-02 17:12:43 -0400557 if (mSaverConfirmation != null) return;
558 final SystemUIDialog d = new SystemUIDialog(mContext);
559 d.setTitle(R.string.battery_saver_confirmation_title);
Makoto Onukie8bbf952018-04-20 14:04:50 -0700560 d.setMessage(getBatterySaverDescription());
561
562 // Sad hack for http://b/78261259 and http://b/78298335. Otherwise "Battery" may be split
563 // into "Bat-tery".
564 if (isEnglishLocale()) {
565 d.setMessageHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NONE);
566 }
567 // We need to set LinkMovementMethod to make the link clickable.
568 d.setMessageMovementMethod(LinkMovementMethod.getInstance());
569
John Spurlock1bb480a2014-08-02 17:12:43 -0400570 d.setNegativeButton(android.R.string.cancel, null);
Makoto Onuki52c62952018-03-22 10:43:03 -0700571 d.setPositiveButton(R.string.battery_saver_confirmation_ok,
572 (dialog, which) -> setSaverMode(true, false));
John Spurlock1bb480a2014-08-02 17:12:43 -0400573 d.setShowForAllUsers(true);
Makoto Onuki52c62952018-03-22 10:43:03 -0700574 d.setOnDismissListener((dialog) -> mSaverConfirmation = null);
John Spurlock3332ba52014-03-10 17:44:07 -0400575 d.show();
John Spurlock1bb480a2014-08-02 17:12:43 -0400576 mSaverConfirmation = d;
John Spurlock3332ba52014-03-10 17:44:07 -0400577 }
578
Makoto Onukie8bbf952018-04-20 14:04:50 -0700579 private boolean isEnglishLocale() {
580 return Objects.equals(Locale.getDefault().getLanguage(),
581 Locale.ENGLISH.getLanguage());
582 }
583
584 /**
585 * Generates the message for the "want to start battery saver?" dialog with a "learn more" link.
586 */
587 private CharSequence getBatterySaverDescription() {
588 final String learnMoreUrl = mContext.getText(
589 R.string.help_uri_battery_saver_learn_more_link_target).toString();
590
591 // If there's no link, use the string with no "learn more".
592 if (TextUtils.isEmpty(learnMoreUrl)) {
593 return mContext.getText(
594 com.android.internal.R.string.battery_saver_description);
595 }
596
597 // If we have a link, use the string with the "learn more" link.
598 final CharSequence rawText = mContext.getText(
599 com.android.internal.R.string.battery_saver_description_with_learn_more);
600 final SpannableString message = new SpannableString(rawText);
601 final SpannableStringBuilder builder = new SpannableStringBuilder(message);
602
603 // Look for the "learn more" part of the string, and set a URL span on it.
604 // We use a customized URLSpan to add FLAG_RECEIVER_FOREGROUND to the intent, and
605 // also to close the dialog.
606 for (Annotation annotation : message.getSpans(0, message.length(), Annotation.class)) {
607 final String key = annotation.getValue();
608
609 if (!BATTERY_SAVER_DESCRIPTION_URL_KEY.equals(key)) {
610 continue;
611 }
612 final int start = message.getSpanStart(annotation);
613 final int end = message.getSpanEnd(annotation);
614
615 // Replace the "learn more" with a custom URL span, with
616 // - No underline.
617 // - When clicked, close the dialog and the notification shade.
618 final URLSpan urlSpan = new URLSpan(learnMoreUrl) {
619 @Override
620 public void updateDrawState(TextPaint ds) {
621 super.updateDrawState(ds);
622 ds.setUnderlineText(false);
623 }
624
625 @Override
626 public void onClick(View widget) {
627 // Close the parent dialog.
628 if (mSaverConfirmation != null) {
629 mSaverConfirmation.dismiss();
630 }
631 // Also close the notification shade, if it's open.
632 mContext.sendBroadcast(
633 new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
634 .setFlags(Intent.FLAG_RECEIVER_FOREGROUND));
635
636 final Uri uri = Uri.parse(getURL());
637 Context context = widget.getContext();
638 Intent intent = new Intent(Intent.ACTION_VIEW, uri)
639 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
640 try {
641 context.startActivity(intent);
642 } catch (ActivityNotFoundException e) {
643 Log.w(TAG, "Activity was not found for intent, " + intent.toString());
644 }
645 }
646 };
647 builder.setSpan(urlSpan, start, end, message.getSpanFlags(urlSpan));
648 }
649 return builder;
650 }
651
Makoto Onuki52c62952018-03-22 10:43:03 -0700652 private void showAutoSaverEnabledConfirmation() {
653 if (mSaverEnabledConfirmation != null) return;
654
655 // Open the Battery Saver setting page.
656 final Intent actionBatterySaverSetting =
657 new Intent(SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING)
658 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
659
660 final SystemUIDialog d = new SystemUIDialog(mContext);
661 d.setTitle(R.string.auto_saver_enabled_title);
662 d.setMessage(mContext.getString(R.string.auto_saver_enabled_text,
663 getLowBatteryAutoTriggerDefaultLevel()));
664
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700665 // "Got it". Just close the dialog. Automatic battery has been enabled already.
666 d.setPositiveButton(R.string.auto_saver_okay_action,
667 (dialog, which) -> onAutoSaverEnabledConfirmationClosed());
668
669 // "Settings" -> Opens the battery saver settings activity.
670 d.setNeutralButton(R.string.open_saver_setting_action, (dialog, which) -> {
671 mContext.startActivity(actionBatterySaverSetting);
672 onAutoSaverEnabledConfirmationClosed();
673 });
Makoto Onuki52c62952018-03-22 10:43:03 -0700674 d.setShowForAllUsers(true);
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700675 d.setOnDismissListener((dialog) -> onAutoSaverEnabledConfirmationClosed());
Makoto Onuki52c62952018-03-22 10:43:03 -0700676 d.show();
677 mSaverEnabledConfirmation = d;
678 }
679
Makoto Onuki41d5ccf2018-04-03 11:46:02 -0700680 private void onAutoSaverEnabledConfirmationClosed() {
681 mSaverEnabledConfirmation = null;
682 }
Makoto Onuki52c62952018-03-22 10:43:03 -0700683
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700684 private void setSaverMode(boolean mode, boolean needFirstTimeWarning) {
685 BatterySaverUtils.setPowerSaveMode(mContext, mode, needFirstTimeWarning);
John Spurlock3332ba52014-03-10 17:44:07 -0400686 }
687
Makoto Onuki52c62952018-03-22 10:43:03 -0700688 private void scheduleAutoBatterySaver() {
689 int autoTriggerThreshold = mContext.getResources().getInteger(
690 com.android.internal.R.integer.config_lowBatteryWarningLevel);
691 if (autoTriggerThreshold == 0) {
692 autoTriggerThreshold = 15;
693 }
694
Makoto Onuki59727732018-04-04 12:44:05 -0700695 BatterySaverUtils.ensureAutoBatterySaver(mContext, autoTriggerThreshold);
Makoto Onuki52c62952018-03-22 10:43:03 -0700696 showAutoSaverEnabledConfirmation();
697 }
698
John Spurlock3332ba52014-03-10 17:44:07 -0400699 private final class Receiver extends BroadcastReceiver {
700
701 public void init() {
702 IntentFilter filter = new IntentFilter();
John Spurlock3332ba52014-03-10 17:44:07 -0400703 filter.addAction(ACTION_SHOW_BATTERY_SETTINGS);
704 filter.addAction(ACTION_START_SAVER);
John Spurlock42bfc9a2014-10-29 11:13:01 -0400705 filter.addAction(ACTION_DISMISSED_WARNING);
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800706 filter.addAction(ACTION_CLICKED_TEMP_WARNING);
707 filter.addAction(ACTION_DISMISSED_TEMP_WARNING);
Salvador Martineza6f7b252017-04-10 10:46:15 -0700708 filter.addAction(ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING);
709 filter.addAction(ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING);
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700710 filter.addAction(ACTION_SHOW_START_SAVER_CONFIRMATION);
Makoto Onuki52c62952018-03-22 10:43:03 -0700711 filter.addAction(ACTION_SHOW_AUTO_SAVER_SUGGESTION);
712 filter.addAction(ACTION_ENABLE_AUTO_SAVER);
713 filter.addAction(ACTION_AUTO_SAVER_NO_THANKS);
Makoto Onuki5ac8d5e2018-04-13 15:53:57 -0700714 filter.addAction(ACTION_DISMISS_AUTO_SAVER_SUGGESTION);
John Spurlock05e07052015-06-01 10:56:42 -0400715 mContext.registerReceiverAsUser(this, UserHandle.ALL, filter,
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700716 android.Manifest.permission.DEVICE_POWER, mHandler);
John Spurlock3332ba52014-03-10 17:44:07 -0400717 }
718
719 @Override
720 public void onReceive(Context context, Intent intent) {
721 final String action = intent.getAction();
John Spurlockeb44a7d2014-06-12 13:00:55 -0400722 Slog.i(TAG, "Received " + action);
John Spurlock86c3de82014-08-19 13:37:44 -0400723 if (action.equals(ACTION_SHOW_BATTERY_SETTINGS)) {
John Spurlock3332ba52014-03-10 17:44:07 -0400724 dismissLowBatteryNotification();
725 mContext.startActivityAsUser(mOpenBatterySettings, UserHandle.CURRENT);
726 } else if (action.equals(ACTION_START_SAVER)) {
Makoto Onuki16a0dd22018-03-20 10:40:37 -0700727 setSaverMode(true, true);
728 dismissLowBatteryNotification();
729 } else if (action.equals(ACTION_SHOW_START_SAVER_CONFIRMATION)) {
John Spurlock3332ba52014-03-10 17:44:07 -0400730 dismissLowBatteryNotification();
731 showStartSaverConfirmation();
John Spurlock42bfc9a2014-10-29 11:13:01 -0400732 } else if (action.equals(ACTION_DISMISSED_WARNING)) {
733 dismissLowBatteryWarning();
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800734 } else if (ACTION_CLICKED_TEMP_WARNING.equals(action)) {
Salvador Martineza6f7b252017-04-10 10:46:15 -0700735 dismissHighTemperatureWarningInternal();
736 showHighTemperatureDialog();
Andrew Sappersteinb7caf1d2016-12-14 15:39:20 -0800737 } else if (ACTION_DISMISSED_TEMP_WARNING.equals(action)) {
Salvador Martineza6f7b252017-04-10 10:46:15 -0700738 dismissHighTemperatureWarningInternal();
739 } else if (ACTION_CLICKED_THERMAL_SHUTDOWN_WARNING.equals(action)) {
740 dismissThermalShutdownWarning();
741 showThermalShutdownDialog();
742 } else if (ACTION_DISMISSED_THERMAL_SHUTDOWN_WARNING.equals(action)) {
743 dismissThermalShutdownWarning();
Makoto Onuki52c62952018-03-22 10:43:03 -0700744 } else if (ACTION_SHOW_AUTO_SAVER_SUGGESTION.equals(action)) {
745 showAutoSaverSuggestion();
746 } else if (ACTION_DISMISS_AUTO_SAVER_SUGGESTION.equals(action)) {
747 dismissAutoSaverSuggestion();
748 } else if (ACTION_ENABLE_AUTO_SAVER.equals(action)) {
749 dismissAutoSaverSuggestion();
750 scheduleAutoBatterySaver();
751 } else if (ACTION_AUTO_SAVER_NO_THANKS.equals(action)) {
752 dismissAutoSaverSuggestion();
753 BatterySaverUtils.suppressAutoBatterySaver(context);
John Spurlock3332ba52014-03-10 17:44:07 -0400754 }
755 }
756 }
John Spurlock3332ba52014-03-10 17:44:07 -0400757}