diff options
3 files changed, 32 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/pm/BackgroundInstallControlCallbackHelper.java b/services/core/java/com/android/server/pm/BackgroundInstallControlCallbackHelper.java index 155361837071..27c4e9dca586 100644 --- a/services/core/java/com/android/server/pm/BackgroundInstallControlCallbackHelper.java +++ b/services/core/java/com/android/server/pm/BackgroundInstallControlCallbackHelper.java @@ -35,6 +35,7 @@ public class BackgroundInstallControlCallbackHelper { @VisibleForTesting static final String FLAGGED_PACKAGE_NAME_KEY = "packageName"; @VisibleForTesting static final String FLAGGED_USER_ID_KEY = "userId"; + @VisibleForTesting static final String INSTALL_EVENT_TYPE_KEY = "installEventType"; private static final String TAG = "BackgroundInstallControlCallbackHelper"; private final Handler mHandler; @@ -74,10 +75,14 @@ public class BackgroundInstallControlCallbackHelper { * Invokes all registered callbacks Callbacks are processed through user provided-threads and * parameters are passed in via {@link BackgroundInstallControlManager} InstallEvent */ - public void notifyAllCallbacks(int userId, String packageName) { + public void notifyAllCallbacks( + int userId, + String packageName, + @BackgroundInstallControlService.InstallEventType int installEventType) { Bundle extras = new Bundle(); extras.putCharSequence(FLAGGED_PACKAGE_NAME_KEY, packageName); extras.putInt(FLAGGED_USER_ID_KEY, userId); + extras.putInt(INSTALL_EVENT_TYPE_KEY, installEventType); synchronized (mCallbacks) { mHandler.post( () -> diff --git a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java index b6daed121057..20cca969dade 100644 --- a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java +++ b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java @@ -19,6 +19,7 @@ package com.android.server.pm; import static android.Manifest.permission.GET_BACKGROUND_INSTALLED_PACKAGES; import static android.content.pm.PackageManager.PERMISSION_GRANTED; +import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.RequiresPermission; import android.app.Flags; @@ -64,6 +65,8 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -76,11 +79,23 @@ import java.util.TreeSet; * @hide */ public class BackgroundInstallControlService extends SystemService { + public static final int INSTALL_EVENT_TYPE_UNKNOWN = 0; + public static final int INSTALL_EVENT_TYPE_INSTALL = 1; + public static final int INSTALL_EVENT_TYPE_UNINSTALL = 2; + + @IntDef( + value = { + INSTALL_EVENT_TYPE_UNKNOWN, + INSTALL_EVENT_TYPE_INSTALL, + INSTALL_EVENT_TYPE_UNINSTALL, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface InstallEventType {} + private static final String TAG = "BackgroundInstallControlService"; private static final String DISK_FILE_NAME = "states"; private static final String DISK_DIR_NAME = "bic"; - private static final String ENFORCE_PERMISSION_ERROR_MSG = "User is not permitted to call service: "; @@ -313,7 +328,7 @@ public class BackgroundInstallControlService extends SystemService { initBackgroundInstalledPackages(); mBackgroundInstalledPackages.add(userId, packageName); - mCallbackHelper.notifyAllCallbacks(userId, packageName); + mCallbackHelper.notifyAllCallbacks(userId, packageName, INSTALL_EVENT_TYPE_INSTALL); writeBackgroundInstalledPackagesToDisk(); } @@ -391,6 +406,7 @@ public class BackgroundInstallControlService extends SystemService { initBackgroundInstalledPackages(); mBackgroundInstalledPackages.remove(userId, packageName); writeBackgroundInstalledPackagesToDisk(); + mCallbackHelper.notifyAllCallbacks(userId, packageName, INSTALL_EVENT_TYPE_UNINSTALL); } void handleUsageEvent(UsageEvents.Event event, int userId) { diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundInstallControlCallbackHelperTest.java b/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundInstallControlCallbackHelperTest.java index 574f3699edb8..ae404cff7171 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundInstallControlCallbackHelperTest.java +++ b/services/tests/mockingservicestests/src/com/android/server/pm/BackgroundInstallControlCallbackHelperTest.java @@ -18,6 +18,7 @@ package com.android.server.pm; import static com.android.server.pm.BackgroundInstallControlCallbackHelper.FLAGGED_PACKAGE_NAME_KEY; import static com.android.server.pm.BackgroundInstallControlCallbackHelper.FLAGGED_USER_ID_KEY; +import static com.android.server.pm.BackgroundInstallControlCallbackHelper.INSTALL_EVENT_TYPE_KEY; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.after; @@ -84,12 +85,18 @@ public class BackgroundInstallControlCallbackHelperTest { int testUserId = 1; mCallbackHelper.registerBackgroundInstallCallback(mCallback); - mCallbackHelper.notifyAllCallbacks(testUserId, testPackageName); + mCallbackHelper.notifyAllCallbacks( + testUserId, + testPackageName, + BackgroundInstallControlService.INSTALL_EVENT_TYPE_INSTALL); ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class); verify(mCallback, after(1000).times(1)).sendResult(bundleCaptor.capture()); Bundle receivedBundle = bundleCaptor.getValue(); assertEquals(testPackageName, receivedBundle.getString(FLAGGED_PACKAGE_NAME_KEY)); assertEquals(testUserId, receivedBundle.getInt(FLAGGED_USER_ID_KEY)); + assertEquals( + BackgroundInstallControlService.INSTALL_EVENT_TYPE_INSTALL, + receivedBundle.getInt(INSTALL_EVENT_TYPE_KEY)); } } |