[DO NOT MERGE] FRP bypass defense in the settings app

Over the last few years, there have been a number of
Factory Reset Protection bypass bugs in the SUW flow.
It's unlikely to defense all points from individual apps.

Therefore, we decide to block some critical pages when
user doesn't complete the SUW flow.

Test: Can't open the certain pages in the suw flow.
Bug: 258422561
Fix: 200746457
Bug: 202975040
Fix: 213091525
Fix: 213090835
Fix: 201561699
Fix: 213090827
Fix: 213090875
Change-Id: Ia18f367109df5af7da0a5acad7702898a459d32e
Merged-In: Ia18f367109df5af7da0a5acad7702898a459d32e
This commit is contained in:
Tsung-Mao Fang
2022-01-03 18:25:04 +08:00
committed by Arc Wang
parent 8f412f14d2
commit b34ff2f272
10 changed files with 171 additions and 1 deletions

View File

@@ -55,6 +55,8 @@ import com.android.settingslib.core.instrumentation.Instrumentable;
import com.android.settingslib.search.Indexable;
import com.android.settingslib.widget.LayoutPreference;
import com.google.android.setupcompat.util.WizardManagerHelper;
import java.util.UUID;
/**
@@ -63,7 +65,7 @@ import java.util.UUID;
public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceFragment
implements DialogCreatable, HelpResourceProvider, Indexable {
private static final String TAG = "SettingsPreference";
private static final String TAG = "SettingsPreferenceFragment";
private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
@@ -123,6 +125,15 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
@VisibleForTesting
public boolean mPreferenceHighlighted = false;
@Override
public void onAttach(Context context) {
if (shouldSkipForInitialSUW() && !WizardManagerHelper.isDeviceProvisioned(getContext())) {
Log.w(TAG, "Skip " + getClass().getSimpleName() + " before SUW completed.");
finish();
}
super.onAttach(context);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -270,6 +281,16 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|| (mAdapter.getPreferenceAdapterPosition(preference) != RecyclerView.NO_POSITION));
}
/**
* Whether UI should be skipped in the initial SUW flow.
*
* @return {@code true} when UI should be skipped in the initial SUW flow.
* {@code false} when UI should not be skipped in the initial SUW flow.
*/
protected boolean shouldSkipForInitialSUW() {
return false;
}
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
updateEmptyView();

View File

@@ -72,6 +72,11 @@ public class AccountDashboardFragment extends DashboardFragment {
return buildPreferenceControllers(context, this /* parent */, authorities);
}
@Override
protected boolean shouldSkipForInitialSUW() {
return true;
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
SettingsPreferenceFragment parent, String[] authorities) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();

View File

@@ -491,6 +491,11 @@ public class AppInfoDashboardFragment extends DashboardFragment
return true;
}
@Override
protected boolean shouldSkipForInitialSUW() {
return true;
}
private void uninstallPkg(String packageName, boolean allUsers, boolean andDisable) {
stopListeningToPackageRemove();
// Create new intent to launch Uninstaller activity

View File

@@ -211,6 +211,11 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
}
}
@Override
protected boolean shouldSkipForInitialSUW() {
return true;
}
/**
* Long-pressing a developer options quick settings tile will by default (see
* QS_TILE_PREFERENCES in the manifest) take you to the developer options page.

View File

@@ -57,6 +57,11 @@ public class ResetDashboardFragment extends DashboardFragment {
return buildPreferenceControllers(context, getSettingsLifecycle());
}
@Override
protected boolean shouldSkipForInitialSUW() {
return true;
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();