From 6dce47346161a80adf6bb107627223662f24d4f7 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Tue, 21 Dec 2021 19:58:46 +0000 Subject: Add logic in DreamBackend to parse dream description. The dream description will be shown in the new Settings UI. Test: locally on device, with test dream Bug: 211662811 Change-Id: I2d99268aa47a2d3b4181747b897a7f3914416cb0 --- .../com/android/settingslib/dream/DreamBackend.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java index ab7b54d98285..c5e1c8d359f3 100644 --- a/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java +++ b/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; @@ -57,6 +58,7 @@ public class DreamBackend { public boolean isActive; public ComponentName componentName; public ComponentName settingsComponentName; + public CharSequence description; @Override public String toString() { @@ -123,6 +125,7 @@ public class DreamBackend { DreamInfo dreamInfo = new DreamInfo(); dreamInfo.caption = resolveInfo.loadLabel(pm); dreamInfo.icon = resolveInfo.loadIcon(pm); + dreamInfo.description = getDescription(resolveInfo, pm); dreamInfo.componentName = getDreamComponentName(resolveInfo); dreamInfo.isActive = dreamInfo.componentName.equals(activeDream); dreamInfo.settingsComponentName = getSettingsComponentName(pm, resolveInfo); @@ -132,9 +135,25 @@ public class DreamBackend { return dreamInfos; } + private static CharSequence getDescription(ResolveInfo resolveInfo, PackageManager pm) { + String packageName = resolveInfo.resolvePackageName; + ApplicationInfo applicationInfo = null; + if (packageName == null) { + packageName = resolveInfo.serviceInfo.packageName; + applicationInfo = resolveInfo.serviceInfo.applicationInfo; + } + if (resolveInfo.serviceInfo.descriptionRes != 0) { + return pm.getText(packageName, + resolveInfo.serviceInfo.descriptionRes, + applicationInfo); + } + return null; + } + public ComponentName getDefaultDream() { - if (mDreamManager == null) + if (mDreamManager == null) { return null; + } try { return mDreamManager.getDefaultDreamComponentForUser(mContext.getUserId()); } catch (RemoteException e) { -- cgit v1.2.3-59-g8ed1b