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

Commit c13053bf authored by Kenny Guy's avatar Kenny Guy
Browse files

Add package state to block uninstall.

Add package state to allow profile or device
owners to block uninstall of packages.
Add API to DevicePolicyManager to set/get the
state.

Bug: 14127299
Change-Id: I03528819850b42df7bafa7747bb9e4558d20c4e6
parent fb2f7d60
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5259,6 +5259,7 @@ package android.app.admin {
    method public java.lang.String[] getAccountTypesWithManagementDisabled();
    method public java.util.List<android.content.ComponentName> getActiveAdmins();
    method public android.os.Bundle getApplicationRestrictions(android.content.ComponentName, java.lang.String);
    method public boolean getBlockUninstall(android.content.ComponentName, java.lang.String);
    method public boolean getCameraDisabled(android.content.ComponentName);
    method public int getCurrentFailedPasswordAttempts();
    method public int getKeyguardDisabledFeatures(android.content.ComponentName);
@@ -5297,6 +5298,7 @@ package android.app.admin {
    method public boolean setApplicationBlocked(android.content.ComponentName, java.lang.String, boolean);
    method public void setApplicationRestrictions(android.content.ComponentName, java.lang.String, android.os.Bundle);
    method public int setApplicationsBlocked(android.content.ComponentName, android.content.Intent, boolean);
    method public void setBlockUninstall(android.content.ComponentName, java.lang.String, boolean);
    method public void setCameraDisabled(android.content.ComponentName, boolean);
    method public void setGlobalSetting(android.content.ComponentName, java.lang.String, java.lang.String);
    method public void setKeyguardDisabledFeatures(android.content.ComponentName, int);
+37 −0
Original line number Diff line number Diff line
@@ -2685,4 +2685,41 @@ public class DevicePolicyManager {
        }
        return false;
    }

    /**
     * Called by profile or device owners to change whether a user can uninstall
     * a package.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param packageName package to change.
     * @param blockUninstall true if the user shouldn't be able to uninstall the package.
     */
    public void setBlockUninstall(ComponentName admin, String packageName, boolean blockUninstall) {
        if (mService != null) {
            try {
                mService.setBlockUninstall(admin, packageName, blockUninstall);
            } catch (RemoteException re) {
                Log.w(TAG, "Failed to call block uninstall on device policy service");
            }
        }
    }

    /**
     * Called by profile or device owners to check whether a user has been blocked from
     * uninstalling a package.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param packageName package to check.
     * @return true if the user shouldn't be able to uninstall the package.
     */
    public boolean getBlockUninstall(ComponentName admin, String packageName) {
        if (mService != null) {
            try {
                return mService.getBlockUninstall(admin, packageName);
            } catch (RemoteException re) {
                Log.w(TAG, "Failed to call block uninstall on device policy service");
            }
        }
        return false;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -154,4 +154,7 @@ interface IDevicePolicyManager {
    boolean isMasterVolumeMuted(in ComponentName admin);

    void notifyLockTaskModeChanged(boolean isEnabled, String pkg, int userId);

    void setBlockUninstall(in ComponentName admin, in String packageName, boolean blockUninstall);
    boolean getBlockUninstall(in ComponentName admin, in String packageName);
}
+3 −0
Original line number Diff line number Diff line
@@ -463,4 +463,7 @@ interface IPackageManager {
    boolean getApplicationBlockedSettingAsUser(String packageName, int userId);

    IPackageInstaller getPackageInstaller();

    boolean setBlockUninstallForUser(String packageName, boolean blockUninstall, int userId);
    boolean getBlockUninstallForUser(String packageName, int userId);
}
+9 −0
Original line number Diff line number Diff line
@@ -840,6 +840,15 @@ public abstract class PackageManager {
     */
    public static final int DELETE_FAILED_USER_RESTRICTED = -3;

    /**
     * Deletion failed return code: this is returned from the PackageInstaller
     * activity if it failed to delete a package because the a profile
     * or device owner has marked the package as uninstallable.
     *
     * @hide
     */
    public static final int DELETE_FAILED_OWNER_BLOCKED= -4;

    /**
     * Return code that is passed to the {@link IPackageMoveObserver} by
     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} when the
Loading