Add "Reboot with MTE" option for supported devices.

Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.development.RebootWithMteDialogTest"
Test: make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.development.RebootWithMtePreferenceControllerTest"

Bug: 206895651

Change-Id: I38ef2c5aeb5c5d805afd4f1ab860f7a0a4d18e1c
This commit is contained in:
Florian Mayer
2021-12-21 12:08:40 -08:00
parent a1c550650b
commit 966aef4edd
7 changed files with 270 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* 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.development;
import static junit.framework.Assert.assertEquals;
import android.content.Context;
import android.os.PowerManager;
import android.os.SystemProperties;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowPowerManager;
import org.robolectric.shadows.ShadowSystemProperties;
@RunWith(RobolectricTestRunner.class)
public class RebootWithMteDialogTest {
private Context mContext;
private ShadowPowerManager mShadowPowerManager;
private RebootWithMteDialog mDialog;
@Before
public void setup() throws Exception {
mContext = ApplicationProvider.getApplicationContext();
mShadowPowerManager = Shadows.shadowOf(mContext.getSystemService(PowerManager.class));
mDialog = new RebootWithMteDialog(mContext);
}
@Test
@Config(
shadows = {
ShadowSystemProperties.class,
ShadowPowerManager.class,
})
public void onClick_shouldSetPropAndReboot() {
mDialog.onClick(null, 0);
assertEquals(SystemProperties.get("arm64.memtag.bootctl"), "memtag-once");
assertEquals(mShadowPowerManager.getTimesRebooted(), 1);
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.development;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import android.content.Context;
import android.os.SystemProperties;
import androidx.test.core.app.ApplicationProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowSystemProperties;
@RunWith(RobolectricTestRunner.class)
@Config(
shadows = {
ShadowSystemProperties.class,
})
public class RebootWithMtePreferenceControllerTest {
private Context mContext;
private RebootWithMtePreferenceController mController;
@Mock private DevelopmentSettingsDashboardFragment mSettings;
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mContext = ApplicationProvider.getApplicationContext();
mController = new RebootWithMtePreferenceController(mContext, mSettings);
}
@Test
public void onAvailable_falseByDefault() {
assertFalse(mController.isAvailable());
}
@Test
public void onAvailable_sysPropEnabled() {
SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1");
assertTrue(mController.isAvailable());
}
}