diff options
| author | 2018-08-17 11:34:27 -0700 | |
|---|---|---|
| committer | 2018-08-20 15:55:21 -0700 | |
| commit | a6afef81b670d8b0adf595e86ec6c1fa997c62d1 (patch) | |
| tree | f830e806b91f16f37f07d7e36f651e7a37035bcb | |
| parent | f38194156f9b4542ed7a0c580162719f6982a2f4 (diff) | |
Remove caching for title and and getId() method.
Bug: 77600770
Test: robotests
Change-Id: Ied4e78570ccc2f25093ca443723c3df93b5e03c8
3 files changed, 41 insertions, 26 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java b/packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java index 84c8b21c925c..dd79618b47b0 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/Tile.java @@ -21,6 +21,7 @@ import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_ICON_URI; import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_KEYHINT; +import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_TITLE; import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL; import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY; @@ -29,16 +30,19 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.res.Resources; import android.graphics.drawable.Icon; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.os.UserHandle; import android.text.TextUtils; +import android.util.Log; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Objects; /** * Description of a single dashboard tile that the user can select. @@ -47,12 +51,6 @@ public class Tile implements Parcelable { private static final String TAG = "Tile"; - /** - * Title of the tile that is shown to the user. - * - * @attr ref android.R.styleable#PreferenceHeader_title - */ - public CharSequence title; /** * Optional summary describing what this tile controls. @@ -90,7 +88,6 @@ public class Tile implements Parcelable { mActivityPackage = in.readString(); mActivityName = in.readString(); mIntent = new Intent().setClassName(mActivityPackage, mActivityName); - title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); final int N = in.readInt(); for (int i = 0; i < N; i++) { @@ -109,7 +106,6 @@ public class Tile implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeString(mActivityPackage); dest.writeString(mActivityName); - TextUtils.writeToParcel(title, dest, flags); TextUtils.writeToParcel(summary, dest, flags); final int N = userHandle.size(); dest.writeInt(N); @@ -120,6 +116,14 @@ public class Tile implements Parcelable { dest.writeBundle(mMetaData); } + public int getId() { + return Objects.hash(mActivityPackage, mActivityName); + } + + public String getDescription() { + return mActivityPackage + "/" + mActivityName; + } + public String getPackageName() { return mActivityPackage; } @@ -158,6 +162,33 @@ public class Tile implements Parcelable { && mMetaData.get(META_DATA_KEY_ORDER) instanceof Integer; } + /** + * Title of the tile that is shown to the user. + */ + public CharSequence getTitle(Context context) { + CharSequence title = null; + final PackageManager packageManager = context.getPackageManager(); + if (mMetaData.containsKey(META_DATA_PREFERENCE_TITLE)) { + if (mMetaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) { + try { + final Resources res = + packageManager.getResourcesForApplication(mActivityPackage); + title = res.getString(mMetaData.getInt(META_DATA_PREFERENCE_TITLE)); + } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { + Log.d(TAG, "Couldn't find info", e); + } + } else { + title = mMetaData.getString(META_DATA_PREFERENCE_TITLE); + } + } + // Set the preference title to the activity's label if no + // meta-data is found + if (title == null) { + title = getActivityInfo(context).loadLabel(packageManager); + } + return title; + } + public Bundle getMetaData() { return mMetaData; } diff --git a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java index e2c8ecdb2a30..f19bb3150e5f 100644 --- a/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/drawer/TileUtils.java @@ -313,7 +313,6 @@ public class TileUtils { if (tile == null) { tile = new Tile(activityInfo, categoryKey); updateTileData(context, tile, activityInfo, activityInfo.applicationInfo, pm); - if (DEBUG) Log.d(LOG_TAG, "Adding tile " + tile.title); addedCache.put(key, tile); } @@ -329,7 +328,6 @@ public class TileUtils { private static boolean updateTileData(Context context, Tile tile, ActivityInfo activityInfo, ApplicationInfo applicationInfo, PackageManager pm) { if (applicationInfo.isSystemApp()) { - CharSequence title = null; String summary = null; // Get the activity's meta-data @@ -338,13 +336,6 @@ public class TileUtils { Bundle metaData = activityInfo.metaData; if (res != null && metaData != null) { - if (metaData.containsKey(META_DATA_PREFERENCE_TITLE)) { - if (metaData.get(META_DATA_PREFERENCE_TITLE) instanceof Integer) { - title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE)); - } else { - title = metaData.getString(META_DATA_PREFERENCE_TITLE); - } - } if (metaData.containsKey(META_DATA_PREFERENCE_SUMMARY)) { if (metaData.get(META_DATA_PREFERENCE_SUMMARY) instanceof Integer) { summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY)); @@ -357,14 +348,7 @@ public class TileUtils { if (DEBUG) Log.d(LOG_TAG, "Couldn't find info", e); } - // Set the preference title to the activity's label if no - // meta-data is found - if (TextUtils.isEmpty(title)) { - title = activityInfo.loadLabel(pm).toString(); - } - // Set title and summary for the preference - tile.title = title; tile.summary = summary; return true; } diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java index 9f097d85e84f..2e1f66a41edf 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/drawer/TileUtilsTest.java @@ -214,7 +214,7 @@ public class TileUtilsTest { null /* defaultCategory */, outTiles, false /* usePriority */); assertThat(outTiles.size()).isEqualTo(1); - assertThat(outTiles.get(0).title).isEqualTo("my title"); + assertThat(outTiles.get(0).getTitle(mContext)).isEqualTo("my title"); } @Test @@ -236,7 +236,7 @@ public class TileUtilsTest { TileUtils.getTilesForIntent(mContext, UserHandle.CURRENT, intent, addedCache, null /* defaultCategory */, outTiles, false /* usePriority */); assertThat(outTiles.size()).isEqualTo(1); - assertThat(outTiles.get(0).title).isEqualTo("my localized title"); + assertThat(outTiles.get(0).getTitle(mContext)).isEqualTo("my localized title"); // Icon should be tintable because the tile is not from settings package, and // "forceTintExternalIcon" is set |