diff options
| author | 2023-09-23 05:23:36 +0000 | |
|---|---|---|
| committer | 2023-09-23 05:23:36 +0000 | |
| commit | 36876eb338867c987cd6748c6b7d128215377639 (patch) | |
| tree | 0463f55411ef0d15ea1df2d4db8afd9b66d25fb1 | |
| parent | 5f483e0d21545156ce84fc0eae68392cb7ac1a6f (diff) | |
| parent | 8417c7bb1cbb77e8b2127234a91377d3568dab80 (diff) | |
Merge "Dispatch BATTERY_CHANGED as foreground broadcast to SystemUI." into udc-qpr-dev
| -rw-r--r-- | core/java/android/app/ActivityManager.java | 12 | ||||
| -rw-r--r-- | services/core/java/com/android/server/BatteryService.java | 21 |
2 files changed, 30 insertions, 3 deletions
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index ff0f437ea8a1..66d04a3132eb 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -5167,11 +5167,21 @@ public class ActivityManager { * @hide */ public static void broadcastStickyIntent(Intent intent, int appOp, Bundle options, int userId) { + broadcastStickyIntent(intent, null, appOp, options, userId); + } + + /** + * Convenience for sending a sticky broadcast. For internal use only. + * + * @hide + */ + public static void broadcastStickyIntent(Intent intent, String[] excludedPackages, + int appOp, Bundle options, int userId) { try { getService().broadcastIntentWithFeature( null, null, intent, null, null, Activity.RESULT_OK, null, null, null /*requiredPermissions*/, null /*excludedPermissions*/, - null /*excludedPackages*/, appOp, options, false, true, userId); + excludedPackages, appOp, options, false, true, userId); } catch (RemoteException ex) { } } diff --git a/services/core/java/com/android/server/BatteryService.java b/services/core/java/com/android/server/BatteryService.java index d94f4f22f2c9..556eba6ced76 100644 --- a/services/core/java/com/android/server/BatteryService.java +++ b/services/core/java/com/android/server/BatteryService.java @@ -167,6 +167,8 @@ public final class BatteryService extends SystemService { private int mBatteryNearlyFullLevel; private int mShutdownBatteryTemperature; + private static String sSystemUiPackage; + private int mPlugType; private int mLastPlugType = -1; // Extra state so we can detect first run @@ -228,6 +230,8 @@ public final class BatteryService extends SystemService { com.android.internal.R.integer.config_lowBatteryCloseWarningBump); mShutdownBatteryTemperature = mContext.getResources().getInteger( com.android.internal.R.integer.config_shutdownBatteryTemperature); + sSystemUiPackage = mContext.getResources().getString( + com.android.internal.R.string.config_systemUi); mBatteryLevelsEventQueue = new ArrayDeque<>(); mMetricsLogger = new MetricsLogger(); @@ -750,8 +754,21 @@ public final class BatteryService extends SystemService { + ", info:" + mHealthInfo.toString()); } - mHandler.post(() -> ActivityManager.broadcastStickyIntent(intent, AppOpsManager.OP_NONE, - mBatteryChangedOptions, UserHandle.USER_ALL)); + mHandler.post(() -> broadcastBatteryChangedIntent(intent, mBatteryChangedOptions)); + } + + private static void broadcastBatteryChangedIntent(Intent intent, Bundle options) { + // TODO (293959093): It is important that SystemUI receives this broadcast as soon as + // possible. Ideally, it should be using binder callbacks but until then, dispatch this + // as a foreground broadcast to SystemUI. + final Intent fgIntent = new Intent(intent); + fgIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + fgIntent.setPackage(sSystemUiPackage); + ActivityManager.broadcastStickyIntent(fgIntent, AppOpsManager.OP_NONE, + options, UserHandle.USER_ALL); + + ActivityManager.broadcastStickyIntent(intent, new String[] {sSystemUiPackage}, + AppOpsManager.OP_NONE, options, UserHandle.USER_ALL); } private void sendBatteryLevelChangedIntentLocked() { |