Remove security settings v1 code

Change-Id: I958ed1588009b91f64cd8ecb98208e72a891903e
Fixes: 32953042
Test: robotests
This commit is contained in:
Fan Zhang
2018-01-29 12:06:58 -08:00
parent 499efd06ab
commit 73dc479ab5
41 changed files with 198 additions and 2291 deletions

View File

@@ -16,8 +16,7 @@
package com.android.settings.security;
import static com.android.settings.security
.SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
import static com.android.settings.security.SecuritySettings.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
@@ -37,7 +36,7 @@ public class ChangeProfileScreenLockPreferenceController extends
private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
public ChangeProfileScreenLockPreferenceController(Context context,
SecuritySettingsV2 host) {
SecuritySettings host) {
super(context, host);
}

View File

@@ -16,7 +16,7 @@
package com.android.settings.security;
import static com.android.settings.security.SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST;
import static com.android.settings.security.SecuritySettings.SET_OR_CHANGE_LOCK_METHOD_REQUEST;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
@@ -45,7 +45,7 @@ public class ChangeScreenLockPreferenceController extends AbstractPreferenceCont
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
protected final DevicePolicyManager mDPM;
protected final SecuritySettingsV2 mHost;
protected final SecuritySettings mHost;
protected final UserManager mUm;
protected final LockPatternUtils mLockPatternUtils;
@@ -54,7 +54,7 @@ public class ChangeScreenLockPreferenceController extends AbstractPreferenceCont
protected RestrictedPreference mPreference;
public ChangeScreenLockPreferenceController(Context context, SecuritySettingsV2 host) {
public ChangeScreenLockPreferenceController(Context context, SecuritySettings host) {
super(context);
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);

View File

@@ -16,11 +16,10 @@
package com.android.settings.security;
import static com.android.settings.security
.SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
import static com.android.settings.security.SecuritySettingsV2.UNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
import static com.android.settings.security.SecuritySettingsV2.UNIFY_LOCK_CONFIRM_PROFILE_REQUEST;
import static com.android.settings.security.SecuritySettingsV2.UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
import static com.android.settings.security.SecuritySettings.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
import static com.android.settings.security.SecuritySettings.UNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
import static com.android.settings.security.SecuritySettings.UNIFY_LOCK_CONFIRM_PROFILE_REQUEST;
import static com.android.settings.security.SecuritySettings.UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
@@ -53,7 +52,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
private final UserManager mUm;
private final LockPatternUtils mLockPatternUtils;
private final int mProfileChallengeUserId;
private final SecuritySettingsV2 mHost;
private final SecuritySettings mHost;
private RestrictedSwitchPreference mUnifyProfile;
@@ -67,7 +66,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
mUnifyProfile = (RestrictedSwitchPreference) screen.findPreference(KEY_UNIFICATION);
}
public LockUnificationPreferenceController(Context context, SecuritySettingsV2 host) {
public LockUnificationPreferenceController(Context context, SecuritySettings host) {
super(context);
mHost = host;
mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
@@ -212,7 +211,7 @@ public class LockUnificationPreferenceController extends AbstractPreferenceContr
mCurrentProfilePassword);
mHost.startFragment(mHost, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
R.string.lock_settings_picker_title,
SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
SecuritySettings.SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
}
}

View File

