Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb8537f0 authored by Florian Mayer's avatar Florian Mayer
Browse files

[MTE] disable dev option if security setting is on

Test: make RunSettingsRoboTests
      check dev settings manually
Bug: 245624194
Change-Id: I3d9c9b89cd5483eee9800077943b1c30738e4c16
parent 57c6df71
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10475,6 +10475,8 @@
    <!-- Title for the button to reboot with MTE enabled. [CHAR LIMIT=NONE] -->
    <string name="reboot_with_mte_title">Reboot with MTE</string>
    <string name="reboot_with_mte_message">System will reboot and allow to experiment with Memory Tagging Extension (MTE). MTE may negatively impact system performance and stability. Will be reset on next subsequent reboot.</string>
    <string name="reboot_with_mte_summary">Try MTE for a single boot for app development.</string>
    <string name="reboot_with_mte_already_enabled">MTE is enabled through Advanced memory protection.</string>
    <!-- Toast that is shown when the user initiates capturing a heap dump for the system server. [CHAR LIMIT=NONE] -->
    <string name="capturing_system_heap_dump_message">Capturing system heap dump</string>
    <!-- Toast that is shown if there's an error capturing the user initiated heap dump. [CHAR LIMIT=NONE] -->
+16 −0
Original line number Diff line number Diff line
@@ -21,8 +21,10 @@ import android.text.TextUtils;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.security.MemtagHelper;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

public class RebootWithMtePreferenceController extends DeveloperOptionsPreferenceController
@@ -43,6 +45,20 @@ public class RebootWithMtePreferenceController extends DeveloperOptionsPreferenc
        return android.os.SystemProperties.getBoolean("ro.arm64.memtag.bootctl_supported", false);
    }

    @Override
    public CharSequence getSummary() {
        if (MemtagHelper.isChecked()) {
            return mContext.getResources().getString(R.string.reboot_with_mte_already_enabled);
        }
        return mContext.getResources().getString(R.string.reboot_with_mte_summary);
    }

    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        preference.setEnabled(!MemtagHelper.isChecked());
    }

    @Override
    public String getPreferenceKey() {
        return KEY_REBOOT_WITH_MTE;
+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static junit.framework.Assert.assertTrue;
import android.content.Context;
import android.os.SystemProperties;

import androidx.preference.Preference;
import androidx.test.core.app.ApplicationProvider;

import org.junit.Before;
@@ -61,4 +62,19 @@ public class RebootWithMtePreferenceControllerTest {
        SystemProperties.set("ro.arm64.memtag.bootctl_supported", "1");
        assertTrue(mController.isAvailable());
    }

    @Test
    public void updateState_enabledByDefault() {
        Preference preference = new Preference(mContext);
        mController.updateState(preference);
        assertTrue(preference.isEnabled());
    }

    @Test
    public void updateState_disabledIfAlreadyOn() {
        SystemProperties.set("arm64.memtag.bootctl", "memtag");
        Preference preference = new Preference(mContext);
        mController.updateState(preference);
        assertFalse(preference.isEnabled());
    }
}