Merge "FRP bypass defense in the settings app"

This commit is contained in:
TreeHugger Robot
2022-01-05 05:37:51 +00:00
committed by Android (Google) Code Review
10 changed files with 170 additions and 1 deletions

View File

@@ -23,11 +23,13 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.FrameLayout;
@@ -41,6 +43,7 @@ import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.ShadowFragment;
import com.android.settings.widget.WorkOnlyCategory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -64,7 +67,9 @@ public class SettingsPreferenceFragmentTest {
private PreferenceScreen mPreferenceScreen;
private Context mContext;
private TestFragment mFragment;
private TestFragment2 mFragment2;
private View mEmptyView;
private int mInitDeviceProvisionedValue;
@Before
public void setUp() {
@@ -72,13 +77,24 @@ public class SettingsPreferenceFragmentTest {
FakeFeatureFactory.setupForTest();
mContext = RuntimeEnvironment.application;
mFragment = spy(new TestFragment());
mFragment2 = spy(new TestFragment2());
doReturn(mActivity).when(mFragment).getActivity();
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment2.getContext()).thenReturn(mContext);
mEmptyView = new View(mContext);
ReflectionHelpers.setField(mFragment, "mEmptyView", mEmptyView);
doReturn(ITEM_COUNT).when(mPreferenceScreen).getPreferenceCount();
mInitDeviceProvisionedValue = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 0);
}
@After
public void tearDown() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, mInitDeviceProvisionedValue);
}
@Test
@@ -210,8 +226,66 @@ public class SettingsPreferenceFragmentTest {
assertThat(mFragment.mPinnedHeaderFrameLayout.getVisibility()).isEqualTo(View.INVISIBLE);
}
@Test
public void onAttach_shouldNotSkipForSUWAndDeviceIsProvisioned_notCallFinish() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 1);
mFragment.onAttach(mContext);
verify(mFragment, never()).finish();
}
@Test
public void onAttach_shouldNotSkipForSUWAndDeviceIsNotProvisioned_notCallFinish() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 0);
mFragment.onAttach(mContext);
verify(mFragment, never()).finish();
}
@Test
public void onAttach_shouldSkipForSUWAndDeviceIsDeviceProvisioned_notCallFinish() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 1);
mFragment2.onAttach(mContext);
verify(mFragment2, never()).finish();
}
@Test
public void onAttach_shouldSkipForSUWAndDeviceProvisioned_notCallFinish() {
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.DEVICE_PROVISIONED, 0);
mFragment2.onAttach(mContext);
verify(mFragment2, times(1)).finish();
}
public static class TestFragment extends SettingsPreferenceFragment {
@Override
protected boolean shouldSkipForInitialSUW() {
return false;
}
@Override
public int getMetricsCategory() {
return 0;
}
}
public static class TestFragment2 extends SettingsPreferenceFragment {
@Override
protected boolean shouldSkipForInitialSUW() {
return true;
}
@Override
public int getMetricsCategory() {
return 0;

View File

@@ -114,4 +114,9 @@ public class AccountDashboardFragmentTest {
assertThat(indexRaws).isNotEmpty();
}
@Test
public void shouldSkipForInitialSUW_returnTrue() {
assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
}
}

View File

@@ -384,6 +384,11 @@ public final class AppInfoDashboardFragmentTest {
.isTrue();
}
@Test
public void shouldSkipForInitialSUW_returnTrue() {
assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
}
@Implements(AppUtils.class)
public static class ShadowAppUtils {

View File

@@ -278,6 +278,11 @@ public class DevelopmentSettingsDashboardFragmentTest {
verify(controller).onDisableLogPersistDialogRejected();
}
@Test
public void shouldSkipForInitialSUW_returnTrue() {
assertThat(mDashboard.shouldSkipForInitialSUW()).isTrue();
}
@Implements(EnableDevelopmentSettingWarningDialog.class)
public static class ShadowEnableDevelopmentSettingWarningDialog {

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2022 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.system;
import static com.google.common.truth.Truth.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class ResetDashboardFragmentTest {
private ResetDashboardFragment mFragment;
@Before
public void setup() {
mFragment = new ResetDashboardFragment();
}
@Test
public void shouldSkipForInitialSUW_returnTrue() {
assertThat(mFragment.shouldSkipForInitialSUW()).isTrue();
}
}