@@ -17,26 +17,14 @@
package com.android.settings.security;
import android.content.Context;
import android.support.v7.preference.PreferenceScreen;
import android.util.FeatureFlagUtils;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.security.trustagent.TrustAgentManager;
import com.android.settingslib.drawer.DashboardCategory;
/** FeatureProvider for security. */
public interface SecurityFeatureProvider {
default boolean isSecuritySettingsV2Enabled(Context context) {
return FeatureFlagUtils.isEnabled(context, FeatureFlags.SECURITY_SETTINGS_V2);
}
/** Update preferences with data from associated tiles. */
void updatePreferences(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory);
/** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
TrustAgentManager getTrustAgentManager();

View File

@@ -17,28 +17,9 @@
package com.android.settings.security;
import android.content.Context;
import android.content.IContentProvider;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.annotation.VisibleForTesting;
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.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.security.trustagent.TrustAgentManager;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.drawer.TileUtils;
import com.android.settingslib.utils.ThreadUtils;
import java.util.Map;
import java.util.TreeMap;
/** Implementation for {@code SecurityFeatureProvider}. */
public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
@@ -46,150 +27,6 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
private TrustAgentManager mTrustAgentManager;
private LockPatternUtils mLockPatternUtils;
@VisibleForTesting
static final Drawable DEFAULT_ICON = null;
@VisibleForTesting
static Map<String, Pair<String, Integer>> sIconCache = new TreeMap<>();
@VisibleForTesting
static Map<String, String> sSummaryCache = new TreeMap<>();
/** Update preferences with data from associated tiles. */
public void updatePreferences(final Context context, final PreferenceScreen preferenceScreen,
final DashboardCategory dashboardCategory) {
if (preferenceScreen == null) {
return;
}
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
if (tilesCount == 0) {
return;
}
initPreferences(context, preferenceScreen, dashboardCategory);
// Fetching the summary and icon from the provider introduces latency, so do this on a
// separate thread.
ThreadUtils.postOnBackgroundThread(() ->
updatePreferencesToRunOnWorkerThread(context, preferenceScreen, dashboardCategory));
}
@VisibleForTesting
static void initPreferences(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory) {
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);
// If the tile does not have a key or appropriate meta data, skip it.
if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
continue;
}
Preference matchingPref = preferenceScreen.findPreference(tile.key);
// If the tile does not have a matching preference, skip it.
if (matchingPref == null) {
continue;
}
// Either remove an icon by replacing them with nothing, or use the cached one since
// there is a delay in fetching the injected icon, and we don't want an inappropriate
// icon to be displayed while waiting for the injected icon.
final String iconUri =
tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_ICON_URI, null);
Drawable drawable = DEFAULT_ICON;
if ((iconUri != null) && sIconCache.containsKey(iconUri)) {
Pair<String, Integer> icon = sIconCache.get(iconUri);
try {
drawable = context.getPackageManager()
.getResourcesForApplication(icon.first /* package name */)
.getDrawable(icon.second /* res id */,
context.getTheme());
} catch (PackageManager.NameNotFoundException e) {
// Ignore and just load the default icon.
}
}
matchingPref.setIcon(drawable);
// Either reserve room for the summary or load the cached one. This prevents the title
// from shifting when the final summary is injected.
final String summaryUri =
tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
String summary = context.getString(R.string.summary_placeholder);
if ((summaryUri != null) && sSummaryCache.containsKey(summaryUri)) {
summary = sSummaryCache.get(summaryUri);
}
matchingPref.setSummary(summary);
}
}
@VisibleForTesting
void updatePreferencesToRunOnWorkerThread(Context context, PreferenceScreen preferenceScreen,
DashboardCategory dashboardCategory) {
int tilesCount = (dashboardCategory != null) ? dashboardCategory.getTilesCount() : 0;
Map<String, IContentProvider> providerMap = new ArrayMap<>();
for (int i = 0; i < tilesCount; i++) {
Tile tile = dashboardCategory.getTile(i);
// If the tile does not have a key or appropriate meta data, skip it.
if (TextUtils.isEmpty(tile.key) || (tile.metaData == null)) {
continue;
}
Preference matchingPref = preferenceScreen.findPreference(tile.key);
// If the tile does not have a matching preference, skip it.
if (matchingPref == null) {
continue;
}
// Check if the tile has content providers for dynamically updatable content.
final String iconUri =
tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_ICON_URI, null);
final String summaryUri =
tile.metaData.getString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI, null);
if (!TextUtils.isEmpty(iconUri)) {
String packageName = null;
if (tile.intent != null) {
Intent intent = tile.intent;
if (!TextUtils.isEmpty(intent.getPackage())) {
packageName = intent.getPackage();
} else if (intent.getComponent() != null) {
packageName = intent.getComponent().getPackageName();
}
}
Pair<String, Integer> icon =
TileUtils.getIconFromUri(context, packageName, iconUri, providerMap);
if (icon != null) {
sIconCache.put(iconUri, icon);
// Icon is only returned if the icon belongs to Settings or the target app.
// setIcon must be called on the UI thread.
ThreadUtils.postOnMainThread(() -> {
try {
matchingPref.setIcon(context.getPackageManager()
.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.
}
});
}
}
if (!TextUtils.isEmpty(summaryUri)) {
String summary = TileUtils.getTextFromUri(context, summaryUri, providerMap,
TileUtils.META_DATA_PREFERENCE_SUMMARY);
sSummaryCache.put(summaryUri, summary);
// setSummary must be called on UI thread.
ThreadUtils.postOnMainThread(() -> {
// Only update the summary if it has actually changed.
if (summary == null) {
if (matchingPref.getSummary() != null) {
matchingPref.setSummary(summary);
}
} else if (!summary.equals(matchingPref.getSummary())) {
matchingPref.setSummary(summary);
}
});
}
}
}
@Override
public TrustAgentManager getTrustAgentManager() {
if (mTrustAgentManager == null) {

File diff suppressed because it is too large Load Diff

View File

@@ -1,188 +0,0 @@
package com.android.settings.security;
import static com.android.settings.security.EncryptionStatusPreferenceController
.PREF_KEY_ENCRYPTION_SECURITY_PAGE;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.hardware.fingerprint.FingerprintManager;
import android.provider.SearchIndexableResource;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
import com.android.settings.fingerprint.FingerprintProfileStatusPreferenceController;
import com.android.settings.fingerprint.FingerprintStatusPreferenceController;
import com.android.settings.location.LocationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.security.screenlock.LockScreenPreferenceController;
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
public class SecuritySettingsV2 extends DashboardFragment {
private static final String TAG = "SecuritySettingsV2";
public static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
public static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
public static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127;
public static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
public static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
public static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.SECURITY;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.security_settings_v2;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public int getHelpResource() {
return R.string.help_url_security;
}
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle(), this /* host*/);
}
/**
* see confirmPatternThenDisableAndClear
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (getPreferenceController(TrustAgentListPreferenceController.class)
.handleActivityResult(requestCode, resultCode)) {
return;
}
if (getPreferenceController(LockUnificationPreferenceController.class)
.handleActivityResult(requestCode, resultCode, data)) {
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
void launchConfirmDeviceLockForUnification() {
getPreferenceController(LockUnificationPreferenceController.class)
.launchConfirmDeviceLockForUnification();
}
void unifyUncompliantLocks() {
getPreferenceController(LockUnificationPreferenceController.class).unifyUncompliantLocks();
}
void updateUnificationPreference() {
getPreferenceController(LockUnificationPreferenceController.class).updateState(null);
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle, SecuritySettingsV2 host) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
controllers.add(new LocationPreferenceController(context, lifecycle));
controllers.add(new ManageDeviceAdminPreferenceController(context));
controllers.add(new EnterprisePrivacyPreferenceController(context));
controllers.add(new ManageTrustAgentsPreferenceController(context));
controllers.add(new ScreenPinningPreferenceController(context));
controllers.add(new SimLockPreferenceController(context));
controllers.add(new ShowPasswordPreferenceController(context));
controllers.add(new FingerprintStatusPreferenceController(context));
controllers.add(new EncryptionStatusPreferenceController(context,
PREF_KEY_ENCRYPTION_SECURITY_PAGE));
controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
controllers.add(new LockScreenPreferenceController(context, lifecycle));
controllers.add(new ChangeScreenLockPreferenceController(context, host));
final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>();
profileSecurityControllers.add(new ChangeProfileScreenLockPreferenceController(
context, host));
profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
profileSecurityControllers.add(new VisiblePatternProfilePreferenceController(
context, lifecycle));
profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context));
controllers.add(new PreferenceCategoryController(context, "security_category_profile",
profileSecurityControllers));
controllers.addAll(profileSecurityControllers);
return controllers;
}
/**
* For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(
Context context, boolean enabled) {
final List<SearchIndexableResource> index = new ArrayList<>();
// Append the rest of the settings
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.security_settings_v2;
index.add(sir);
return index;
}
@Override
public List<AbstractPreferenceController> getPreferenceControllers(Context
context) {
return buildPreferenceControllers(context, null /* lifecycle */,
null /* host*/);
}
};
static class SummaryProvider implements SummaryLoader.SummaryProvider {
private final Context mContext;
private final SummaryLoader mSummaryLoader;
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
mContext = context;
mSummaryLoader = summaryLoader;
}
@Override
public void setListening(boolean listening) {
if (listening) {
final FingerprintManager fpm =
Utils.getFingerprintManagerOrNull(mContext);
if (fpm != null && fpm.isHardwareDetected()) {
mSummaryLoader.setSummary(this,
mContext.getString(R.string.security_dashboard_summary));
} else {
mSummaryLoader.setSummary(this, mContext.getString(
R.string.security_dashboard_summary_no_fingerprint));
}
}
}
}
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
new SummaryLoader.SummaryProviderFactory() {
@Override
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
SummaryLoader summaryLoader) {
return new SummaryProvider(activity, summaryLoader);
}
};
}

