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

Commit 55280a91 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Improve shutdown process to send broadcast for applications.

This introduces a new class in the base platform for performing a clean
shutdown (which was copied from the classes in the policies).  It
includes new features to send a shutdown broadcast for applications
to do cleanup, and ot have the activity manager pause the current
activity before proceeding with the shutdown.  These facilities are
also use to write at the most recent stat files for sync, battery
and user activity.
parent 672f1e2b
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -1013,6 +1013,17 @@
 visibility="public"
>
</field>
<field name="SHUTDOWN"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.permission.SHUTDOWN&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="SIGNAL_PERSISTENT_PROCESSES"
 type="java.lang.String"
 transient="false"
@@ -28790,6 +28801,17 @@
 visibility="public"
>
</field>
<field name="ACTION_SHUTDOWN"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.intent.action.ACTION_SHUTDOWN&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="ACTION_SYNC"
 type="java.lang.String"
 transient="false"
+22 −0
Original line number Diff line number Diff line
@@ -990,6 +990,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }
        
        case SHUTDOWN_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            boolean res = shutdown(data.readInt());
            reply.writeNoException();
            reply.writeInt(res ? 1 : 0);
            return true;
        }
        
        case PEEK_SERVICE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            Intent service = Intent.CREATOR.createFromParcel(data);
@@ -2160,5 +2168,19 @@ class ActivityManagerProxy implements IActivityManager
        return res;
    }
    
    public boolean shutdown(int timeout) throws RemoteException
    {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeInt(timeout);
        mRemote.transact(SHUTDOWN_TRANSACTION, data, reply, 0);
        reply.readException();
        boolean res = reply.readInt() != 0;
        reply.recycle();
        data.recycle();
        return res;
    }
    
    private IBinder mRemote;
}
+3 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.app;

import android.app.ActivityManager.MemoryInfo;
import android.content.ComponentName;
import android.content.ContentProviderNative;
import android.content.IContentProvider;
@@ -34,7 +33,6 @@ import android.os.IInterface;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.os.Bundle;

import java.util.List;
@@ -225,6 +223,8 @@ public interface IActivityManager extends IInterface {
    public boolean profileControl(String process, boolean start,
            String path) throws RemoteException;
    
    public boolean shutdown(int timeout) throws RemoteException;
    
    /*
     * Private non-Binder interfaces
     */
@@ -370,4 +370,5 @@ public interface IActivityManager extends IInterface {
    int GET_DEVICE_CONFIGURATION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+83;
    int PEEK_SERVICE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+84;
    int PROFILE_CONTROL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+85;
    int SHUTDOWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+86;
}
+10 −0
Original line number Diff line number Diff line
@@ -510,6 +510,7 @@ import java.util.Set;
 *     <li> {@link #ACTION_BATTERY_CHANGED}
 *     <li> {@link #ACTION_POWER_CONNECTED}
 *     <li> {@link #ACTION_POWER_DISCONNECTED} 
 *     <li> {@link #ACTION_SHUTDOWN} 
 * </ul>
 *
 * <h3>Standard Categories</h3>
@@ -1269,6 +1270,15 @@ public class Intent implements Parcelable {
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED";    
    /**
     * Broadcast Action:  Device is shutting down.
     * This is broadcast when the device is being shut down (completely turned
     * off, not sleeping).  Once the broadcast is complete, the final shutdown
     * will proceed and all unsaved data lost.  Apps will not normally need
     * to handle this, since the forground activity will be paused as well.
     */
    @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
    public static final String ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";    
    /**
     * Broadcast Action:  Indicates low memory condition on the device
     */
+12 −0
Original line number Diff line number Diff line
@@ -212,6 +212,14 @@ class SyncManager {
        }
    };

    private BroadcastReceiver mShutdownIntentReceiver =
            new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            Log.w(TAG, "Writing sync state before shutdown...");
            getSyncStorageEngine().writeAllState();
        }
    };

    private static final String ACTION_SYNC_ALARM = "android.content.syncmanager.SYNC_ALARM";
    private static final String SYNC_POLL_ALARM = "android.content.syncmanager.SYNC_POLL_ALARM";
    private final SyncHandler mSyncHandler;
@@ -249,6 +257,10 @@ class SyncManager {
        intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
        context.registerReceiver(mStorageIntentReceiver, intentFilter);

        intentFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
        intentFilter.setPriority(100);
        context.registerReceiver(mShutdownIntentReceiver, intentFilter);

        if (!factoryTest) {
            mNotificationMgr = (NotificationManager)
                context.getSystemService(Context.NOTIFICATION_SERVICE);
Loading