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

Commit 9b8684fd authored by Fan Zhang's avatar Fan Zhang Committed by android-build-merger
Browse files

Merge "Don't use cached app icon in app info page." into pi-dev

am: 7312f555

Change-Id: I3f196276bca134df35d0c723ae637354f5214744
parents 9c6ccfbb 7312f555
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.support.annotation.IntDef;
import android.support.annotation.VisibleForTesting;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.IconDrawableFactory;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -146,9 +147,7 @@ public class EntityHeaderController {
     * accessibility purposes.
     */
    public EntityHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
        if (appEntry.icon != null) {
            mIcon = appEntry.icon.getConstantState().newDrawable(mAppContext.getResources());
        }
        mIcon = IconDrawableFactory.newInstance(mAppContext).getBadgedIcon(appEntry.info);
        return this;
    }

+35 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.testutils;

import android.content.pm.ApplicationInfo;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.IconDrawableFactory;

import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

@Implements(IconDrawableFactory.class)
public class ShadowIconDrawableFactory {

    @Implementation
    public Drawable getBadgedIcon(ApplicationInfo appInfo) {
        return new ColorDrawable(Color.BLUE);
    }
}
+22 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.ColorDrawable;
@@ -39,12 +40,14 @@ import android.support.v7.preference.Preference;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.ShadowIconDrawableFactory;
import com.android.settingslib.applications.ApplicationsState;

import org.junit.Before;
import org.junit.Test;
@@ -53,6 +56,7 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@RunWith(SettingsRobolectricTestRunner.class)
public class EntityHeaderControllerTest {
@@ -68,12 +72,10 @@ public class EntityHeaderControllerTest {
    private LayoutInflater mLayoutInflater;
    private PackageInfo mInfo;
    private EntityHeaderController mController;
    private FakeFeatureFactory mFeatureFactory;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mFeatureFactory = FakeFeatureFactory.setupForTest();
        mShadowContext = RuntimeEnvironment.application;
        when(mActivity.getApplicationContext()).thenReturn(mShadowContext);
        when(mContext.getApplicationContext()).thenReturn(mContext);
@@ -254,6 +256,23 @@ public class EntityHeaderControllerTest {
                .isEqualTo(description);
    }

    @Test
    @Config(shadows = ShadowIconDrawableFactory.class)
    public void setIcon_usingAppEntry_shouldLoadIconFromDrawableFactory() {
        final View view = mLayoutInflater
                .inflate(R.layout.settings_entity_header, null /* root */);
        final ApplicationsState.AppEntry entry = mock(ApplicationsState.AppEntry.class);
        entry.info = new ApplicationInfo();
        mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
        mController.setIcon(entry).done(mActivity);
        final ImageView iconView = view.findViewById(R.id.entity_header_icon);

        // Icon is set
        assertThat(iconView.getDrawable()).isNotNull();
        // ... and entry.icon is still empty. This means the icon didn't come from cache.
        assertThat(entry.icon).isNull();
    }

    @Test
    public void bindButton_hasAppNotifIntent_shouldShowButton() {
        final View appLinks = mLayoutInflater