Move allowed list definition in the battery usage to feature provider am: b62cdecc67 am: bb535f4bce

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15785737

Change-Id: I4a19dcc41b14af235c3e1d94675d14fc8f05e3a0
This commit is contained in:
ykhung
2021-09-10 05:14:37 +00:00
committed by Automerger Merge Worker
7 changed files with 26 additions and 14 deletions

View File

@@ -1536,11 +1536,6 @@
<item>@string/enhanced_4g_lte_mode_summary_4g_calling</item> <item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
</string-array> </string-array>
<!-- An allowlist which packages won't show summary in battery usage screen.
[CHAR LIMIT=NONE] -->
<string-array name="allowlist_hide_summary_in_battery_usage" translatable="false">
</string-array>
<!-- Array of titles palette list for accessibility. --> <!-- Array of titles palette list for accessibility. -->
<string-array name="setting_palette_data" translatable="false" > <string-array name="setting_palette_data" translatable="false" >
<item>@string/color_red</item> <item>@string/color_red</item>

View File

@@ -47,6 +47,7 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment; import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -440,8 +441,10 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
} }
private boolean shouldShowSummary(BatteryEntry entry) { private boolean shouldShowSummary(BatteryEntry entry) {
final CharSequence[] allowlistPackages = mContext.getResources() final CharSequence[] allowlistPackages =
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage); FeatureFactory.getFactory(mContext)
.getPowerUsageFeatureProvider(mContext)
.getHideApplicationSummary(mContext);
final String target = entry.getDefaultPackageName(); final String target = entry.getDefaultPackageName();
for (CharSequence packageName : allowlistPackages) { for (CharSequence packageName : allowlistPackages) {

View File

@@ -121,14 +121,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mFragment = fragment; mFragment = fragment;
mPreferenceKey = preferenceKey; mPreferenceKey = preferenceKey;
mIs24HourFormat = DateFormat.is24HourFormat(context); mIs24HourFormat = DateFormat.is24HourFormat(context);
mNotAllowShowSummaryPackages = context.getResources()
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
mMetricsFeatureProvider = mMetricsFeatureProvider =
FeatureFactory.getFactory(mContext).getMetricsFeatureProvider(); FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
mNotAllowShowEntryPackages = mNotAllowShowEntryPackages =
FeatureFactory.getFactory(mContext) FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context) .getPowerUsageFeatureProvider(context)
.getHideApplicationEntries(mContext); .getHideApplicationEntries(context);
mNotAllowShowSummaryPackages =
FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.getHideApplicationSummary(context);
if (lifecycle != null) { if (lifecycle != null) {
lifecycle.addObserver(this); lifecycle.addObserver(this);
} }

View File

@@ -157,4 +157,9 @@ public interface PowerUsageFeatureProvider {
* Returns package names for hidding application in the usage screen. * Returns package names for hidding application in the usage screen.
*/ */
CharSequence[] getHideApplicationEntries(Context context); CharSequence[] getHideApplicationEntries(Context context);
/**
* Returns package names for hidding summary in the usage screen.
*/
CharSequence[] getHideApplicationSummary(Context context);
} }

View File

@@ -171,4 +171,9 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
public CharSequence[] getHideApplicationEntries(Context context) { public CharSequence[] getHideApplicationEntries(Context context) {
return new CharSequence[0]; return new CharSequence[0];
} }
@Override
public CharSequence[] getHideApplicationSummary(Context context) {
return new CharSequence[0];
}
} }

View File

@@ -67,11 +67,13 @@ public class BatteryAppListPreferenceControllerTest {
private Context mContext; private Context mContext;
private PowerGaugePreference mPreference; private PowerGaugePreference mPreference;
private BatteryAppListPreferenceController mPreferenceController; private BatteryAppListPreferenceController mPreferenceController;
private FakeFeatureFactory mFeatureFactory;
@Before @Before
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
final Resources resources = spy(mContext.getResources()); final Resources resources = spy(mContext.getResources());
when(mContext.getResources()).thenReturn(resources); when(mContext.getResources()).thenReturn(resources);
@@ -79,9 +81,8 @@ public class BatteryAppListPreferenceControllerTest {
when(mContext.getApplicationContext()).thenReturn(mContext); when(mContext.getApplicationContext()).thenReturn(mContext);
when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {}); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
when(resources.getTextArray(R.array.allowlist_hide_summary_in_battery_usage)) when(mFeatureFactory.powerUsageFeatureProvider.getHideApplicationSummary(mContext))
.thenReturn(new String[] {"com.android.googlequicksearchbox"}); .thenReturn(new String[] {"com.android.googlequicksearchbox"});
FakeFeatureFactory.setupForTest();
mPreference = new PowerGaugePreference(mContext); mPreference = new PowerGaugePreference(mContext);

View File

@@ -103,7 +103,8 @@ public final class BatteryChartPreferenceControllerTest {
resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US"))); resources.getConfiguration().setLocales(new LocaleList(new Locale("en_US")));
doReturn(resources).when(mContext).getResources(); doReturn(resources).when(mContext).getResources();
doReturn(new String[] {"com.android.googlequicksearchbox"}) doReturn(new String[] {"com.android.googlequicksearchbox"})
.when(resources).getTextArray(R.array.allowlist_hide_summary_in_battery_usage); .when(mFeatureFactory.powerUsageFeatureProvider)
.getHideApplicationSummary(mContext);
mBatteryChartPreferenceController = createController(); mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext; mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup; mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;