Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dce5fb61 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Dispatch BATTERY_CHANGED as foreground broadcast to SystemUI." into...

Merge "Dispatch BATTERY_CHANGED as foreground broadcast to SystemUI." into udc-qpr-dev am: 36876eb3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24840691



Change-Id: I251c286722c6ef5497b5336188c2cd16eaf53ac4
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6424b1ea 36876eb3
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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) {
        }
    }
+19 −2
Original line number Diff line number Diff line
@@ -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() {