Only show restricted apps that belong to the user.

Filter out the restricted apps that not belong to the correct user, in
this way secondary user cannot see what apps been restricted by primary
user.

Bug: 74076658
Test: RunSettingsRoboTests
Change-Id: I8471f07be747c177f8611cdc1973a8420dc41296
This commit is contained in:
Lei Yu
2018-03-20 16:11:25 -07:00
parent 048b71a67c
commit 37d29ee6a6
4 changed files with 54 additions and 6 deletions

View File

@@ -19,6 +19,8 @@ package com.android.settings.fuelgauge;
import android.app.AppOpsManager;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
@@ -38,14 +40,17 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
@VisibleForTesting
static final String KEY_RESTRICT_APP = "restricted_app";
@VisibleForTesting
List<AppInfo> mAppInfos;
private AppOpsManager mAppOpsManager;
private List<AppInfo> mAppInfos;
private SettingsActivity mSettingsActivity;
private InstrumentedPreferenceFragment mPreferenceFragment;
private UserManager mUserManager;
public RestrictAppPreferenceController(Context context) {
super(context, KEY_RESTRICT_APP);
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
mUserManager = context.getSystemService(UserManager.class);
}
public RestrictAppPreferenceController(SettingsActivity settingsActivity,
@@ -64,7 +69,7 @@ public class RestrictAppPreferenceController extends BasePreferenceController {
public void updateState(Preference preference) {
super.updateState(preference);
mAppInfos = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager);
mAppInfos = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager, mUserManager);
final int num = mAppInfos.size();
// Enable the preference if some apps already been restricted, otherwise disable it