diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-04 19:44:31 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-02-04 19:44:31 +0000 |
commit | 045f9155699a505237b6883a13732ac126ea41d9 (patch) | |
tree | 3fed32cd568be35680e8bf0150689eaed7255840 | |
parent | 83116e56809b54500f69d222b727a35721c6a04d (diff) | |
parent | a6b53117805483bf6a46eb24c75454bc9f74785f (diff) | |
download | TV-045f9155699a505237b6883a13732ac126ea41d9.tar.gz |
Simplify getting the customization package name. am: 8ce952b746 am: 41a10142c6 am: a6b5311780
Change-Id: I7d5fce2e248bf1b11ffb684d9330f7f1928f1e55
-rw-r--r-- | common/src/com/android/tv/common/customization/CustomizationManager.java | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/common/src/com/android/tv/common/customization/CustomizationManager.java b/common/src/com/android/tv/common/customization/CustomizationManager.java index 6ec60fe4..94f1a4ed 100644 --- a/common/src/com/android/tv/common/customization/CustomizationManager.java +++ b/common/src/com/android/tv/common/customization/CustomizationManager.java @@ -32,6 +32,8 @@ import android.util.Log; import com.android.tv.common.CommonConstants; +import com.google.common.collect.Iterables; + import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; @@ -160,33 +162,25 @@ public class CustomizationManager { private static String getCustomizationPackageName(Context context) { if (sCustomizationPackage == null) { - List<PackageInfo> packageInfos = context.getPackageManager() .getPackagesHoldingPermissions(CUSTOMIZE_PERMISSIONS, 0); sCustomizationPackage = getCustomizationPackageName(packageInfos); } - return sCustomizationPackage; } @VisibleForTesting static String getCustomizationPackageName(List<PackageInfo> packageInfos) { - String packageName = ""; - if (!packageInfos.isEmpty()) { - /** Iterate through all packages returning the first vendor customizer */ - for (PackageInfo packageInfo : packageInfos) { - if (packageInfo.packageName.startsWith("com.android") == false) { - packageName = packageInfo.packageName; - break; - } - } - /** If no vendor package found, return first in the list */ - if (TextUtils.isEmpty(packageName)) { - packageName = packageInfos.get(0).packageName; - } - } - return packageName; + Iterable<String> packageNames = + Iterables.transform(packageInfos, input -> input.packageName); + + // Find the first vendor customizer + return Iterables.find( + packageNames, + input -> !input.startsWith("com.android"), + // else use the first one or blank + Iterables.getFirst(packageNames, "")); } /** Initialize TV customization options. Run this API only on the main thread. */ |