summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/ActivityManager.java12
-rw-r--r--services/core/java/com/android/server/BatteryService.java21
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() {