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

Commit 1e283918 authored by Andrei Stingaceanu's avatar Andrei Stingaceanu
Browse files

Wire call to suspend a package

Adds APIs in DevicePolicyManager and PackageManager for allowing
a device admin to suspend a package. PackageManagerService sets
or unsets a new PackageUserState 'suspended' setting. Terminal
command to suspend/unsuspend has been added via
PackageManagerShellCommand (as root).

Next steps:
* use the new 'suspended' setting for denying access to start app
(probably in ActivityStackSupervisor)
* broadcast a PACKAGE_(UN)SUSPENDED intent for launchers to pick up
* remove app from recents (go further and kill it if it is running)
* erase existing notifications for this app

Bug: 22776576
Change-Id: I718b3498f6a53cc0c6fdfb6d15031e53ddca4353
parent 53129f1c
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -5767,6 +5767,7 @@ package android.app.admin {
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5825,6 +5826,7 @@ package android.app.admin {
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public boolean setPackageSuspended(android.content.ComponentName, java.lang.String, boolean);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
@@ -9097,6 +9099,7 @@ package android.content.pm {
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUSPENDED = 1073741824; // 0x40000000
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
+3 −0
Original line number Original line Diff line number Diff line
@@ -5895,6 +5895,7 @@ package android.app.admin {
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5959,6 +5960,7 @@ package android.app.admin {
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public boolean setPackageSuspended(android.content.ComponentName, java.lang.String, boolean);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
@@ -9365,6 +9367,7 @@ package android.content.pm {
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUSPENDED = 1073741824; // 0x40000000
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
+3 −0
Original line number Original line Diff line number Diff line
@@ -5767,6 +5767,7 @@ package android.app.admin {
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public int getMaximumFailedPasswordsForWipe(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public long getMaximumTimeToLock(android.content.ComponentName);
    method public boolean getPackageSuspended(android.content.ComponentName, java.lang.String);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpiration(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public long getPasswordExpirationTimeout(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
    method public int getPasswordHistoryLength(android.content.ComponentName);
@@ -5825,6 +5826,7 @@ package android.app.admin {
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMasterVolumeMuted(android.content.ComponentName, boolean);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumFailedPasswordsForWipe(android.content.ComponentName, int);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public void setMaximumTimeToLock(android.content.ComponentName, long);
    method public boolean setPackageSuspended(android.content.ComponentName, java.lang.String, boolean);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordExpirationTimeout(android.content.ComponentName, long);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordHistoryLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
    method public void setPasswordMinimumLength(android.content.ComponentName, int);
@@ -9097,6 +9099,7 @@ package android.content.pm {
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 8192; // 0x2000
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_SMALL_SCREENS = 512; // 0x200
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 524288; // 0x80000
    field public static final int FLAG_SUSPENDED = 1073741824; // 0x40000000
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_SYSTEM = 1; // 0x1
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_TEST_ONLY = 256; // 0x100
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
    field public static final int FLAG_UPDATED_SYSTEM_APP = 128; // 0x80
+10 −0
Original line number Original line Diff line number Diff line
@@ -1857,6 +1857,16 @@ public class ApplicationPackageManager extends PackageManager {
        }
        }
    }
    }


    @Override
    public boolean setPackageSuspendedAsUser(String packageName, boolean suspended, int userId) {
        try {
            return mPM.setPackageSuspendedAsUser(packageName, suspended, userId);
        } catch (RemoteException e) {
            // Should never happen!
        }
        return false;
    }

    @Override
    @Override
    public void getPackageSizeInfo(String packageName, int userHandle,
    public void getPackageSizeInfo(String packageName, int userHandle,
            IPackageStatsObserver observer) {
            IPackageStatsObserver observer) {
+42 −0
Original line number Original line Diff line number Diff line
@@ -3091,6 +3091,48 @@ public class DevicePolicyManager {
        return null;
        return null;
    }
    }


    /**
     * Called by device or profile owners for setting the package suspended for this user.
     * A suspended package will not be started by the package manager, its notifications will
     * be hidden and it will not show up in recents. The package must already be installed.
     *
     * @param admin The name of the admin component to check.
     * @param packageName The package name of the app to suspend or unsuspend.
     * @param suspended If set to {@code true} than the package will be suspended, if set to
     * {@code false} the package will be unsuspended.
     * @return boolean {@code true} if the operation was successfully performed, {@code false}
     * otherwise.
     */
    public boolean setPackageSuspended(@NonNull ComponentName admin, String packageName,
            boolean suspended) {
        if (mService != null) {
            try {
                return mService.setPackageSuspended(admin, packageName, suspended);
            } catch (RemoteException re) {
                Log.w(TAG, "Failed talking with device policy service", re);
            }
        }
        return false;
    }

    /**
     * Called by device or profile owners to determine if a package is suspended.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param packageName The name of the package to retrieve the suspended status of.
     * @return boolean {@code true} if the package is suspended, {@code false} otherwise.
     */
    public boolean getPackageSuspended(@NonNull ComponentName admin, String packageName) {
        if (mService != null) {
            try {
                return mService.getPackageSuspended(admin, packageName);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed talking with device policy service", e);
            }
        }
        return false;
    }

    /**
    /**
     * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
     * Sets the enabled state of the profile. A profile should be enabled only once it is ready to
     * be used. Only the profile owner can call this.
     * be used. Only the profile owner can call this.
Loading