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

Commit c39bb4aa authored by Kenny Root's avatar Kenny Root
Browse files

Switch to returnCode for IPackageDeleteObserver

Before the IPackageDeleteObserver only knew whether the deletion
succeeded or failed, but not the reason why.

Bug: 2520191
Change-Id: I1f0d7c04f06c539660b6e17e7e133defb0f61b5b
parent 051d4430
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -767,10 +767,10 @@ public final class Pm {
        boolean finished;
        boolean result;

        public void packageDeleted(boolean succeeded) {
        public void packageDeleted(String packageName, int returnCode) {
            synchronized (this) {
                finished = true;
                result = succeeded;
                result = returnCode == PackageManager.DELETE_SUCCEEDED;
                notifyAll();
            }
        }
+1 −1
Original line number Diff line number Diff line
@@ -23,6 +23,6 @@ package android.content.pm;
 * {@hide}
 */
oneway interface IPackageDeleteObserver {
    void packageDeleted(in boolean succeeded);
    void packageDeleted(in String packageName, in int returnCode);
}
+31 −2
Original line number Diff line number Diff line
@@ -551,10 +551,39 @@ public abstract class PackageManager {
     */
    public static final int DONT_DELETE_DATA = 0x00000001;

    /**
     * Return code for when package deletion succeeds. This is passed to the
     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
     * succeeded in deleting the package.
     * 
     * @hide
     */
    public static final int DELETE_SUCCEEDED = 1;

    /**
     * Deletion failed return code: this is passed to the
     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
     * failed to delete the package for an unspecified reason.
     * 
     * @hide
     */
    public static final int DELETE_FAILED_INTERNAL_ERROR = -1;

    /**
     * Deletion failed return code: this is passed to the
     * {@link IPackageDeleteObserver} by {@link #deletePackage()} if the system
     * failed to delete the package because it is the active DevicePolicy
     * manager.
     * 
     * @hide
     */
    public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER = -2;

    /**
     * Return code that is passed to the {@link IPackageMoveObserver} by
     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)}
     * when the package has been successfully moved by the system.
     * {@link #movePackage(android.net.Uri, IPackageMoveObserver)} when the
     * package has been successfully moved by the system.
     * 
     * @hide
     */
    public static final int MOVE_SUCCEEDED = 1;
+2 −2
Original line number Diff line number Diff line
@@ -769,9 +769,9 @@ public class PackageManagerTests extends AndroidTestCase {
            return doneFlag;
        }

        public void packageDeleted(boolean succeeded) throws RemoteException {
        public void packageDeleted(String packageName, int returnCode) throws RemoteException {
            synchronized(this) {
                this.succeeded = succeeded;
                this.succeeded = returnCode == PackageManager.DELETE_SUCCEEDED;
                doneFlag = true;
                notifyAll();
            }
+9 −8
Original line number Diff line number Diff line
@@ -6204,10 +6204,10 @@ class PackageManagerService extends IPackageManager.Stub {
        mHandler.post(new Runnable() {
            public void run() {
                mHandler.removeCallbacks(this);
                final boolean succeded = deletePackageX(packageName, true, true, flags);
                final int returnCode = deletePackageX(packageName, true, true, flags);
                if (observer != null) {
                    try {
                        observer.packageDeleted(succeded);
                        observer.packageDeleted(packageName, returnCode);
                    } catch (RemoteException e) {
                        Log.i(TAG, "Observer no longer exists.");
                    } //end catch
@@ -6230,17 +6230,17 @@ class PackageManagerService extends IPackageManager.Stub {
     *  persisting settings for later use
     *  sending a broadcast if necessary
     */
    private boolean deletePackageX(String packageName, boolean sendBroadCast,
    private int deletePackageX(String packageName, boolean sendBroadCast,
                                   boolean deleteCodeAndResources, int flags) {
        PackageRemovedInfo info = new PackageRemovedInfo();
        boolean res;
        final PackageRemovedInfo info = new PackageRemovedInfo();
        final boolean res;

        IDevicePolicyManager dpm = IDevicePolicyManager.Stub.asInterface(
                ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
        try {
            if (dpm != null && dpm.packageHasActiveAdmins(packageName)) {
                Slog.w(TAG, "Not removing package " + packageName + ": has active device admin");
                return false;
                return PackageManager.DELETE_FAILED_DEVICE_POLICY_MANAGER;
            }
        } catch (RemoteException e) {
        }
@@ -6278,7 +6278,8 @@ class PackageManagerService extends IPackageManager.Stub {
                info.args.doPostDeleteLI(deleteCodeAndResources);
            }
        }
        return res;

        return res ? PackageManager.DELETE_SUCCEEDED : PackageManager.DELETE_FAILED_INTERNAL_ERROR;
    }

    static class PackageRemovedInfo {