View File

@@ -40,7 +40,7 @@ public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
return dialog;
}
public void show(SecuritySettingsV2 host) {
public void show(SecuritySettings host) {
final FragmentManager manager = host.getChildFragmentManager();
if (manager.findFragmentByTag(TAG_UNIFICATION_DIALOG) == null) {
// Prevent opening multiple dialogs if tapped on button quickly
@@ -50,7 +50,7 @@ public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final SecuritySettingsV2 parentFragment = ((SecuritySettingsV2) getParentFragment());
final SecuritySettings parentFragment = ((SecuritySettings) getParentFragment());
final boolean compliant = getArguments().getBoolean(EXTRA_COMPLIANT);
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.lock_settings_profile_unification_dialog_title)
@@ -75,7 +75,7 @@ public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
((SecuritySettingsV2) getParentFragment()).updateUnificationPreference();
((SecuritySettings) getParentFragment()).updateUnificationPreference();
}
@Override

View File

@@ -16,7 +16,7 @@
package com.android.settings.security.trustagent;
import static com.android.settings.security.SecuritySettingsV2.CHANGE_TRUST_AGENT_SETTINGS;
import static com.android.settings.security.SecuritySettings.CHANGE_TRUST_AGENT_SETTINGS;
import android.app.Activity;
import android.content.Context;
@@ -35,7 +35,7 @@ import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.security.SecuritySettingsV2;
import com.android.settings.security.SecuritySettings;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -59,12 +59,12 @@ public class TrustAgentListPreferenceController extends AbstractPreferenceContro
private final LockPatternUtils mLockPatternUtils;
private final TrustAgentManager mTrustAgentManager;
private final SecuritySettingsV2 mHost;
private final SecuritySettings mHost;
private Intent mTrustAgentClickIntent;
private PreferenceCategory mSecurityCategory;
public TrustAgentListPreferenceController(Context context, SecuritySettingsV2 host,
public TrustAgentListPreferenceController(Context context, SecuritySettings host,
Lifecycle lifecycle) {
super(context);
final SecurityFeatureProvider provider = FeatureFactory.getFactory(context)