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

Commit 03abb817 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Kill the task killers.

The ActivityManager.restartPackage() API is now deprecated, and no longer
allows applications to mess up the state of other applications.  This was
being abused by task killers, causing users to think their other applications
had bugs.

A new API is introduced for task killers,
ActivityManager.killBackgroundProcesses(), which allows these applications
to kill processes but only the same amount that the out of memory
killer does, thus causing no permanent damage.  The old restartPackage()
API is now a wrapper for calling this new API.

There is also a new private forceStopPackage() API that is used for the
system's force stop UI which does what the old restartPackage() API did.
parent 129ef0aa
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -595,6 +595,17 @@
 visibility="public"
>
</field>
<field name="KILL_BACKGROUND_PROCESSES"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;android.permission.KILL_BACKGROUND_PROCESSES&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="MANAGE_ACCOUNTS"
 type="java.lang.String"
 transient="false"
@@ -899,7 +910,7 @@
 value="&quot;android.permission.RESTART_PACKAGES&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 deprecated="deprecated"
 visibility="public"
>
</field>
@@ -17534,7 +17545,7 @@
<exception name="SecurityException" type="java.lang.SecurityException">
</exception>
</method>
<method name="restartPackage"
<method name="killBackgroundProcesses"
 return="void"
 abstract="false"
 native="false"
@@ -17547,6 +17558,19 @@
<parameter name="packageName" type="java.lang.String">
</parameter>
</method>
<method name="restartPackage"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="deprecated"
 visibility="public"
>
<parameter name="packageName" type="java.lang.String">
</parameter>
</method>
<field name="RECENT_WITH_EXCLUDED"
 type="int"
 transient="false"
+39 −3
Original line number Diff line number Diff line
@@ -890,6 +890,38 @@ public class ActivityManager {
        }
    }
    
    /**
     * @deprecated This is now just a wrapper for
     * {@link #killBackgroundProcesses(String)}; the previous behavior here
     * is no longer available to applications because it allows them to
     * break other applications by removing their alarms, stopping their
     * services, etc.
     */
    @Deprecated
    public void restartPackage(String packageName) {
        killBackgroundProcesses(packageName);
    }
    
    /**
     * Have the system immediately kill all background processes associated
     * with the given package.  This is the same as the kernel killing those
     * processes to reclaim memory; the system will take care of restarting
     * these processes in the future as needed.
     * 
     * <p>You must hold the permission
     * {@link android.Manifest.permission#KILL_BACKGROUND_PROCESSES} to be able to
     * call this method.
     * 
     * @param packageName The name of the package whose processes are to
     * be killed.
     */
    public void killBackgroundProcesses(String packageName) {
        try {
            ActivityManagerNative.getDefault().killBackgroundProcesses(packageName);
        } catch (RemoteException e) {
        }
    }
    
    /**
     * Have the system perform a force stop of everything associated with
     * the given application package.  All processes that share its uid
@@ -899,14 +931,18 @@ public class ActivityManager {
     * be stopped, notifications removed, etc.
     * 
     * <p>You must hold the permission
     * {@link android.Manifest.permission#RESTART_PACKAGES} to be able to
     * {@link android.Manifest.permission#FORCE_STOP_PACKAGES} to be able to
     * call this method.
     * 
     * @param packageName The name of the package to be stopped.
     * 
     * @hide This is not available to third party applications due to
     * it allowing them to break other applications by stopping their
     * services, removing their alarms, etc.
     */
    public void restartPackage(String packageName) {
    public void forceStopPackage(String packageName) {
        try {
            ActivityManagerNative.getDefault().restartPackage(packageName);
            ActivityManagerNative.getDefault().forceStopPackage(packageName);
        } catch (RemoteException e) {
        }
    }
+24 −5
Original line number Diff line number Diff line
@@ -1007,10 +1007,18 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case RESTART_PACKAGE_TRANSACTION: {
        case KILL_BACKGROUND_PROCESSES_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            String packageName = data.readString();
            restartPackage(packageName);
            killBackgroundProcesses(packageName);
            reply.writeNoException();
            return true;
        }
        
        case FORCE_STOP_PACKAGE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            String packageName = data.readString();
            forceStopPackage(packageName);
            reply.writeNoException();
            return true;
        }
@@ -2388,12 +2396,23 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
    }
    
    public void restartPackage(String packageName) throws RemoteException {
    public void killBackgroundProcesses(String packageName) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeString(packageName);
        mRemote.transact(KILL_BACKGROUND_PROCESSES_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }
    
    public void forceStopPackage(String packageName) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeString(packageName);
        mRemote.transact(RESTART_PACKAGE_TRANSACTION, data, reply, 0);
        mRemote.transact(FORCE_STOP_PACKAGE_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
+4 −2
Original line number Diff line number Diff line
@@ -216,7 +216,8 @@ public interface IActivityManager extends IInterface {
    
    public void getMemoryInfo(ActivityManager.MemoryInfo outInfo) throws RemoteException;
    
    public void restartPackage(final String packageName) throws RemoteException;
    public void killBackgroundProcesses(final String packageName) throws RemoteException;
    public void forceStopPackage(final String packageName) throws RemoteException;
    
    // Note: probably don't want to allow applications access to these.
    public void goingToSleep() throws RemoteException;
@@ -424,7 +425,7 @@ public interface IActivityManager extends IInterface {
    int GET_MEMORY_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+75;
    int GET_PROCESSES_IN_ERROR_STATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+76;
    int CLEAR_APP_DATA_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+77;
    int RESTART_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+78;
    int FORCE_STOP_PACKAGE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+78;
    int KILL_PIDS_FOR_MEMORY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+79;
    int GET_SERVICES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+80;
    int REPORT_PSS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+81;
@@ -448,4 +449,5 @@ public interface IActivityManager extends IInterface {
    int START_ACTIVITY_INTENT_SENDER_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+99;
    int OVERRIDE_PENDING_TRANSITION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+100;
    int HANDLE_APPLICATION_WTF_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+101;
    int KILL_BACKGROUND_PROCESSES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+102;
}
+22 −4
Original line number Diff line number Diff line
@@ -556,12 +556,30 @@
        android:label="@string/permlab_changeConfiguration"
        android:description="@string/permdesc_changeConfiguration" />

    <!-- Allows an application to restart other applications. -->
    <!-- @deprecated The {@link android.app.ActivityManager#restartPackage}
        API is no longer supported. -->
    <permission android:name="android.permission.RESTART_PACKAGES"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_restartPackages"
        android:description="@string/permdesc_restartPackages" />
        android:protectionLevel="normal"
        android:label="@string/permlab_killBackgroundProcesses"
        android:description="@string/permdesc_killBackgroundProcesses" />

    <!-- Allows an application to call
        {@link android.app.ActivityManager#killBackgroundProcesses}. -->
    <permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="normal"
        android:label="@string/permlab_killBackgroundProcesses"
        android:description="@string/permdesc_killBackgroundProcesses" />

    <!-- Allows an application to call
        {@link android.app.ActivityManager#forceStopPackage}.
        @hide -->
    <permission android:name="android.permission.FORCE_STOP_PACKAGES"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="signature"
        android:label="@string/permlab_forceStopPackages"
        android:description="@string/permdesc_forceStopPackages" />

    <!-- Allows an application to retrieve state dump information from system
         services. -->
Loading