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

Commit fdc4a0e9 authored by Rupesh Bansal's avatar Rupesh Bansal Committed by Android (Google) Code Review
Browse files

Merge "A system API to shutdown the device" into main

parents 83502b27 929f4d14
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11731,6 +11731,7 @@ package android.os {
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_LOW_POWER_STANDBY, android.Manifest.permission.DEVICE_POWER}) public void setLowPowerStandbyEnabled(boolean);
    method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_LOW_POWER_STANDBY, android.Manifest.permission.DEVICE_POWER}) public void setLowPowerStandbyPolicy(@Nullable android.os.PowerManager.LowPowerStandbyPolicy);
    method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setPowerSaveModeEnabled(boolean);
    method @FlaggedApi("com.android.server.power.feature.flags.shutdown_system_api") @RequiresPermission(android.Manifest.permission.REBOOT) public void shutdown(boolean);
    method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void suppressAmbientDisplay(@NonNull String, boolean);
    method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.USER_ACTIVITY}) public void userActivity(long, int, int);
    field @RequiresPermission(android.Manifest.permission.MANAGE_LOW_POWER_STANDBY) public static final String ACTION_LOW_POWER_STANDBY_PORTS_CHANGED = "android.os.action.LOW_POWER_STANDBY_PORTS_CHANGED";
+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@ interface IPowerManager
    @UnsupportedAppUsage
    void reboot(boolean confirm, String reason, boolean wait);
    void rebootSafeMode(boolean confirm, boolean wait);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.REBOOT)")
    void shutdown(boolean confirm, String reason, boolean wait);
    void crash(String message);
    int getLastShutdownReason();
+29 −0
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.os;

import static android.app.PropertyInvalidatedCache.MODULE_SYSTEM;

import static com.android.server.power.feature.flags.Flags.FLAG_SHUTDOWN_SYSTEM_API;

import android.Manifest.permission;
import android.annotation.CallbackExecutor;
import android.annotation.CurrentTimeMillisLong;
@@ -989,6 +991,13 @@ public final class PowerManager {
     */
    public static final String SHUTDOWN_LOW_BATTERY = "battery";

    /**
     * The value to pass as the 'reason' argument to android_reboot() when the device shutdown is
     * being requested by a call to {@link PowerManager#shutdown(boolean)}
     * @hide
     */
    public static final String SHUTDOWN_SERVICE_CALL = "service";

    /**
     * @hide
     */
@@ -2766,6 +2775,26 @@ public final class PowerManager {
        }
    }

    /**
     * Shuts down the Android device.
     *
     * @param wait If true, this call waits for the shutdown to complete and does not return.
     *             Clients can use this to catch exceptions that might be thrown while shutting
     *             down the device
     *
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_SHUTDOWN_SYSTEM_API)
    @RequiresPermission(android.Manifest.permission.REBOOT)
    public void shutdown(boolean wait) {
        try {
            mService.shutdown(false, SHUTDOWN_SERVICE_CALL, wait);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * This function checks if the device has implemented Sustained Performance
     * Mode. This needs to be checked only once and is constant for a particular
+1 −0
Original line number Diff line number Diff line
@@ -7072,6 +7072,7 @@ public final class PowerManagerService extends SystemService
         * @param confirm If true, shows a shutdown confirmation dialog.
         * @param wait If true, this call waits for the shutdown to complete and does not return.
         */
        @RequiresPermission(android.Manifest.permission.REBOOT)
        @Override // Binder call
        public void shutdown(boolean confirm, String reason, boolean wait) {
            mContext.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
+7 −0
Original line number Diff line number Diff line
@@ -84,3 +84,10 @@ flag {
    description: "Feature flag to enable a new Perfetto data source for tracing app wakelocks."
    bug: "400774865"
}

flag {
    name: "shutdown_system_api"
    namespace: "power"
    description: "Feature flag to have a system API which shuts down the device."
    bug: "365055195"
}