Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6afef81 authored by Fan Zhang's avatar Fan Zhang
Browse files

Remove caching for title and and getId() method.

Bug: 77600770
Test: robotests
Change-Id: Ied4e78570ccc2f25093ca443723c3df93b5e03c8
parent f3819415
Loading
Loading
Loading
Loading
+39 −8
Original line number Diff line number Diff line
@@ -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;
    }
+0 −16
Original line number Diff line number Diff line
@@ -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;
        }
+2 −2
Original line number Diff line number Diff line
@@ -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