diff options
author | Nick Chalko <nchalko@google.com> | 2020-01-27 22:28:38 -0800 |
---|---|---|
committer | Nick Chalko <nchalko@google.com> | 2020-02-03 18:08:48 -0800 |
commit | 8ce952b7463cfcd3ab7a355775371de67d421359 (patch) | |
tree | 9f12c4650b8a4cd542c7cd26e2ae5e502cc09479 | |
parent | f7a041ca1920c20336c7026172a436f987bfe4c1 (diff) | |
download | TV-8ce952b7463cfcd3ab7a355775371de67d421359.tar.gz |
Simplify getting the customization package name.android-r-preview-1
PiperOrigin-RevId: 291869481
Change-Id: I22b392cfa39866bae053124ef2d89e870f83d264
-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. */ |