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

Commit 815e7559 authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Move keys removal to background handler.

After 600 app uninstalls, the delay as compared to immedate call:
50%	0ms
75%	1ms
90%	1.2ms
95%	3.1ms
99%	12.04ms
99.9%	62.216ms

Bug: 220083428
Test: presubmit
Change-Id: I73d18283a49beb7724a8f86a5767c28970ba8170
parent 70a4c768
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.pm;

import static android.content.pm.PackageManager.UNINSTALL_REASON_UNKNOWN;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static android.os.incremental.IncrementalManager.isIncrementalPath;
import static android.os.storage.StorageManager.FLAG_STORAGE_CE;
import static android.os.storage.StorageManager.FLAG_STORAGE_DE;
@@ -29,6 +30,7 @@ import static com.android.server.pm.PackageManagerService.TAG;

import android.annotation.NonNull;
import android.content.pm.PackageManager;
import android.os.Trace;
import android.os.UserHandle;
import android.os.incremental.IncrementalManager;
import android.util.Log;
@@ -334,10 +336,19 @@ final class RemovePackageHelper {
                mPm.mSettings.writeKernelMappingLPr(deletedPs);
            }
        }

        if (removedAppId != -1) {
            // A user ID was deleted here. Go through all users and remove it
            // from KeyStore.
            mAppDataHelper.clearKeystoreData(UserHandle.USER_ALL, removedAppId);
            // A user ID was deleted here. Go through all users and remove it from KeyStore.
            final int appIdToRemove = removedAppId;
            mPm.mInjector.getBackgroundHandler().post(() -> {
                try {
                    Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER,
                            "clearKeystoreData:" + appIdToRemove);
                    mAppDataHelper.clearKeystoreData(UserHandle.USER_ALL, appIdToRemove);
                } finally {
                    Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
                }
            });
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
        val domainVerificationManagerInternal: DomainVerificationManagerInternal = mock()
        val handler = TestHandler(null)
        val defaultAppProvider: DefaultAppProvider = mock()
        val backgroundHandler = TestHandler(null)
    }

    companion object {
@@ -286,6 +287,7 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) {
            .thenReturn(mocks.domainVerificationManagerInternal)
        whenever(mocks.injector.handler) { mocks.handler }
        whenever(mocks.injector.defaultAppProvider) { mocks.defaultAppProvider }
        whenever(mocks.injector.backgroundHandler) { mocks.backgroundHandler }
        wheneverStatic { SystemConfig.getInstance() }.thenReturn(mocks.systemConfig)
        whenever(mocks.systemConfig.availableFeatures).thenReturn(DEFAULT_AVAILABLE_FEATURES_MAP)
        whenever(mocks.systemConfig.sharedLibraries).thenReturn(DEFAULT_SHARED_LIBRARIES_LIST)