Merge "Add persistent MTE toggle to development options."
This commit is contained in:
committed by
Android (Google) Code Review
commit
834dda9105
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.development;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
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 DevelopmentMemtagPagePreferenceControllerTest {
|
||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
||||
|
||||
private DevelopmentMemtagPagePreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
@Mock private DevelopmentSettingsDashboardFragment mFragment;
|
||||
private static final String FRAGMENT_TAG = "memtag_page";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new DevelopmentMemtagPagePreferenceController(mContext, mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAvailable_sysPropEnabled() {
|
||||
SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1");
|
||||
assertTrue(mController.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAvailable_sysPropDisabled() {
|
||||
SystemProperties.set("ro.arm64.memtag.bootctl_supported", "0");
|
||||
assertFalse(mController.isAvailable());
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DevelopmentMemtagPageTest {
|
||||
private DevelopmentMemtagPage mMemtagPage;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mMemtagPage = new DevelopmentMemtagPage();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_isSETTINGS_MEMTAG_CATEGORY() {
|
||||
assertThat(mMemtagPage.getMetricsCategory())
|
||||
.isEqualTo(SettingsEnums.SETTINGS_MEMTAG_CATEGORY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceScreenResId_isMemtag_page() {
|
||||
assertThat(mMemtagPage.getPreferenceScreenResId()).isEqualTo(R.xml.development_memtag_page);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SEARCH_INDEX_DATA_PROVIDERgetPreferenceControllers_isNotEmpty() {
|
||||
assertThat(
|
||||
DevelopmentMemtagPage.SEARCH_INDEX_DATA_PROVIDER.getPreferenceControllers(
|
||||
mContext))
|
||||
.isNotEmpty();
|
||||
}
|
||||
}
|
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.development;
|
||||
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentContainerView;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.security.ZygoteShadow;
|
||||
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;
|
||||
import org.junit.Rule;
|
||||
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 = {
|
||||
ZygoteShadow.class,
|
||||
ShadowDeviceConfig.class,
|
||||
ShadowInteractionJankMonitor.class,
|
||||
ShadowRestrictedLockUtilsInternal.class
|
||||
})
|
||||
public class DevelopmentMemtagPreferenceControllerTest {
|
||||
private final String mMemtagSupportedProperty = "ro.arm64.memtag.bootctl_supported";
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<TestActivity> mActivityTestRule =
|
||||
new ActivityTestRule<>(TestActivity.class);
|
||||
|
||||
private DevelopmentMemtagPage mMemtagPage;
|
||||
private DevelopmentMemtagPreferenceController mController;
|
||||
private Context mContext;
|
||||
private TestActivity mActivity;
|
||||
|
||||
private static final String FRAGMENT_TAG = "development_memtag_page";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowSystemProperties.override(mMemtagSupportedProperty, "true");
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mMemtagPage = new DevelopmentMemtagPage();
|
||||
mActivity = mActivityTestRule.getActivity();
|
||||
mActivity
|
||||
.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.add(TestActivity.CONTAINER_VIEW_ID, mMemtagPage)
|
||||
.commit();
|
||||
mController = new DevelopmentMemtagPreferenceController(mContext, FRAGMENT_TAG);
|
||||
mController.setFragment(mMemtagPage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliceHighlightMenuRes_isMenu_key_security() {
|
||||
assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_security);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isChecked_updatesSummary() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||
mController.setChecked(true);
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getResources().getString(R.string.memtag_on));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isUnchecked_updatesSummary() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||
mController.setChecked(false);
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getResources().getString(R.string.memtag_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isCheckedPending_updatesSummary() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||
mController.setChecked(true);
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getResources().getString(R.string.memtag_on_pending));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isUncheckedPending_updatesSummary() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||
mController.setChecked(false);
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getResources().getString(R.string.memtag_off_pending));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isCheckedPending_showsDialog() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||
mController.setChecked(true);
|
||||
onView(withText(R.string.memtag_reboot_title)).inRoot(isDialog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isUncheckedPending_showsDialog() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||
mController.setChecked(false);
|
||||
onView(withText(R.string.memtag_reboot_title)).inRoot(isDialog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isChecked_doesNotShowDialog() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(false);
|
||||
mController.setChecked(false);
|
||||
onView(withText(R.string.memtag_reboot_title)).inRoot(isDialog()).check(doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_isUnchecked_doesNotShowDialog() {
|
||||
ZygoteShadow.setSupportsMemoryTagging(true);
|
||||
mController.setChecked(true);
|
||||
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;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
FragmentContainerView contentView = new FragmentContainerView(this);
|
||||
contentView.setId(CONTAINER_VIEW_ID);
|
||||
setContentView(contentView);
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,6 +22,7 @@ import static junit.framework.Assert.assertTrue;
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
@@ -42,14 +43,15 @@ import org.robolectric.shadows.ShadowSystemProperties;
|
||||
public class RebootWithMtePreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private RebootWithMtePreferenceController mController;
|
||||
@Mock private DevelopmentSettingsDashboardFragment mSettings;
|
||||
@Mock private Fragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mController = new RebootWithMtePreferenceController(mContext, mSettings);
|
||||
mController = new RebootWithMtePreferenceController(mContext);
|
||||
mController.setFragment(mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -25,7 +25,7 @@ import org.robolectric.annotation.Implements;
|
||||
public class ZygoteShadow {
|
||||
private static boolean sSupportsMemoryTagging;
|
||||
|
||||
static void setSupportsMemoryTagging(boolean value) {
|
||||
public static void setSupportsMemoryTagging(boolean value) {
|
||||
sSupportsMemoryTagging = value;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user