Merge "Add persistent MTE toggle to development options."

This commit is contained in:
TreeHugger Robot
2023-02-14 02:40:01 +00:00
committed by Android (Google) Code Review
16 changed files with 663 additions and 29 deletions

View 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.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 DevelopmentMemtagFooterPreferenceController extends BasePreferenceController {
public DevelopmentMemtagFooterPreferenceController(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_development_memtag);
if (prefFooter != null && !TextUtils.isEmpty(helpUrl)) {
prefFooter.setLearnMoreAction(
v ->
mContext.startActivity(
HelpUtils.getHelpIntent(
mContext, helpUrl, /* backupContext= */ "")));
prefFooter.setLearnMoreText(mContext.getString(R.string.development_memtag_learn_more));
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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 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 DevelopmentMemtagPage extends DashboardFragment {
private static final String TAG = "DevelopmentMemtagPage";
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_DEVELOPMENT_MEMTAG_CATEGORY;
}
@Override
protected String getLogTag() {
return TAG;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
use(RebootWithMtePreferenceController.class).setFragment(this);
use(DevelopmentMemtagPreferenceController.class).setFragment(this);
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.development_memtag_page;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.development_memtag_page);
}

View File

@@ -0,0 +1,49 @@
/*
* 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 android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.security.MemtagHelper;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
public class DevelopmentMemtagPagePreferenceController extends DeveloperOptionsPreferenceController
implements PreferenceControllerMixin {
private static final String KEY_DEVELOPMENT_MEMTAG_PAGE = "development_memtag_page";
public DevelopmentMemtagPagePreferenceController(
Context context, DevelopmentSettingsDashboardFragment fragment) {
super(context);
}
@Override
public boolean isAvailable() {
return android.os.SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false);
}
@Override
public String getPreferenceKey() {
return KEY_DEVELOPMENT_MEMTAG_PAGE;
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
super.onDeveloperOptionsSwitchDisabled();
MemtagHelper.setChecked(false);
}
}

View File

@@ -0,0 +1,107 @@
/*
* 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.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.content.Context;
import android.os.SystemProperties;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.security.MemtagHelper;
import com.android.settings.security.MemtagRebootDialog;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
public class DevelopmentMemtagPreferenceController extends TogglePreferenceController {
private Preference mPreference;
private DashboardFragment mFragment;
public DevelopmentMemtagPreferenceController(Context context, String key) {
super(context, key);
}
public void setFragment(DashboardFragment fragment) {
mFragment = fragment;
}
@Override
public int getAvailabilityStatus() {
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
&& SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false)
? BasePreferenceController.AVAILABLE
: BasePreferenceController.UNSUPPORTED_ON_DEVICE;
}
@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()) {
int msg =
isChecked
? R.string.development_memtag_reboot_message_on
: R.string.development_memtag_reboot_message_off;
MemtagRebootDialog.show(mContext, mFragment, msg);
}
mFragment.forceUpdatePreferences();
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
refreshSummary(mPreference);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfMteIsDisabled(mContext);
if (admin != null) {
// Make sure this is disabled even if the user directly goes to this
// page via the android.settings.ADVANCED_MEMORY_PROTECTION_SETTINGS intent.
((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);
}
refreshSummary(preference);
}
@Override
public CharSequence getSummary() {
return mContext.getResources().getString(MemtagHelper.getSummary());
}
}

View File

@@ -556,7 +556,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new BugReportPreferenceController(context));
controllers.add(new BugReportHandlerPreferenceController(context));
controllers.add(new SystemServerHeapDumpPreferenceController(context));
controllers.add(new RebootWithMtePreferenceController(context, fragment));
controllers.add(new DevelopmentMemtagPagePreferenceController(context, fragment));
controllers.add(new LocalBackupPasswordPreferenceController(context));
controllers.add(new StayAwakePreferenceController(context, lifecycle));
controllers.add(new HdcpCheckingPreferenceController(context));

View File

@@ -17,32 +17,35 @@
package com.android.settings.development;
import android.content.Context;
import android.os.SystemProperties;
import android.text.TextUtils;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.security.MemtagHelper;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
public class RebootWithMtePreferenceController extends DeveloperOptionsPreferenceController
public class RebootWithMtePreferenceController extends BasePreferenceController
implements PreferenceControllerMixin {
private static final String KEY_REBOOT_WITH_MTE = "reboot_with_mte";
private final DevelopmentSettingsDashboardFragment mFragment;
private Fragment mFragment;
public RebootWithMtePreferenceController(
Context context, DevelopmentSettingsDashboardFragment fragment) {
super(context);
mFragment = fragment;
public RebootWithMtePreferenceController(Context context) {
super(context, KEY_REBOOT_WITH_MTE);
}
@Override
public boolean isAvailable() {
return android.os.SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false);
public int getAvailabilityStatus() {
return DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)
&& SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false)
? BasePreferenceController.AVAILABLE
: BasePreferenceController.UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -64,6 +67,10 @@ public class RebootWithMtePreferenceController extends DeveloperOptionsPreferenc
return KEY_REBOOT_WITH_MTE;
}
public void setFragment(Fragment fragment) {
mFragment = fragment;
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (Utils.isMonkeyRunning()) {

View File

@@ -1,5 +1,6 @@
/*
* 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.
@@ -58,7 +59,11 @@ public class MemtagPreferenceController extends TogglePreferenceController {
refreshSummary(mPreference);
}
if (isChecked != MemtagHelper.isOn()) {
MemtagRebootDialog.show(mContext, mFragment, isChecked);
int msg =
isChecked
? R.string.memtag_reboot_message_on
: R.string.memtag_reboot_message_off;
MemtagRebootDialog.show(mContext, mFragment, msg);
}
return true;
}

View File

@@ -34,16 +34,16 @@ public class MemtagRebootDialog extends InstrumentedDialogFragment
implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener {
public static final String TAG = "MemtagRebootDialog";
private boolean mIsChecked;
private int mMessage;
public MemtagRebootDialog(Context context, boolean isChecked) {
mIsChecked = isChecked;
public MemtagRebootDialog(Context context, int msg) {
mMessage = msg;
}
public static void show(Context context, Fragment host, boolean isChecked) {
public static void show(Context context, Fragment host, int msg) {
final FragmentManager manager = host.getActivity().getSupportFragmentManager();
if (manager.findFragmentByTag(TAG) == null) {
final MemtagRebootDialog dialog = new MemtagRebootDialog(context, isChecked);
final MemtagRebootDialog dialog = new MemtagRebootDialog(context, msg);
dialog.show(manager, TAG);
}
}
@@ -55,11 +55,9 @@ public class MemtagRebootDialog extends InstrumentedDialogFragment
@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)
.setMessage(mMessage)
.setPositiveButton(R.string.memtag_reboot_yes, this /* onClickListener */)
.setNegativeButton(R.string.memtag_reboot_no, null /* onClickListener */)
.create();