Distinguish user-requested shutdown from power-related ones

With this patch, when the user requested shutdown,
PowerManagerService sets sys.powerctl is set to
"shutdown,userrequested", and init runs fsck on shutdown.

When shutdown is triggered due to a low power state etc.,
the service sets the property to "shutdown,", and init
immediately shuts down the system without running the
command.

This is a follow-up CL for http://r.android.com/158525.

Bug: 21853106
Change-Id: Iae72990130fe9aa479c802f77301438190dbbfb3
This commit is contained in:
Yusuke Sato
2015-07-21 15:52:11 -07:00
parent 37353dc13e
commit 705ffd1efe
9 changed files with 56 additions and 25 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -367,7 +367,13 @@ public final class PowerManager {
* @hide
*/
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) {
}
}

View File

@@ -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) {
}