Merge "[MTE] allow device policy to control setting"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2be085005b
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.security;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowSystemProperties;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowRestrictedLockUtilsInternal.class})
|
||||
public class MemtagPagePreferenceControllerTest {
|
||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
||||
|
||||
private MemtagPagePreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
private static final String FRAGMENT_TAG = "memtag_page";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new MemtagPagePreferenceController(mContext, FRAGMENT_TAG);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_disabledByAdmin_disablesPreference() {
|
||||
ShadowRestrictedLockUtilsInternal.setMteIsDisabled(true);
|
||||
RestrictedPreference preference = new RestrictedPreference(mContext);
|
||||
preference.setKey(mController.getPreferenceKey());
|
||||
PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
|
||||
screen.addPreference(preference);
|
||||
|
||||
mController.displayPreference(screen);
|
||||
assertThat(preference.isDisabledByAdmin()).isTrue();
|
||||
}
|
||||
}
|
@@ -32,6 +32,8 @@ import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.testutils.shadow.ShadowInteractionJankMonitor;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -48,7 +50,8 @@ import org.robolectric.shadows.ShadowSystemProperties;
|
||||
shadows = {
|
||||
ZygoteShadow.class,
|
||||
ShadowDeviceConfig.class,
|
||||
ShadowInteractionJankMonitor.class
|
||||
ShadowInteractionJankMonitor.class,
|
||||
ShadowRestrictedLockUtilsInternal.class
|
||||
})
|
||||
public class MemtagPreferenceControllerTest {
|
||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
||||
@@ -145,6 +148,14 @@ public class MemtagPreferenceControllerTest {
|
||||
onView(withText(R.string.memtag_reboot_title)).inRoot(isDialog()).check(doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_disabledByAdmin_disablesPreference() {
|
||||
ShadowRestrictedLockUtilsInternal.setMteIsDisabled(true);
|
||||
RestrictedSwitchPreference preference = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.isDisabledByAdmin()).isTrue();
|
||||
}
|
||||
|
||||
private static final class TestActivity extends FragmentActivity {
|
||||
|
||||
private static final int CONTAINER_VIEW_ID = 1234;
|
||||
|
@@ -33,6 +33,7 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
private static boolean sIsRestricted;
|
||||
private static boolean sHasSystemFeature;
|
||||
private static boolean sMaximumTimeToLockIsSet;
|
||||
private static boolean sMteOverridden;
|
||||
private static String[] sRestrictedPkgs;
|
||||
private static DevicePolicyManager sDevicePolicyManager;
|
||||
private static String[] sDisabledTypes;
|
||||
@@ -45,6 +46,7 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
sKeyguardDisabledFeatures = 0;
|
||||
sDisabledTypes = new String[0];
|
||||
sMaximumTimeToLockIsSet = false;
|
||||
sMteOverridden = false;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
@@ -101,6 +103,11 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
return sMaximumTimeToLockIsSet ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static EnforcedAdmin checkIfMteIsDisabled(Context context) {
|
||||
return sMteOverridden ? new EnforcedAdmin() : null;
|
||||
}
|
||||
|
||||
public static void setRestricted(boolean restricted) {
|
||||
sIsRestricted = restricted;
|
||||
}
|
||||
@@ -132,4 +139,8 @@ public class ShadowRestrictedLockUtilsInternal {
|
||||
public static void setMaximumTimeToLockIsSet(boolean isSet) {
|
||||
sMaximumTimeToLockIsSet = isSet;
|
||||
}
|
||||
|
||||
public static void setMteIsDisabled(boolean isSet) {
|
||||
sMteOverridden = isSet;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user