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

Commit bad80e0d authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Add Activity Intent.ACTION_REQUEST_SHUTDOWN for requesting a system shutdown.



The Intent.EXTRA_KEY_CONFIRM extra can be set to require user confirmation before shutting down.
The ACTION_REQUEST_SHUTDOWN Intent is protected by android.permission.SHUTDOWN.

Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent d2fb9800
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -1408,6 +1408,17 @@ public class Intent implements Parcelable {
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
    /**
     * 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.
     *
     * <p class="note">This is a protected intent that can only be sent
     * by the system.
     *
     * {@hide}
     */
    public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
    /**
     * Broadcast Action:  Indicates low memory condition on the device
     * 
@@ -1892,6 +1903,14 @@ public class Intent implements Parcelable {
     */
    public static final String EXTRA_KEY_EVENT = "android.intent.extra.KEY_EVENT";

    /**
     * Set to true in {@link #ACTION_REQUEST_SHUTDOWN} to request confirmation from the user
     * before shutting down.
     *
     * {@hide}
     */
    public static final String EXTRA_KEY_CONFIRM = "android.intent.extra.KEY_CONFIRM";

    /**
     * Used as an 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
+10 −0
Original line number Diff line number Diff line
@@ -1130,6 +1130,16 @@
                android:exported="true">
        </activity>

        <activity android:name="com.android.server.ShutdownActivity"
            android:permission="android.permission.SHUTDOWN"
            android:excludeFromRecents="true"
            android:multiprocess="true">
            <intent-filter>
                <action android:name="android.intent.action.ACTION_REQUEST_SHUTDOWN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <service android:name="com.android.server.LoadAverageService"
            android:exported="true" />

+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.android.internal.app.ShutdownThread;

public class ShutdownActivity extends Activity {

    private static final String TAG = "ShutdownActivity";
    private boolean mConfirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mConfirm = getIntent().getBooleanExtra(Intent.EXTRA_KEY_CONFIRM, false);
        Log.i(TAG, "onCreate(): confirm=" + mConfirm);

        Handler h = new Handler();
        h.post(new Runnable() {
            public void run() {
                ShutdownThread.shutdown(ShutdownActivity.this, mConfirm);
            }
        });
    }
}