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

Commit ce74c1e1 authored by Shahriyar Amini's avatar Shahriyar Amini Committed by Android (Google) Code Review
Browse files

Merge "Consider res package when updating security icons."

parents edfeaace 31357bb9
Loading
Loading
Loading
Loading
+12 −25
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Pair;

import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils;
@@ -68,10 +69,7 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
            String summaryUri =
                    tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
            if (!TextUtils.isEmpty(iconUri)) {
                int icon = TileUtils.getIconFromUri(context, iconUri, providerMap);
                boolean updateIcon = true;
                String packageName = null;
                // Dynamic icon has to come from the same package that the preference launches.
                if (tile.intent != null) {
                    Intent intent = tile.intent;
                    if (!TextUtils.isEmpty(intent.getPackage())) {
@@ -80,25 +78,14 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
                        packageName = intent.getComponent().getPackageName();
                    }
                }
                if (TextUtils.isEmpty(packageName)) {
                    updateIcon = false;
                } else {
                    if (tile.icon == null) {
                        // If the tile does not have an icon already, only update if the suggested
                        // icon is non-zero.
                        updateIcon = (icon != 0);
                    } else {
                        // If the existing icon has the same resource package and resource id, the
                        // icon does not need to be updated.
                        updateIcon = !(packageName.equals(tile.icon.getResPackage())
                                && (icon == tile.icon.getResId()));
                    }
                }
                if (updateIcon) {
                Pair<String, Integer> icon =
                        TileUtils.getIconFromUri(context, packageName, iconUri, providerMap);
                if (icon != null) {
                    // Icon is only returned if the icon belongs to Settings or the target app.
                    try {
                        matchingPref.setIcon(context.getPackageManager()
                                .getResourcesForApplication(packageName)
                                        .getDrawable(icon, context.getTheme()));
                                .getResourcesForApplication(icon.first /* package name */)
                                        .getDrawable(icon.second /* res id */, context.getTheme()));
                    } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
                        // Intentionally ignored. If icon resources cannot be found, do not update.
                    }
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Pair;

import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
@@ -77,9 +78,9 @@ public class SecurityFeatureProviderImplTest {
    @Implements(com.android.settingslib.drawer.TileUtils.class)
    public static class TileUtilsMock {
        @Implementation
        public static int getIconFromUri(Context context, String uriString,
        public static Pair getIconFromUri(Context context, String packageName, String uriString,
                Map<String, IContentProvider> providerMap) {
            return 161803;
            return Pair.create("package", 161803);
        }

        @Implementation