Add MTE Settings.
MTE is a technology to help prevent exploitation of some security bugs. We want to offer users that want to trade off a slight reduction in performance for higher security the option to do so from the settings menu. Test: make RunSettingsRoboTests check UI manually Bug: 245624194 Change-Id: Ifbb76e124142ae843ce90bd604ae8417d65fcc7b
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
/** Footer for face settings showing the help text and help link. */
|
||||
public class MemtagFooterPreferenceController extends BasePreferenceController {
|
||||
|
||||
public MemtagFooterPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
// Set up learn more link.
|
||||
FooterPreference prefFooter = screen.findPreference(getPreferenceKey());
|
||||
String helpUrl = mContext.getString(R.string.help_url_memtag);
|
||||
if (prefFooter != null && !TextUtils.isEmpty(helpUrl)) {
|
||||
prefFooter.setLearnMoreAction(
|
||||
v ->
|
||||
mContext.startActivity(
|
||||
HelpUtils.getHelpIntent(
|
||||
mContext, helpUrl, /* backupContext= */ "")));
|
||||
prefFooter.setLearnMoreText(mContext.getString(R.string.memtag_learn_more));
|
||||
}
|
||||
}
|
||||
}
|
79
src/com/android/settings/security/MemtagHelper.java
Normal file
79
src/com/android/settings/security/MemtagHelper.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 android.os.SystemProperties;
|
||||
|
||||
import com.android.internal.os.Zygote;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MemtagHelper {
|
||||
private static boolean isForcedOff() {
|
||||
return "force_off"
|
||||
.equals(
|
||||
SystemProperties.get(
|
||||
"persist.device_config.memory_safety_native.bootloader_override"));
|
||||
}
|
||||
|
||||
public static boolean isChecked() {
|
||||
String modes[] = SystemProperties.get("arm64.memtag.bootctl", "").split(",");
|
||||
return Arrays.asList(modes).contains("memtag");
|
||||
}
|
||||
|
||||
public static void setChecked(boolean isChecked) {
|
||||
String newString = isChecked ? "memtag" : "none";
|
||||
SystemProperties.set("arm64.memtag.bootctl", newString);
|
||||
}
|
||||
|
||||
public static int getAvailabilityStatus() {
|
||||
if (MemtagHelper.isForcedOff()) {
|
||||
return BasePreferenceController.DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
return SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false)
|
||||
? BasePreferenceController.AVAILABLE
|
||||
: BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether MTE is currently active on this device. We use this to determine whether we
|
||||
* need to reboot the device to apply the user choice.
|
||||
*
|
||||
* @return boolean whether MTE is currently active
|
||||
*/
|
||||
public static boolean isOn() {
|
||||
return Zygote.nativeSupportsMemoryTagging();
|
||||
}
|
||||
|
||||
public static int getSummary() {
|
||||
if (isForcedOff()) {
|
||||
return R.string.memtag_force_off;
|
||||
}
|
||||
if (isOn()) {
|
||||
if (isChecked()) {
|
||||
return R.string.memtag_on;
|
||||
}
|
||||
return R.string.memtag_off_pending;
|
||||
}
|
||||
if (isChecked()) {
|
||||
return R.string.memtag_on_pending;
|
||||
}
|
||||
return R.string.memtag_off;
|
||||
}
|
||||
}
|
56
src/com/android/settings/security/MemtagPage.java
Normal file
56
src/com/android/settings/security/MemtagPage.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
@SearchIndexable
|
||||
public class MemtagPage extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "MemtagPage";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_MEMTAG_CATEGORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
use(MemtagPreferenceController.class).setFragment(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.memtag_page;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.memtag_page);
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class MemtagPagePreferenceController extends BasePreferenceController {
|
||||
static final String KEY_MEMTAG = "memtag_page";
|
||||
|
||||
public MemtagPagePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MemtagHelper.getAvailabilityStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
Preference preference = screen.findPreference(getPreferenceKey());
|
||||
refreshSummary(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getResources().getString(MemtagHelper.getSummary());
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
public class MemtagPreferenceController extends TogglePreferenceController {
|
||||
private Preference mPreference;
|
||||
private Fragment mFragment;
|
||||
|
||||
public MemtagPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setFragment(Fragment fragment) {
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MemtagHelper.getAvailabilityStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return MemtagHelper.isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
MemtagHelper.setChecked(isChecked);
|
||||
if (mPreference != null) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
if (isChecked != MemtagHelper.isOn()) {
|
||||
MemtagRebootDialog.show(mContext, mFragment, isChecked);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_security;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
refreshSummary(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getResources().getString(MemtagHelper.getSummary());
|
||||
}
|
||||
}
|
73
src/com/android/settings/security/MemtagRebootDialog.java
Normal file
73
src/com/android/settings/security/MemtagRebootDialog.java
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 android.app.Dialog;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
public class MemtagRebootDialog extends InstrumentedDialogFragment
|
||||
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
|
||||
|
||||
public static final String TAG = "MemtagRebootDialog";
|
||||
private boolean mIsChecked;
|
||||
|
||||
public MemtagRebootDialog(Context context, boolean isChecked) {
|
||||
mIsChecked = isChecked;
|
||||
}
|
||||
|
||||
public static void show(Context context, Fragment host, boolean isChecked) {
|
||||
final FragmentManager manager = host.getActivity().getSupportFragmentManager();
|
||||
if (manager.findFragmentByTag(TAG) == null) {
|
||||
final MemtagRebootDialog dialog = new MemtagRebootDialog(context, isChecked);
|
||||
dialog.show(manager, TAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.REBOOT_WITH_MTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
int msg =
|
||||
mIsChecked ? R.string.memtag_reboot_message_on : R.string.memtag_reboot_message_off;
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.memtag_reboot_title)
|
||||
.setMessage(msg)
|
||||
.setPositiveButton(R.string.memtag_reboot_yes, this /* onClickListener */)
|
||||
.setNegativeButton(R.string.memtag_reboot_no, null /* onClickListener */)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PowerManager pm = getContext().getSystemService(PowerManager.class);
|
||||
pm.reboot(/* reason */ null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user