Loading packages/SettingsLib/src/com/android/settingslib/utils/ThreadUtils.java +5 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Looper; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class ThreadUtils { Loading Loading @@ -59,12 +60,14 @@ public class ThreadUtils { /** * Posts runnable in background using shared background thread pool. * * @Return A future of the task that can be monitored for updates or cancelled. */ public static void postOnBackgroundThread(Runnable runnable) { public static Future postOnBackgroundThread(Runnable runnable) { if (sSingleThreadExecutor == null) { sSingleThreadExecutor = Executors.newSingleThreadExecutor(); } sSingleThreadExecutor.execute(runnable); return sSingleThreadExecutor.submit(runnable); } /** Loading packages/SystemUI/src/com/android/systemui/power/PowerUI.java +23 −5 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.time.Duration; import java.util.Arrays; import java.util.concurrent.Future; public class PowerUI extends SystemUI { static final String TAG = "PowerUI"; Loading @@ -80,6 +81,7 @@ public class PowerUI extends SystemUI { private Estimate mLastEstimate; private boolean mLowWarningShownThisChargeCycle; private boolean mSevereWarningShownThisChargeCycle; private Future mLastShowWarningTask; private int mLowBatteryAlertCloseLevel; private final int[] mLowBatteryReminderLevels = new int[2]; Loading Loading @@ -247,7 +249,10 @@ public class PowerUI extends SystemUI { } // Show the correct version of low battery warning if needed ThreadUtils.postOnBackgroundThread(() -> { if (mLastShowWarningTask != null) { mLastShowWarningTask.cancel(true); } mLastShowWarningTask = ThreadUtils.postOnBackgroundThread(() -> { maybeShowBatteryWarning( oldBatteryLevel, plugged, oldPlugged, oldBucket, bucket); }); Loading Loading @@ -276,7 +281,7 @@ public class PowerUI extends SystemUI { estimate = mEnhancedEstimates.getEstimate(); mLastEstimate = estimate; } // Turbo is not always booted once SysUI is running so we have ot make sure we actually // Turbo is not always booted once SysUI is running so we have to make sure we actually // get data back if (estimate != null) { mTimeRemaining = estimate.estimateMillis; Loading Loading @@ -362,6 +367,19 @@ public class PowerUI extends SystemUI { && (timeRemaining < mEnhancedEstimates.getSevereWarningThreshold() || mBatteryLevel <= critLevel); final boolean canShow = canShowWarning || canShowSevereWarning; if (DEBUG) { Slog.d(TAG, "Enhanced trigger is: " + canShow + "\nwith values: " + " mLowWarningShownThisChargeCycle: " + mLowWarningShownThisChargeCycle + " mSevereWarningShownThisChargeCycle: " + mSevereWarningShownThisChargeCycle + " mEnhancedEstimates.timeremaining: " + timeRemaining + " mBatteryLevel: " + mBatteryLevel + " canShowWarning: " + canShowWarning + " canShowSevereWarning: " + canShowSevereWarning + " plugged: " + plugged + " batteryStatus: " + batteryStatus + " isPowerSaver: " + isPowerSaver); } return canShowWarning || canShowSevereWarning; } Loading Loading
packages/SettingsLib/src/com/android/settingslib/utils/ThreadUtils.java +5 −2 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.os.Looper; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; public class ThreadUtils { Loading Loading @@ -59,12 +60,14 @@ public class ThreadUtils { /** * Posts runnable in background using shared background thread pool. * * @Return A future of the task that can be monitored for updates or cancelled. */ public static void postOnBackgroundThread(Runnable runnable) { public static Future postOnBackgroundThread(Runnable runnable) { if (sSingleThreadExecutor == null) { sSingleThreadExecutor = Executors.newSingleThreadExecutor(); } sSingleThreadExecutor.execute(runnable); return sSingleThreadExecutor.submit(runnable); } /** Loading
packages/SystemUI/src/com/android/systemui/power/PowerUI.java +23 −5 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ import java.io.FileDescriptor; import java.io.PrintWriter; import java.time.Duration; import java.util.Arrays; import java.util.concurrent.Future; public class PowerUI extends SystemUI { static final String TAG = "PowerUI"; Loading @@ -80,6 +81,7 @@ public class PowerUI extends SystemUI { private Estimate mLastEstimate; private boolean mLowWarningShownThisChargeCycle; private boolean mSevereWarningShownThisChargeCycle; private Future mLastShowWarningTask; private int mLowBatteryAlertCloseLevel; private final int[] mLowBatteryReminderLevels = new int[2]; Loading Loading @@ -247,7 +249,10 @@ public class PowerUI extends SystemUI { } // Show the correct version of low battery warning if needed ThreadUtils.postOnBackgroundThread(() -> { if (mLastShowWarningTask != null) { mLastShowWarningTask.cancel(true); } mLastShowWarningTask = ThreadUtils.postOnBackgroundThread(() -> { maybeShowBatteryWarning( oldBatteryLevel, plugged, oldPlugged, oldBucket, bucket); }); Loading Loading @@ -276,7 +281,7 @@ public class PowerUI extends SystemUI { estimate = mEnhancedEstimates.getEstimate(); mLastEstimate = estimate; } // Turbo is not always booted once SysUI is running so we have ot make sure we actually // Turbo is not always booted once SysUI is running so we have to make sure we actually // get data back if (estimate != null) { mTimeRemaining = estimate.estimateMillis; Loading Loading @@ -362,6 +367,19 @@ public class PowerUI extends SystemUI { && (timeRemaining < mEnhancedEstimates.getSevereWarningThreshold() || mBatteryLevel <= critLevel); final boolean canShow = canShowWarning || canShowSevereWarning; if (DEBUG) { Slog.d(TAG, "Enhanced trigger is: " + canShow + "\nwith values: " + " mLowWarningShownThisChargeCycle: " + mLowWarningShownThisChargeCycle + " mSevereWarningShownThisChargeCycle: " + mSevereWarningShownThisChargeCycle + " mEnhancedEstimates.timeremaining: " + timeRemaining + " mBatteryLevel: " + mBatteryLevel + " canShowWarning: " + canShowWarning + " canShowSevereWarning: " + canShowSevereWarning + " plugged: " + plugged + " batteryStatus: " + batteryStatus + " isPowerSaver: " + isPowerSaver); } return canShowWarning || canShowSevereWarning; } Loading