mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-12-15 02:44:23 -05:00
167 lines
6.8 KiB
Diff
167 lines
6.8 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: flawedworld <38294951+flawedworld@users.noreply.github.com>
|
||
|
Date: Tue, 6 Apr 2021 01:15:32 +0100
|
||
|
Subject: [PATCH] add native debugging setting
|
||
|
|
||
|
---
|
||
|
res/values/strings.xml | 3 +
|
||
|
res/xml/security_dashboard_settings.xml | 6 +
|
||
|
.../NativeDebugPreferenceController.java | 106 ++++++++++++++++++
|
||
|
.../settings/security/SecuritySettings.java | 1 +
|
||
|
4 files changed, 116 insertions(+)
|
||
|
create mode 100644 src/com/android/settings/security/NativeDebugPreferenceController.java
|
||
|
|
||
|
diff --git a/res/values/strings.xml b/res/values/strings.xml
|
||
|
index d80f6cbd94..05a253e170 100644
|
||
|
--- a/res/values/strings.xml
|
||
|
+++ b/res/values/strings.xml
|
||
|
@@ -10146,4 +10146,7 @@
|
||
|
|
||
|
<string name="auto_reboot_title">Auto reboot</string>
|
||
|
<string name="auto_reboot_summary">Automatically reboot the device, if the phone hasn\'t been unlocked within the selected number of hours.</string>
|
||
|
+
|
||
|
+ <string name="native_debug_title">Enable native code debugging</string>
|
||
|
+ <string name="native_debug_summary">Generate useful logs / bug reports from crashes and permit debugging native code.</string>
|
||
|
</resources>
|
||
|
diff --git a/res/xml/security_dashboard_settings.xml b/res/xml/security_dashboard_settings.xml
|
||
|
index 5d13c434d4..0e8f0f511a 100644
|
||
|
--- a/res/xml/security_dashboard_settings.xml
|
||
|
+++ b/res/xml/security_dashboard_settings.xml
|
||
|
@@ -63,6 +63,12 @@
|
||
|
android:persistent="false"
|
||
|
android:entries="@array/auto_reboot_entries"
|
||
|
android:entryValues="@array/auto_reboot_values" />
|
||
|
+
|
||
|
+ <SwitchPreference
|
||
|
+ android:key="native_debug"
|
||
|
+ android:title="@string/native_debug_title"
|
||
|
+ android:summary="@string/native_debug_summary"
|
||
|
+ android:persistent="false" />
|
||
|
</PreferenceCategory>
|
||
|
|
||
|
<!-- work profile security section -->
|
||
|
diff --git a/src/com/android/settings/security/NativeDebugPreferenceController.java b/src/com/android/settings/security/NativeDebugPreferenceController.java
|
||
|
new file mode 100644
|
||
|
index 0000000000..9271e6e21c
|
||
|
--- /dev/null
|
||
|
+++ b/src/com/android/settings/security/NativeDebugPreferenceController.java
|
||
|
@@ -0,0 +1,106 @@
|
||
|
+/*
|
||
|
+ * Copyright (C) 2020 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.os.UserHandle;
|
||
|
+import android.os.UserManager;
|
||
|
+import android.os.SystemProperties;
|
||
|
+
|
||
|
+import android.provider.Settings;
|
||
|
+
|
||
|
+import androidx.preference.Preference;
|
||
|
+import androidx.preference.PreferenceCategory;
|
||
|
+import androidx.preference.PreferenceGroup;
|
||
|
+import androidx.preference.PreferenceScreen;
|
||
|
+import androidx.preference.TwoStatePreference;
|
||
|
+import androidx.preference.SwitchPreference;
|
||
|
+
|
||
|
+import com.android.internal.widget.LockPatternUtils;
|
||
|
+import com.android.settings.core.PreferenceControllerMixin;
|
||
|
+import com.android.settingslib.core.AbstractPreferenceController;
|
||
|
+import com.android.settingslib.core.lifecycle.events.OnResume;
|
||
|
+
|
||
|
+public class NativeDebugPreferenceController extends AbstractPreferenceController
|
||
|
+ implements PreferenceControllerMixin, OnResume, Preference.OnPreferenceChangeListener {
|
||
|
+
|
||
|
+ private static final String SYS_KEY_NATIVE_DEBUG = "persist.native_debug";
|
||
|
+ private static final String PREF_KEY_NATIVE_DEBUG = "native_debug";
|
||
|
+ private static final String PREF_KEY_SECURITY_CATEGORY = "security_category";
|
||
|
+
|
||
|
+ private PreferenceCategory mSecurityCategory;
|
||
|
+ private SwitchPreference mNativeDebug;
|
||
|
+ private boolean mIsAdmin;
|
||
|
+ private UserManager mUm;
|
||
|
+
|
||
|
+ public NativeDebugPreferenceController(Context context) {
|
||
|
+ super(context);
|
||
|
+ mUm = UserManager.get(context);
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public void displayPreference(PreferenceScreen screen) {
|
||
|
+ super.displayPreference(screen);
|
||
|
+ mSecurityCategory = screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
|
||
|
+ updatePreferenceState();
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public boolean isAvailable() {
|
||
|
+ mIsAdmin = mUm.isAdminUser();
|
||
|
+ return mIsAdmin;
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public String getPreferenceKey() {
|
||
|
+ return PREF_KEY_NATIVE_DEBUG;
|
||
|
+ }
|
||
|
+
|
||
|
+ // TODO: should we use onCreatePreferences() instead?
|
||
|
+ private void updatePreferenceState() {
|
||
|
+ if (mSecurityCategory == null) {
|
||
|
+ return;
|
||
|
+ }
|
||
|
+
|
||
|
+ if (mIsAdmin) {
|
||
|
+ mNativeDebug = (SwitchPreference) mSecurityCategory.findPreference(PREF_KEY_NATIVE_DEBUG);
|
||
|
+ mNativeDebug.setChecked(SystemProperties.getBoolean(SYS_KEY_NATIVE_DEBUG, true));
|
||
|
+ } else {
|
||
|
+ mSecurityCategory.removePreference(mSecurityCategory.findPreference(PREF_KEY_NATIVE_DEBUG));
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public void onResume() {
|
||
|
+ updatePreferenceState();
|
||
|
+ if (mNativeDebug != null) {
|
||
|
+ boolean mode = mNativeDebug.isChecked();
|
||
|
+ SystemProperties.set(SYS_KEY_NATIVE_DEBUG, Boolean.toString(mode));
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ @Override
|
||
|
+ public boolean onPreferenceChange(Preference preference, Object value) {
|
||
|
+ final String key = preference.getKey();
|
||
|
+ if (PREF_KEY_NATIVE_DEBUG.equals(key)) {
|
||
|
+ final boolean mode = !mNativeDebug.isChecked();
|
||
|
+ SystemProperties.set(SYS_KEY_NATIVE_DEBUG, Boolean.toString(mode));
|
||
|
+ }
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+}
|
||
|
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
|
||
|
index defbdc2e68..89f5176121 100644
|
||
|
--- a/src/com/android/settings/security/SecuritySettings.java
|
||
|
+++ b/src/com/android/settings/security/SecuritySettings.java
|
||
|
@@ -129,6 +129,7 @@ public class SecuritySettings extends DashboardFragment {
|
||
|
securityPreferenceControllers.add(new LockScreenPreferenceController(context, lifecycle));
|
||
|
securityPreferenceControllers.add(new ChangeScreenLockPreferenceController(context, host));
|
||
|
securityPreferenceControllers.add(new AutoRebootPreferenceController(context));
|
||
|
+ securityPreferenceControllers.add(new NativeDebugPreferenceController(context));
|
||
|
controllers.add(new PreferenceCategoryController(context, SECURITY_CATEGORY)
|
||
|
.setChildren(securityPreferenceControllers));
|
||
|
controllers.addAll(securityPreferenceControllers);
|