Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
| 17 | package com.android.systemui.power; |
| 18 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 19 | import android.content.BroadcastReceiver; |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 20 | import android.content.ContentResolver; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 24 | import android.content.pm.ActivityInfo; |
| 25 | import android.content.res.Configuration; |
Andrew Sapperstein | e335256 | 2017-01-20 15:41:03 -0800 | [diff] [blame] | 26 | import android.content.res.Resources; |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 27 | import android.database.ContentObserver; |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 28 | import android.os.BatteryManager; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 29 | import android.os.Handler; |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 30 | import android.os.HardwarePropertiesManager; |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 31 | import android.os.IBinder; |
| 32 | import android.os.IThermalEventListener; |
| 33 | import android.os.IThermalService; |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 34 | import android.os.PowerManager; |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 35 | import android.os.RemoteException; |
| 36 | import android.os.ServiceManager; |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 37 | import android.os.SystemClock; |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 38 | import android.os.Temperature; |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 39 | import android.os.UserHandle; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 40 | import android.provider.Settings; |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 41 | import android.text.format.DateUtils; |
John Spurlock | 1bb480a | 2014-08-02 17:12:43 -0400 | [diff] [blame] | 42 | import android.util.Log; |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 43 | import android.util.Slog; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 44 | |
| 45 | import com.android.internal.annotations.VisibleForTesting; |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 46 | import com.android.internal.logging.MetricsLogger; |
Salvador Martinez | 110f9a1 | 2018-01-31 09:57:17 -0800 | [diff] [blame] | 47 | import com.android.settingslib.utils.ThreadUtils; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 48 | import com.android.systemui.Dependency; |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 49 | import com.android.systemui.R; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 50 | import com.android.systemui.SystemUI; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 51 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 52 | |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 53 | import java.io.FileDescriptor; |
| 54 | import java.io.PrintWriter; |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 55 | import java.time.Duration; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 56 | import java.util.Arrays; |
| 57 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 58 | public class PowerUI extends SystemUI { |
| 59 | static final String TAG = "PowerUI"; |
John Spurlock | 1bb480a | 2014-08-02 17:12:43 -0400 | [diff] [blame] | 60 | static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 61 | private static final long TEMPERATURE_INTERVAL = 30 * DateUtils.SECOND_IN_MILLIS; |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 62 | private static final long TEMPERATURE_LOGGING_INTERVAL = DateUtils.HOUR_IN_MILLIS; |
| 63 | private static final int MAX_RECENT_TEMPS = 125; // TEMPERATURE_LOGGING_INTERVAL plus a buffer |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 64 | static final long THREE_HOURS_IN_MILLIS = DateUtils.HOUR_IN_MILLIS * 3; |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 65 | private static final int CHARGE_CYCLE_PERCENT_RESET = 45; |
| 66 | private static final long SIX_HOURS_MILLIS = Duration.ofHours(6).toMillis(); |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 67 | |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 68 | private final Handler mHandler = new Handler(); |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 69 | @VisibleForTesting |
| 70 | final Receiver mReceiver = new Receiver(); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 71 | |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 72 | private PowerManager mPowerManager; |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 73 | private HardwarePropertiesManager mHardwarePropertiesManager; |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 74 | private WarningsUI mWarnings; |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 75 | private final Configuration mLastConfiguration = new Configuration(); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 76 | private long mTimeRemaining = Long.MAX_VALUE; |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 77 | private int mPlugType = 0; |
| 78 | private int mInvalidCharger = 0; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 79 | private EnhancedEstimates mEnhancedEstimates; |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 80 | private Estimate mLastEstimate; |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 81 | private boolean mLowWarningShownThisChargeCycle; |
| 82 | private boolean mSevereWarningShownThisChargeCycle; |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 83 | |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 84 | private int mLowBatteryAlertCloseLevel; |
| 85 | private final int[] mLowBatteryReminderLevels = new int[2]; |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 86 | |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 87 | private long mScreenOffTime = -1; |
| 88 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 89 | private float mThresholdTemp; |
| 90 | private float[] mRecentTemps = new float[MAX_RECENT_TEMPS]; |
| 91 | private int mNumTemps; |
| 92 | private long mNextLogTime; |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 93 | @VisibleForTesting IThermalService mThermalService; |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 94 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 95 | @VisibleForTesting int mBatteryLevel = 100; |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 96 | @VisibleForTesting int mBatteryStatus = BatteryManager.BATTERY_STATUS_UNKNOWN; |
| 97 | |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 98 | // by using the same instance (method references are not guaranteed to be the same object |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 99 | // We create a method reference here so that we are guaranteed that we can remove a callback |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 100 | // each time they are created). |
| 101 | private final Runnable mUpdateTempCallback = this::updateTemperatureWarning; |
| 102 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 103 | public void start() { |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 104 | mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 105 | mHardwarePropertiesManager = (HardwarePropertiesManager) |
| 106 | mContext.getSystemService(Context.HARDWARE_PROPERTIES_SERVICE); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 107 | mScreenOffTime = mPowerManager.isScreenOn() ? -1 : SystemClock.elapsedRealtime(); |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 108 | mWarnings = Dependency.get(WarningsUI.class); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 109 | mEnhancedEstimates = Dependency.get(EnhancedEstimates.class); |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 110 | mLastConfiguration.setTo(mContext.getResources().getConfiguration()); |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 111 | |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 112 | ContentObserver obs = new ContentObserver(mHandler) { |
| 113 | @Override |
| 114 | public void onChange(boolean selfChange) { |
| 115 | updateBatteryWarningLevels(); |
| 116 | } |
| 117 | }; |
| 118 | final ContentResolver resolver = mContext.getContentResolver(); |
| 119 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 120 | Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL), |
| 121 | false, obs, UserHandle.USER_ALL); |
| 122 | updateBatteryWarningLevels(); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 123 | mReceiver.init(); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 124 | |
Salvador Martinez | a6f7b25 | 2017-04-10 10:46:15 -0700 | [diff] [blame] | 125 | // Check to see if we need to let the user know that the phone previously shut down due |
| 126 | // to the temperature being too high. |
| 127 | showThermalShutdownDialog(); |
| 128 | |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 129 | initTemperatureWarning(); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 130 | } |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 131 | |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 132 | @Override |
| 133 | protected void onConfigurationChanged(Configuration newConfig) { |
| 134 | final int mask = ActivityInfo.CONFIG_MCC | ActivityInfo.CONFIG_MNC; |
| 135 | |
| 136 | // Safe to modify mLastConfiguration here as it's only updated by the main thread (here). |
| 137 | if ((mLastConfiguration.updateFrom(newConfig) & mask) != 0) { |
| 138 | mHandler.post(this::initTemperatureWarning); |
| 139 | } |
| 140 | } |
| 141 | |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 142 | void updateBatteryWarningLevels() { |
| 143 | int critLevel = mContext.getResources().getInteger( |
| 144 | com.android.internal.R.integer.config_criticalBatteryWarningLevel); |
Makoto Onuki | 16a0dd2 | 2018-03-20 10:40:37 -0700 | [diff] [blame] | 145 | int warnLevel = mContext.getResources().getInteger( |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 146 | com.android.internal.R.integer.config_lowBatteryWarningLevel); |
Makoto Onuki | 4a9036b | 2018-01-11 14:48:20 -0800 | [diff] [blame] | 147 | |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 148 | if (warnLevel < critLevel) { |
| 149 | warnLevel = critLevel; |
| 150 | } |
| 151 | |
| 152 | mLowBatteryReminderLevels[0] = warnLevel; |
| 153 | mLowBatteryReminderLevels[1] = critLevel; |
| 154 | mLowBatteryAlertCloseLevel = mLowBatteryReminderLevels[0] |
| 155 | + mContext.getResources().getInteger( |
| 156 | com.android.internal.R.integer.config_lowBatteryCloseWarningBump); |
| 157 | } |
| 158 | |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Buckets the battery level. |
| 161 | * |
| 162 | * The code in this function is a little weird because I couldn't comprehend |
| 163 | * the bucket going up when the battery level was going down. --joeo |
| 164 | * |
| 165 | * 1 means that the battery is "ok" |
| 166 | * 0 means that the battery is between "ok" and what we should warn about. |
| 167 | * less than 0 means that the battery is low |
| 168 | */ |
| 169 | private int findBatteryLevelBucket(int level) { |
| 170 | if (level >= mLowBatteryAlertCloseLevel) { |
| 171 | return 1; |
| 172 | } |
Dianne Hackborn | 1427230 | 2014-06-10 23:13:02 -0700 | [diff] [blame] | 173 | if (level > mLowBatteryReminderLevels[0]) { |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 174 | return 0; |
| 175 | } |
| 176 | final int N = mLowBatteryReminderLevels.length; |
| 177 | for (int i=N-1; i>=0; i--) { |
| 178 | if (level <= mLowBatteryReminderLevels[i]) { |
| 179 | return -1-i; |
| 180 | } |
| 181 | } |
| 182 | throw new RuntimeException("not possible!"); |
| 183 | } |
| 184 | |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 185 | @VisibleForTesting |
| 186 | final class Receiver extends BroadcastReceiver { |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 187 | |
| 188 | public void init() { |
| 189 | // Register for Intent broadcasts for... |
| 190 | IntentFilter filter = new IntentFilter(); |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 191 | filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 192 | filter.addAction(Intent.ACTION_BATTERY_CHANGED); |
| 193 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
| 194 | filter.addAction(Intent.ACTION_SCREEN_ON); |
John Spurlock | ecbc5e8 | 2014-10-22 09:05:51 -0400 | [diff] [blame] | 195 | filter.addAction(Intent.ACTION_USER_SWITCHED); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 196 | mContext.registerReceiver(this, filter, null, mHandler); |
John Spurlock | 3332ba5 | 2014-03-10 17:44:07 -0400 | [diff] [blame] | 197 | } |
| 198 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 199 | @Override |
| 200 | public void onReceive(Context context, Intent intent) { |
| 201 | String action = intent.getAction(); |
Amin Shaikh | 2f6c45c | 2018-04-16 14:00:09 -0400 | [diff] [blame] | 202 | if (PowerManager.ACTION_POWER_SAVE_MODE_CHANGED.equals(action)) { |
| 203 | ThreadUtils.postOnBackgroundThread(() -> { |
| 204 | if (mPowerManager.isPowerSaveMode()) { |
| 205 | mWarnings.dismissLowBatteryWarning(); |
| 206 | } |
| 207 | }); |
| 208 | } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 209 | final int oldBatteryLevel = mBatteryLevel; |
| 210 | mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 100); |
| 211 | final int oldBatteryStatus = mBatteryStatus; |
| 212 | mBatteryStatus = intent.getIntExtra(BatteryManager.EXTRA_STATUS, |
| 213 | BatteryManager.BATTERY_STATUS_UNKNOWN); |
| 214 | final int oldPlugType = mPlugType; |
| 215 | mPlugType = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 1); |
| 216 | final int oldInvalidCharger = mInvalidCharger; |
| 217 | mInvalidCharger = intent.getIntExtra(BatteryManager.EXTRA_INVALID_CHARGER, 0); |
| 218 | |
| 219 | final boolean plugged = mPlugType != 0; |
| 220 | final boolean oldPlugged = oldPlugType != 0; |
| 221 | |
| 222 | int oldBucket = findBatteryLevelBucket(oldBatteryLevel); |
| 223 | int bucket = findBatteryLevelBucket(mBatteryLevel); |
| 224 | |
Daniel Sandler | 7198662 | 2011-07-26 13:06:49 -0400 | [diff] [blame] | 225 | if (DEBUG) { |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 226 | Slog.d(TAG, "buckets ....." + mLowBatteryAlertCloseLevel |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 227 | + " .. " + mLowBatteryReminderLevels[0] |
| 228 | + " .. " + mLowBatteryReminderLevels[1]); |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 229 | Slog.d(TAG, "level " + oldBatteryLevel + " --> " + mBatteryLevel); |
| 230 | Slog.d(TAG, "status " + oldBatteryStatus + " --> " + mBatteryStatus); |
| 231 | Slog.d(TAG, "plugType " + oldPlugType + " --> " + mPlugType); |
| 232 | Slog.d(TAG, "invalidCharger " + oldInvalidCharger + " --> " + mInvalidCharger); |
| 233 | Slog.d(TAG, "bucket " + oldBucket + " --> " + bucket); |
| 234 | Slog.d(TAG, "plugged " + oldPlugged + " --> " + plugged); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 235 | } |
| 236 | |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 237 | mWarnings.update(mBatteryLevel, bucket, mScreenOffTime); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 238 | if (oldInvalidCharger == 0 && mInvalidCharger != 0) { |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 239 | Slog.d(TAG, "showing invalid charger warning"); |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 240 | mWarnings.showInvalidChargerWarning(); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 241 | return; |
| 242 | } else if (oldInvalidCharger != 0 && mInvalidCharger == 0) { |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 243 | mWarnings.dismissInvalidChargerWarning(); |
| 244 | } else if (mWarnings.isInvalidChargerWarningShowing()) { |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 245 | // if invalid charger is showing, don't show low battery |
| 246 | return; |
| 247 | } |
| 248 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 249 | // Show the correct version of low battery warning if needed |
Salvador Martinez | 110f9a1 | 2018-01-31 09:57:17 -0800 | [diff] [blame] | 250 | ThreadUtils.postOnBackgroundThread(() -> { |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 251 | maybeShowBatteryWarning( |
| 252 | oldBatteryLevel, plugged, oldPlugged, oldBucket, bucket); |
Salvador Martinez | 110f9a1 | 2018-01-31 09:57:17 -0800 | [diff] [blame] | 253 | }); |
Beverly | 334bc5f | 2017-07-31 10:37:17 -0400 | [diff] [blame] | 254 | |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 255 | } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 256 | mScreenOffTime = SystemClock.elapsedRealtime(); |
| 257 | } else if (Intent.ACTION_SCREEN_ON.equals(action)) { |
| 258 | mScreenOffTime = -1; |
John Spurlock | ecbc5e8 | 2014-10-22 09:05:51 -0400 | [diff] [blame] | 259 | } else if (Intent.ACTION_USER_SWITCHED.equals(action)) { |
| 260 | mWarnings.userSwitched(); |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 261 | } else { |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 262 | Slog.w(TAG, "unknown intent: " + intent); |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 265 | } |
| 266 | |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 267 | protected void maybeShowBatteryWarning(int oldBatteryLevel, boolean plugged, boolean oldPlugged, |
| 268 | int oldBucket, int bucket) { |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 269 | boolean isPowerSaver = mPowerManager.isPowerSaveMode(); |
| 270 | // only play SFX when the dialog comes up or the bucket changes |
| 271 | final boolean playSound = bucket != oldBucket || oldPlugged; |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 272 | final boolean hybridEnabled = mEnhancedEstimates.isHybridNotificationEnabled(); |
| 273 | if (hybridEnabled) { |
Salvador Martinez | 926f071 | 2018-07-03 18:07:07 -0700 | [diff] [blame] | 274 | Estimate estimate = mLastEstimate; |
| 275 | if (estimate == null || mBatteryLevel != oldBatteryLevel) { |
| 276 | estimate = mEnhancedEstimates.getEstimate(); |
| 277 | mLastEstimate = estimate; |
| 278 | } |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 279 | // Turbo is not always booted once SysUI is running so we have ot make sure we actually |
| 280 | // get data back |
| 281 | if (estimate != null) { |
| 282 | mTimeRemaining = estimate.estimateMillis; |
| 283 | mWarnings.updateEstimate(estimate); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 284 | mWarnings.updateThresholds(mEnhancedEstimates.getLowWarningThreshold(), |
| 285 | mEnhancedEstimates.getSevereWarningThreshold()); |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 286 | |
| 287 | // if we are now over 45% battery & 6 hours remaining we can trigger hybrid |
| 288 | // notification again |
| 289 | if (mBatteryLevel >= CHARGE_CYCLE_PERCENT_RESET |
| 290 | && mTimeRemaining > SIX_HOURS_MILLIS) { |
| 291 | mLowWarningShownThisChargeCycle = false; |
| 292 | mSevereWarningShownThisChargeCycle = false; |
| 293 | } |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 297 | if (shouldShowLowBatteryWarning(plugged, oldPlugged, oldBucket, bucket, |
| 298 | mTimeRemaining, isPowerSaver, mBatteryStatus)) { |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 299 | mWarnings.showLowBatteryWarning(playSound); |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 300 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 301 | // mark if we've already shown a warning this cycle. This will prevent the notification |
| 302 | // trigger from spamming users by only showing low/critical warnings once per cycle |
| 303 | if (hybridEnabled) { |
Salvador Martinez | 88b0d50 | 2018-10-01 11:31:43 -0700 | [diff] [blame] | 304 | if (mTimeRemaining <= mEnhancedEstimates.getSevereWarningThreshold() |
| 305 | || mBatteryLevel <= mLowBatteryReminderLevels[1]) { |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 306 | mSevereWarningShownThisChargeCycle = true; |
Salvador Martinez | 88b0d50 | 2018-10-01 11:31:43 -0700 | [diff] [blame] | 307 | mLowWarningShownThisChargeCycle = true; |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 308 | } else { |
| 309 | mLowWarningShownThisChargeCycle = true; |
| 310 | } |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 311 | } |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 312 | } else if (shouldDismissLowBatteryWarning(plugged, oldBucket, bucket, mTimeRemaining, |
| 313 | isPowerSaver)) { |
| 314 | mWarnings.dismissLowBatteryWarning(); |
| 315 | } else { |
| 316 | mWarnings.updateLowBatteryWarning(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | @VisibleForTesting |
| 321 | boolean shouldShowLowBatteryWarning(boolean plugged, boolean oldPlugged, int oldBucket, |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 322 | int bucket, long timeRemaining, boolean isPowerSaver, int batteryStatus) { |
| 323 | if (mEnhancedEstimates.isHybridNotificationEnabled()) { |
| 324 | // triggering logic when enhanced estimate is available |
| 325 | return isEnhancedTrigger(plugged, timeRemaining, isPowerSaver, batteryStatus); |
| 326 | } |
| 327 | // legacy triggering logic |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 328 | return !plugged |
| 329 | && !isPowerSaver |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 330 | && (((bucket < oldBucket || oldPlugged) && bucket < 0)) |
| 331 | && batteryStatus != BatteryManager.BATTERY_STATUS_UNKNOWN; |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 334 | @VisibleForTesting |
| 335 | boolean shouldDismissLowBatteryWarning(boolean plugged, int oldBucket, int bucket, |
| 336 | long timeRemaining, boolean isPowerSaver) { |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 337 | final boolean hybridEnabled = mEnhancedEstimates.isHybridNotificationEnabled(); |
| 338 | final boolean hybridWouldDismiss = hybridEnabled |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 339 | && timeRemaining > mEnhancedEstimates.getLowWarningThreshold(); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 340 | final boolean standardWouldDismiss = (bucket > oldBucket && bucket > 0); |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 341 | return (isPowerSaver && !hybridEnabled) |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 342 | || plugged |
| 343 | || (standardWouldDismiss && (!mEnhancedEstimates.isHybridNotificationEnabled() |
| 344 | || hybridWouldDismiss)); |
| 345 | } |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 346 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 347 | private boolean isEnhancedTrigger(boolean plugged, long timeRemaining, boolean isPowerSaver, |
| 348 | int batteryStatus) { |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 349 | if (plugged || batteryStatus == BatteryManager.BATTERY_STATUS_UNKNOWN) { |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 350 | return false; |
| 351 | } |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 352 | int warnLevel = mLowBatteryReminderLevels[0]; |
| 353 | int critLevel = mLowBatteryReminderLevels[1]; |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 354 | |
Salvador Martinez | c25604b | 2018-08-03 14:07:44 -0700 | [diff] [blame] | 355 | // Only show the low warning once per charge cycle & no battery saver |
| 356 | final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !isPowerSaver |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 357 | && (timeRemaining < mEnhancedEstimates.getLowWarningThreshold() |
| 358 | || mBatteryLevel <= warnLevel); |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 359 | |
Salvador Martinez | fd38aa5 | 2018-03-28 23:56:59 -0700 | [diff] [blame] | 360 | // Only show the severe warning once per charge cycle |
| 361 | final boolean canShowSevereWarning = !mSevereWarningShownThisChargeCycle |
| 362 | && (timeRemaining < mEnhancedEstimates.getSevereWarningThreshold() |
| 363 | || mBatteryLevel <= critLevel); |
Salvador Martinez | 3630796 | 2018-02-08 14:29:08 -0800 | [diff] [blame] | 364 | |
| 365 | return canShowWarning || canShowSevereWarning; |
| 366 | } |
| 367 | |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 368 | private void initTemperatureWarning() { |
Andrew Sapperstein | e335256 | 2017-01-20 15:41:03 -0800 | [diff] [blame] | 369 | ContentResolver resolver = mContext.getContentResolver(); |
| 370 | Resources resources = mContext.getResources(); |
| 371 | if (Settings.Global.getInt(resolver, Settings.Global.SHOW_TEMPERATURE_WARNING, |
| 372 | resources.getInteger(R.integer.config_showTemperatureWarning)) == 0) { |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 376 | mThresholdTemp = Settings.Global.getFloat(resolver, Settings.Global.WARNING_TEMPERATURE, |
Andrew Sapperstein | e335256 | 2017-01-20 15:41:03 -0800 | [diff] [blame] | 377 | resources.getInteger(R.integer.config_warningTemperature)); |
Andrew Sapperstein | 7518471 | 2017-01-05 16:45:37 -0800 | [diff] [blame] | 378 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 379 | if (mThresholdTemp < 0f) { |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 380 | // Get the shutdown temperature, adjust for warning tolerance. |
Andrew Sapperstein | 7518471 | 2017-01-05 16:45:37 -0800 | [diff] [blame] | 381 | float[] throttlingTemps = mHardwarePropertiesManager.getDeviceTemperatures( |
| 382 | HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 383 | HardwarePropertiesManager.TEMPERATURE_SHUTDOWN); |
Andrew Sapperstein | 7518471 | 2017-01-05 16:45:37 -0800 | [diff] [blame] | 384 | if (throttlingTemps == null |
| 385 | || throttlingTemps.length == 0 |
| 386 | || throttlingTemps[0] == HardwarePropertiesManager.UNDEFINED_TEMPERATURE) { |
| 387 | return; |
| 388 | } |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 389 | mThresholdTemp = throttlingTemps[0] - |
| 390 | resources.getInteger(R.integer.config_warningTemperatureTolerance); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 391 | } |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 392 | |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 393 | if (mThermalService == null) { |
| 394 | // Enable push notifications of throttling from vendor thermal |
| 395 | // management subsystem via thermalservice, in addition to our |
| 396 | // usual polling, to react to temperature jumps more quickly. |
Wei Wang | bf05e60 | 2018-11-21 11:46:48 -0800 | [diff] [blame] | 397 | IBinder b = ServiceManager.getService(Context.THERMAL_SERVICE); |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 398 | |
| 399 | if (b != null) { |
| 400 | mThermalService = IThermalService.Stub.asInterface(b); |
| 401 | try { |
Wei Wang | bad7c20 | 2018-11-01 11:57:39 -0700 | [diff] [blame] | 402 | mThermalService.registerThermalEventListenerWithType( |
| 403 | new ThermalEventListener(), Temperature.TYPE_SKIN); |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 404 | } catch (RemoteException e) { |
| 405 | // Should never happen. |
| 406 | } |
| 407 | } else { |
| 408 | Slog.w(TAG, "cannot find thermalservice, no throttling push notifications"); |
| 409 | } |
| 410 | } |
| 411 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 412 | setNextLogTime(); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 413 | |
| 414 | // We have passed all of the checks, start checking the temp |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 415 | mHandler.post(mUpdateTempCallback); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Salvador Martinez | a6f7b25 | 2017-04-10 10:46:15 -0700 | [diff] [blame] | 418 | private void showThermalShutdownDialog() { |
| 419 | if (mPowerManager.getLastShutdownReason() |
| 420 | == PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN) { |
| 421 | mWarnings.showThermalShutdownWarning(); |
| 422 | } |
| 423 | } |
| 424 | |
Jason Monk | d819c31 | 2017-08-11 12:53:36 -0400 | [diff] [blame] | 425 | @VisibleForTesting |
| 426 | protected void updateTemperatureWarning() { |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 427 | float[] temps = mHardwarePropertiesManager.getDeviceTemperatures( |
| 428 | HardwarePropertiesManager.DEVICE_TEMPERATURE_SKIN, |
| 429 | HardwarePropertiesManager.TEMPERATURE_CURRENT); |
| 430 | if (temps.length != 0) { |
| 431 | float temp = temps[0]; |
| 432 | mRecentTemps[mNumTemps++] = temp; |
| 433 | |
| 434 | StatusBar statusBar = getComponent(StatusBar.class); |
| 435 | if (statusBar != null && !statusBar.isDeviceInVrMode() |
| 436 | && temp >= mThresholdTemp) { |
| 437 | logAtTemperatureThreshold(temp); |
Salvador Martinez | a6f7b25 | 2017-04-10 10:46:15 -0700 | [diff] [blame] | 438 | mWarnings.showHighTemperatureWarning(); |
Andrew Sapperstein | 65d8a5f | 2016-12-19 14:36:33 -0800 | [diff] [blame] | 439 | } else { |
Salvador Martinez | a6f7b25 | 2017-04-10 10:46:15 -0700 | [diff] [blame] | 440 | mWarnings.dismissHighTemperatureWarning(); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 441 | } |
| 442 | } |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 443 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 444 | logTemperatureStats(); |
| 445 | |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 446 | // Remove any pending callbacks as we only want to enable one |
| 447 | mHandler.removeCallbacks(mUpdateTempCallback); |
Adam Lesinski | 1aab3fa | 2017-07-31 13:42:00 -0700 | [diff] [blame] | 448 | mHandler.postDelayed(mUpdateTempCallback, TEMPERATURE_INTERVAL); |
Andrew Sapperstein | b7caf1d | 2016-12-14 15:39:20 -0800 | [diff] [blame] | 449 | } |
| 450 | |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 451 | private void logAtTemperatureThreshold(float temp) { |
| 452 | StringBuilder sb = new StringBuilder(); |
| 453 | sb.append("currentTemp=").append(temp) |
| 454 | .append(",thresholdTemp=").append(mThresholdTemp) |
| 455 | .append(",batteryStatus=").append(mBatteryStatus) |
| 456 | .append(",recentTemps="); |
| 457 | for (int i = 0; i < mNumTemps; i++) { |
| 458 | sb.append(mRecentTemps[i]).append(','); |
| 459 | } |
| 460 | Slog.i(TAG, sb.toString()); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Calculates and logs min, max, and average |
| 465 | * {@link HardwarePropertiesManager#DEVICE_TEMPERATURE_SKIN} over the past |
| 466 | * {@link #TEMPERATURE_LOGGING_INTERVAL}. |
| 467 | */ |
| 468 | private void logTemperatureStats() { |
| 469 | if (mNextLogTime > System.currentTimeMillis() && mNumTemps != MAX_RECENT_TEMPS) { |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | if (mNumTemps > 0) { |
| 474 | float sum = mRecentTemps[0], min = mRecentTemps[0], max = mRecentTemps[0]; |
| 475 | for (int i = 1; i < mNumTemps; i++) { |
| 476 | float temp = mRecentTemps[i]; |
| 477 | sum += temp; |
| 478 | if (temp > max) { |
| 479 | max = temp; |
| 480 | } |
| 481 | if (temp < min) { |
| 482 | min = temp; |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | float avg = sum / mNumTemps; |
| 487 | Slog.i(TAG, "avg=" + avg + ",min=" + min + ",max=" + max); |
| 488 | MetricsLogger.histogram(mContext, "device_skin_temp_avg", (int) avg); |
| 489 | MetricsLogger.histogram(mContext, "device_skin_temp_min", (int) min); |
| 490 | MetricsLogger.histogram(mContext, "device_skin_temp_max", (int) max); |
| 491 | } |
| 492 | setNextLogTime(); |
| 493 | mNumTemps = 0; |
| 494 | } |
| 495 | |
| 496 | private void setNextLogTime() { |
| 497 | mNextLogTime = System.currentTimeMillis() + TEMPERATURE_LOGGING_INTERVAL; |
| 498 | } |
| 499 | |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 500 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 501 | pw.print("mLowBatteryAlertCloseLevel="); |
| 502 | pw.println(mLowBatteryAlertCloseLevel); |
| 503 | pw.print("mLowBatteryReminderLevels="); |
| 504 | pw.println(Arrays.toString(mLowBatteryReminderLevels)); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 505 | pw.print("mBatteryLevel="); |
| 506 | pw.println(Integer.toString(mBatteryLevel)); |
| 507 | pw.print("mBatteryStatus="); |
| 508 | pw.println(Integer.toString(mBatteryStatus)); |
| 509 | pw.print("mPlugType="); |
| 510 | pw.println(Integer.toString(mPlugType)); |
| 511 | pw.print("mInvalidCharger="); |
| 512 | pw.println(Integer.toString(mInvalidCharger)); |
Daniel Sandler | dea6462 | 2013-09-23 16:05:57 -0400 | [diff] [blame] | 513 | pw.print("mScreenOffTime="); |
| 514 | pw.print(mScreenOffTime); |
| 515 | if (mScreenOffTime >= 0) { |
| 516 | pw.print(" ("); |
| 517 | pw.print(SystemClock.elapsedRealtime() - mScreenOffTime); |
| 518 | pw.print(" ago)"); |
| 519 | } |
| 520 | pw.println(); |
| 521 | pw.print("soundTimeout="); |
| 522 | pw.println(Settings.Global.getInt(mContext.getContentResolver(), |
| 523 | Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, 0)); |
Joe Onorato | 4ca7f1e | 2010-10-27 15:32:23 -0700 | [diff] [blame] | 524 | pw.print("bucket: "); |
| 525 | pw.println(Integer.toString(findBatteryLevelBucket(mBatteryLevel))); |
Andrew Sapperstein | a6ed7f8 | 2017-02-01 17:13:08 -0800 | [diff] [blame] | 526 | pw.print("mThresholdTemp="); |
| 527 | pw.println(Float.toString(mThresholdTemp)); |
| 528 | pw.print("mNextLogTime="); |
| 529 | pw.println(Long.toString(mNextLogTime)); |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 530 | mWarnings.dump(pw); |
| 531 | } |
| 532 | |
| 533 | public interface WarningsUI { |
| 534 | void update(int batteryLevel, int bucket, long screenOffTime); |
Salvador Martinez | f9e4750 | 2018-01-04 13:45:48 -0800 | [diff] [blame] | 535 | void updateEstimate(Estimate estimate); |
Salvador Martinez | bb902fc | 2018-01-22 19:46:55 -0800 | [diff] [blame] | 536 | void updateThresholds(long lowThreshold, long severeThreshold); |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 537 | void dismissLowBatteryWarning(); |
| 538 | void showLowBatteryWarning(boolean playSound); |
| 539 | void dismissInvalidChargerWarning(); |
| 540 | void showInvalidChargerWarning(); |
| 541 | void updateLowBatteryWarning(); |
| 542 | boolean isInvalidChargerWarningShowing(); |
Salvador Martinez | a6f7b25 | 2017-04-10 10:46:15 -0700 | [diff] [blame] | 543 | void dismissHighTemperatureWarning(); |
| 544 | void showHighTemperatureWarning(); |
| 545 | void showThermalShutdownWarning(); |
John Spurlock | ed452c5 | 2014-03-06 12:02:31 -0500 | [diff] [blame] | 546 | void dump(PrintWriter pw); |
John Spurlock | ecbc5e8 | 2014-10-22 09:05:51 -0400 | [diff] [blame] | 547 | void userSwitched(); |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 548 | } |
Joe Onorato | 10523b4d | 2010-10-25 10:42:46 -0700 | [diff] [blame] | 549 | |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 550 | // Thermal event received from vendor thermal management subsystem |
| 551 | private final class ThermalEventListener extends IThermalEventListener.Stub { |
Wei Wang | bad7c20 | 2018-11-01 11:57:39 -0700 | [diff] [blame] | 552 | @Override public void notifyThrottling(Temperature temp) { |
Wei Wang | feb9de6 | 2018-11-26 14:35:17 -0800 | [diff] [blame] | 553 | mHandler.post(mUpdateTempCallback); |
Todd Poynor | fb95e12 | 2017-10-04 13:00:32 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |