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

Commit 158560ad authored by Yusuke Sato's avatar Yusuke Sato Committed by Gerrit Code Review
Browse files

Merge "Distinguish user-requested shutdown from power-related ones"

parents f8a6a2f6 705ffd1e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ public class PowerCommand extends Svc.Command {
                } else if ("shutdown".equals(args[1])) {
                    try {
                        // no confirm, wait till device is off
                        pm.shutdown(false, true);
                        pm.shutdown(false, null, true);
                    } catch (RemoteException e) {
                        System.err.println("Failed to shutdown.");
                    }
+12 −1
Original line number Diff line number Diff line
@@ -2018,7 +2018,9 @@ public class Intent implements Parcelable, Cloneable {
    /**
     * Activity Action:  Start this activity to request system shutdown.
     * The optional boolean extra field {@link #EXTRA_KEY_CONFIRM} can be set to true
     * to request confirmation from the user before shutting down.
     * to request confirmation from the user before shutting down. The optional boolean
     * extra field {@link #EXTRA_USER_REQUESTED_SHUTDOWN} can be set to true to
     * indicate that the shutdown is requested by the user.
     *
     * <p class="note">This is a protected intent that can only be sent
     * by the system.
@@ -3228,6 +3230,15 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";

    /**
     * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to indicate that the shutdown is
     * requested by the user.
     *
     * {@hide}
     */
    public static final String EXTRA_USER_REQUESTED_SHUTDOWN =
            "android.intent.extra.USER_REQUESTED_SHUTDOWN";

    /**
     * Used as a boolean extra field in {@link android.content.Intent#ACTION_PACKAGE_REMOVED} or
     * {@link android.content.Intent#ACTION_PACKAGE_CHANGED} intents to override the default action
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ interface IPowerManager
    boolean setPowerSaveMode(boolean mode);

    void reboot(boolean confirm, String reason, boolean wait);
    void shutdown(boolean confirm, boolean wait);
    void shutdown(boolean confirm, String reason, boolean wait);
    void crash(String message);

    void setStayOnSetting(int val);
+10 −3
Original line number Diff line number Diff line
@@ -368,6 +368,12 @@ public final class PowerManager {
     */
    public static final String REBOOT_RECOVERY = "recovery";

    /**
     * The value to pass as the 'reason' argument to android_reboot().
     * @hide
     */
    public static final String SHUTDOWN_USER_REQUESTED = "userrequested";

    final Context mContext;
    final IPowerManager mService;
    final Handler mHandler;
@@ -838,13 +844,14 @@ public final class PowerManager {
     * Turn off the device.
     *
     * @param confirm If true, shows a shutdown confirmation dialog.
     * @param reason code to pass to android_reboot() (e.g. "userrequested"), or null.
     * @param wait If true, this call waits for the shutdown to complete and does not return.
     *
     * @hide
     */
    public void shutdown(boolean confirm, boolean wait) {
    public void shutdown(boolean confirm, String reason, boolean wait) {
        try {
            mService.shutdown(confirm, wait);
            mService.shutdown(confirm, reason, wait);
        } catch (RemoteException e) {
        }
    }
+6 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.IPowerManager;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Slog;
@@ -30,6 +31,7 @@ public class ShutdownActivity extends Activity {
    private static final String TAG = "ShutdownActivity";
    private boolean mReboot;
    private boolean mConfirm;
    private boolean mUserRequested;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -38,6 +40,7 @@ public class ShutdownActivity extends Activity {
        Intent intent = getIntent();
        mReboot = Intent.ACTION_REBOOT.equals(intent.getAction());
        mConfirm = intent.getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
        mUserRequested = intent.getBooleanExtra(Intent.EXTRA_USER_REQUESTED_SHUTDOWN, false);
        Slog.i(TAG, "onCreate(): confirm=" + mConfirm);

        Thread thr = new Thread("ShutdownActivity") {
@@ -49,7 +52,9 @@ public class ShutdownActivity extends Activity {
                    if (mReboot) {
                        pm.reboot(mConfirm, null, false);
                    } else {
                        pm.shutdown(mConfirm, false);
                        pm.shutdown(mConfirm,
                                    mUserRequested ? PowerManager.SHUTDOWN_USER_REQUESTED : null,
                                    false);
                    }
                } catch (RemoteException e) {
                }
Loading