diff options
| author | 2023-01-27 04:55:45 +0000 | |
|---|---|---|
| committer | 2023-01-30 22:11:46 +0000 | |
| commit | cf8a36fba7be1669742f41fce005e550b294ccdd (patch) | |
| tree | 6ed40db18c8888e2c9d83300251d3a4e10ed52a5 | |
| parent | df22180cb94e050810d59af374c3d67812e3a19c (diff) | |
[BIC] Enable the creation of mock apps
We can populate mock background installed apps by setting the
value of "debug.transparency.bg-install-apps".
The string value is the list of names of the mock apps.
Bug: 266888785
Test: Run `adb shell setprop
debug.transparency.bg-install-apps
<some existing apps>`
to set the list of mock apps.
Run `adb shell cmd transparency get mba_info`
to check existence of the apps.
Change-Id: I07a6106937a8217c16c31cbacf967d3c2102a2b1
| -rw-r--r-- | services/core/java/com/android/server/pm/BackgroundInstallControlService.java | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java index 69436da981b1..8d40adfb29f0 100644 --- a/services/core/java/com/android/server/pm/BackgroundInstallControlService.java +++ b/services/core/java/com/android/server/pm/BackgroundInstallControlService.java @@ -27,12 +27,15 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.content.pm.ParceledListSlice; +import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemClock; +import android.os.SystemProperties; import android.os.UserHandle; +import android.text.TextUtils; import android.util.ArraySet; import android.util.AtomicFile; import android.util.Slog; @@ -51,6 +54,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.ListIterator; import java.util.Set; @@ -122,7 +126,18 @@ public class BackgroundInstallControlService extends SystemService { @Override public ParceledListSlice<PackageInfo> getBackgroundInstalledPackages( @PackageManager.PackageInfoFlagsBits long flags, int userId) { - return mService.getBackgroundInstalledPackages(flags, userId); + if (!Build.IS_DEBUGGABLE) { + return mService.getBackgroundInstalledPackages(flags, userId); + } + // The debug.transparency.bg-install-apps (only works for debuggable builds) + // is used to set mock list of background installed apps for testing. + // The list of apps' names is delimited by ",". + String propertyString = SystemProperties.get("debug.transparency.bg-install-apps"); + if (TextUtils.isEmpty(propertyString)) { + return mService.getBackgroundInstalledPackages(flags, userId); + } else { + return mService.getMockBackgroundInstalledPackages(propertyString); + } } } @@ -145,6 +160,27 @@ public class BackgroundInstallControlService extends SystemService { return new ParceledListSlice<>(packages); } + /** + * Mock a list of background installed packages based on the property string. + */ + @NonNull + ParceledListSlice<PackageInfo> getMockBackgroundInstalledPackages( + @NonNull String propertyString) { + String[] mockPackageNames = propertyString.split(","); + List<PackageInfo> mockPackages = new ArrayList<>(); + for (String name : mockPackageNames) { + try { + PackageInfo packageInfo = mPackageManager.getPackageInfo(name, + PackageManager.PackageInfoFlags.of(PackageManager.MATCH_ALL)); + mockPackages.add(packageInfo); + } catch (PackageManager.NameNotFoundException e) { + Slog.w(TAG, "Package's PackageInfo not found " + name); + continue; + } + } + return new ParceledListSlice<>(mockPackages); + } + private static class EventHandler extends Handler { private final BackgroundInstallControlService mService; |