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

Commit cfc6b97c authored by Anthony Hugh's avatar Anthony Hugh
Browse files

Fix wake lock leak

Wake lock was not being released when installation failed
due to early bail out call.  I wrapped the calls into
a try/finally to ensure it gets released.

Code was tested by tweaking the code to force a failure
and test installing/uninstalling apps.

BUG: 25814793
Change-Id: I2e81e5d76edcfb601ce734cf571705e979c51f32
parent 741ac03b
Loading
Loading
Loading
Loading
+32 −27
Original line number Diff line number Diff line
@@ -586,6 +586,7 @@ public class WearPackageInstallerService extends Service {
        }

        public void packageInstalled(String packageName, int returnCode) {
            try {
                // If installation failed, bail out and remove the ShowPermsStore entry
                if (returnCode < 0) {
                    Log.e(TAG, "Package install failed " + mApplicationPackageName
@@ -609,10 +610,11 @@ public class WearPackageInstallerService extends Service {
                    gmsInstalledIntent.setPackage(GMS_PACKAGE_NAME);
                    mContext.sendBroadcast(gmsInstalledIntent);
                }

            } finally {
                finishService(mWakeLock, mStartId);
            }
        }
    }

    private class PackageDeleteObserver extends IPackageDeleteObserver.Stub {
        private PowerManager.WakeLock mWakeLock;
@@ -624,13 +626,16 @@ public class WearPackageInstallerService extends Service {
        }

        public void packageDeleted(String packageName, int returnCode) {
            try {
                if (returnCode >= 0) {
                    Log.i(TAG, "Package " + packageName + " was uninstalled.");
                } else {
                    Log.e(TAG, "Package uninstall failed " + packageName + ", returnCode " +
                            returnCode);
                }
            } finally {
                finishService(mWakeLock, mStartId);
            }
        }
    }
}