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

Commit 57a7f595 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Add "adb shell am restart" command.

So you can restart the system without being root.

Change-Id: I89770f497833ecbe2b69e3a0cfafae7ef472a9f5
parent 5cf6663c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6299,6 +6299,7 @@ package android.content {
    field public static final java.lang.String EXTRA_SHORTCUT_ICON_RESOURCE = "android.intent.extra.shortcut.ICON_RESOURCE";
    field public static final java.lang.String EXTRA_SHORTCUT_INTENT = "android.intent.extra.shortcut.INTENT";
    field public static final java.lang.String EXTRA_SHORTCUT_NAME = "android.intent.extra.shortcut.NAME";
    field public static final java.lang.String EXTRA_SHUTDOWN_USERSPACE_ONLY = "android.intent.extra.SHUTDOWN_USERSPACE_ONLY";
    field public static final java.lang.String EXTRA_STREAM = "android.intent.extra.STREAM";
    field public static final java.lang.String EXTRA_SUBJECT = "android.intent.extra.SUBJECT";
    field public static final java.lang.String EXTRA_TEMPLATE = "android.intent.extra.TEMPLATE";
+16 −0
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class Am extends BaseCommand {
                "       am clear-debug-app\n" +
                "       am monitor [--gdb <port>]\n" +
                "       am hang [--allow-restart]\n" +
                "       am restart\n" +
                "       am screen-compat [on|off] <PACKAGE>\n" +
                "       am to-uri [INTENT]\n" +
                "       am to-intent-uri [INTENT]\n" +
@@ -186,6 +187,8 @@ public class Am extends BaseCommand {
                "am hang: hang the system.\n" +
                "    --allow-restart: allow watchdog to perform normal system restart\n" +
                "\n" +
                "am restart: restart the user-space system.\n" +
                "\n" +
                "am screen-compat: control screen compatibility mode of <PACKAGE>.\n" +
                "\n" +
                "am to-uri: print the given Intent specification as a URI.\n" +
@@ -290,6 +293,8 @@ public class Am extends BaseCommand {
            runMonitor();
        } else if (op.equals("hang")) {
            runHang();
        } else if (op.equals("restart")) {
            runRestart();
        } else if (op.equals("screen-compat")) {
            runScreenCompat();
        } else if (op.equals("to-uri")) {
@@ -1377,6 +1382,17 @@ public class Am extends BaseCommand {
        mAm.hang(new Binder(), allowRestart);
    }

    private void runRestart() throws Exception {
        String opt;
        while ((opt=nextOption()) != null) {
            System.err.println("Error: Unknown option: " + opt);
            return;
        }

        System.out.println("Restart the system...");
        mAm.restart();
    }

    private void runScreenCompat() throws Exception {
        String mode = nextArgRequired();
        boolean enabled;
+17 −0
Original line number Diff line number Diff line
@@ -1972,6 +1972,13 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            reply.writeNoException();
            return true;
        }

        case RESTART_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            restart();
            reply.writeNoException();
            return true;
        }
        }

        return super.onTransact(code, data, reply, flags);
@@ -4520,5 +4527,15 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
    }

    public void restart() throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        mRemote.transact(RESTART_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    private IBinder mRemote;
}
+3 −0
Original line number Diff line number Diff line
@@ -396,6 +396,8 @@ public interface IActivityManager extends IInterface {

    public void reportActivityFullyDrawn(IBinder token) throws RemoteException;

    public void restart() throws RemoteException;

    /*
     * Private non-Binder interfaces
     */
@@ -676,4 +678,5 @@ public interface IActivityManager extends IInterface {
    int CONVERT_TO_TRANSLUCENT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+174;
    int NOTIFY_ACTIVITY_DRAWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+175;
    int REPORT_ACTIVITY_FULLY_DRAWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+176;
    int RESTART_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+177;
}
+14 −0
Original line number Diff line number Diff line
@@ -1896,6 +1896,11 @@ public class Intent implements Parcelable, Cloneable {
     *
     * <p class="note">This is a protected intent that can only be sent
     * by the system.
     * <p>May include the following extras:
     * <ul>
     * <li> {@link #EXTRA_SHUTDOWN_USERSPACE_ONLY} a boolean that is set to true if this
     * shutdown is only for userspace processes.  If not set, assumed to be false.
     * </ul>
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
@@ -3260,6 +3265,15 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_MIME_TYPES = "android.intent.extra.MIME_TYPES";

    /**
     * Optional extra for {@link #ACTION_SHUTDOWN} that allows the sender to qualify that
     * this shutdown is only for the user space of the system, not a complete shutdown.
     * Hardware should not be shut down when this is true.  The default if not supplied
     * is false.
     */
    public static final String EXTRA_SHUTDOWN_USERSPACE_ONLY
            = "android.intent.extra.SHUTDOWN_USERSPACE_ONLY";

    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------
    // Intent flags (see mFlags variable).
Loading