From 4a4de015c8c7724bc9c222cc6c8f1a6dc4a013f1 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 28 Feb 2013 14:49:24 -0800 Subject: [PATCH] Settings: Add Superuser entry Amended for r-x86 porting by electrikjesus. Squashed commit of the following: Author: Koushik Dutta Switch to new Superuser Change-Id: I9d91392ad6fbc9953d19059ab59b91d214c00e0c Author: Danny Baumann Hide Superuser entry if root access for apps is disabled. Change-Id: Ibb77ba5a0fccf22564a26b8b1e13f7762c65718e Author: Ricardo Cerqueira Development: Root for apps is unavailable if the su daemon isn't running The superuser options are tied to the Superuser app variant we use, which in turn is tied to the su daemon. No daemon, no menu options. Change-Id: I41d58e62986759336ab38e67f26a558c2eed5aa3 Change-Id: I9d91392ad6fbc9953d19059ab59b91d214c00e0c Conflicts: Android.bp AndroidManifest.xml res/xml/development_settings.xml src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java --- Android.bp | 13 ++- AndroidManifest.xml | 89 +++++++++++++++++++ koush | 1 + proguard.flags | 2 + src/com/android/settings/Settings.java | 1 + .../android/settings/SettingsActivity.java | 6 ++ .../core/gateway/SettingsGateway.java | 2 + .../superuser/MultitaskSuRequestActivity.java | 4 + .../cyanogenmod/superuser/NotifyActivity.java | 4 + .../superuser/PolicyNativeFragment.java | 4 + .../superuser/RequestActivity.java | 4 + .../cyanogenmod/superuser/SuReceiver.java | 4 + .../RootAccessPreferenceController.java | 7 ++ 13 files changed, 139 insertions(+), 2 deletions(-) create mode 120000 koush create mode 100644 src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java create mode 100644 src/com/android/settings/cyanogenmod/superuser/NotifyActivity.java create mode 100644 src/com/android/settings/cyanogenmod/superuser/PolicyNativeFragment.java create mode 100644 src/com/android/settings/cyanogenmod/superuser/RequestActivity.java create mode 100644 src/com/android/settings/cyanogenmod/superuser/SuReceiver.java diff --git a/Android.bp b/Android.bp index 12b3c5b414f..0108df285b8 100644 --- a/Android.bp +++ b/Android.bp @@ -29,12 +29,21 @@ android_library { srcs: ["src/**/*.java", "SakuraSettings/src/**/*.java", + "koush/Widgets/Widgets/src/**/*.java", + "koush/Superuser/Superuser/src/**/*.java", + "src/com/android/settings/cyanogenmod/superuser/*.java", ], - aaptflags: ["--extra-packages com.sakura.settings"], + aaptflags: ["--extra-packages com.sakura.settings", + "--extra-packages com.koushikdutta.superuser", + "--extra-packages com.koushikdutta.widgets", + ], resource_dirs: ["res", - "SakuraSettings/res" + "SakuraSettings/res", + "koush/Widgets/WidgetsSample/res", + "koush/Widgets/Widgets/res", + "koush/Superuser/Superuser/res", ], static_libs: [ diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4e4db6eeb50..aa5ae3c7a86 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -109,6 +109,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/koush b/koush new file mode 120000 index 00000000000..8e6c0880fd0 --- /dev/null +++ b/koush @@ -0,0 +1 @@ +../../../external/koush \ No newline at end of file diff --git a/proguard.flags b/proguard.flags index 4f300cd94b0..3733e0550be 100644 --- a/proguard.flags +++ b/proguard.flags @@ -7,6 +7,8 @@ # Keep all Fragments in this package, which are used by reflection. -keep public class com.android.settings.** extends androidx.fragment.app.Fragment +-keep public class com.android.settings.cyanogenmod.superuser.** +-keep public class com.koushikdutta.** # Keep all preference controllers needed by slice and DashboardFragment. -keep class * extends com.android.settings.core.BasePreferenceController { diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 7c796cbd141..0194a1484e6 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -151,6 +151,7 @@ public static class TrustedCredentialsSettingsActivity extends SettingsActivity public static class PaymentSettingsActivity extends SettingsActivity { /* empty */ } public static class PrintSettingsActivity extends SettingsActivity { /* empty */ } public static class PrintJobSettingsActivity extends SettingsActivity { /* empty */ } + public static class SuperuserActivity extends SettingsActivity { /* empty */ } public static class ZenModeSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeBehaviorSettingsActivity extends SettingsActivity { /* empty */ } public static class ZenModeBlockedEffectsSettingsActivity extends SettingsActivity { /* empty */ } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 47bb2f839ea..aaf1e2bc1d3 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -58,6 +58,7 @@ import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.gateway.SettingsGateway; import com.android.settings.dashboard.DashboardFeatureProvider; +import com.android.settings.development.RootAccessPreferenceController; import com.android.settings.homepage.TopLevelSettings; import com.android.settings.overlay.FeatureFactory; import com.android.settings.wfd.WifiDisplaySettings; @@ -639,6 +640,11 @@ private void doUpdateTilesList() { && !Utils.isMonkeyRunning(), isAdmin) || somethingChanged; + somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, + Settings.SuperuserActivity.class.getName()), + RootAccessPreferenceController.isRootForAppsEnabled(), isAdmin) + || somethingChanged; + final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this) && !Utils.isMonkeyRunning(); somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java index c1c05c0060e..3cb5537f0c7 100644 --- a/src/com/android/settings/core/gateway/SettingsGateway.java +++ b/src/com/android/settings/core/gateway/SettingsGateway.java @@ -65,6 +65,7 @@ import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment; import com.android.settings.connecteddevice.PreviouslyConnectedDeviceDashboardFragment; import com.android.settings.connecteddevice.usb.UsbDetailsFragment; +import com.android.settings.cyanogenmod.superuser.PolicyNativeFragment; import com.android.settings.datausage.DataSaverSummary; import com.android.settings.datausage.DataUsageList; import com.android.settings.datausage.DataUsageSummary; @@ -244,6 +245,7 @@ public class SettingsGateway { ZenAccessSettings.class.getName(), ZenAccessDetails.class.getName(), ZenModeAutomationSettings.class.getName(), + PolicyNativeFragment.class.getName(), PrintSettingsFragment.class.getName(), PrintJobSettingsFragment.class.getName(), TrustedCredentialsSettings.class.getName(), diff --git a/src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java b/src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java new file mode 100644 index 00000000000..01030763684 --- /dev/null +++ b/src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java @@ -0,0 +1,4 @@ +package com.android.settings.cyanogenmod.superuser; + +public class MultitaskSuRequestActivity extends com.koushikdutta.superuser.MultitaskSuRequestActivity { +} \ No newline at end of file diff --git a/src/com/android/settings/cyanogenmod/superuser/NotifyActivity.java b/src/com/android/settings/cyanogenmod/superuser/NotifyActivity.java new file mode 100644 index 00000000000..23aa6a720d0 --- /dev/null +++ b/src/com/android/settings/cyanogenmod/superuser/NotifyActivity.java @@ -0,0 +1,4 @@ +package com.android.settings.cyanogenmod.superuser; + +public class NotifyActivity extends com.koushikdutta.superuser.NotifyActivity { +} \ No newline at end of file diff --git a/src/com/android/settings/cyanogenmod/superuser/PolicyNativeFragment.java b/src/com/android/settings/cyanogenmod/superuser/PolicyNativeFragment.java new file mode 100644 index 00000000000..1c74543bfcf --- /dev/null +++ b/src/com/android/settings/cyanogenmod/superuser/PolicyNativeFragment.java @@ -0,0 +1,4 @@ +package com.android.settings.cyanogenmod.superuser; + +public class PolicyNativeFragment extends com.koushikdutta.superuser.PolicyNativeFragment { +} \ No newline at end of file diff --git a/src/com/android/settings/cyanogenmod/superuser/RequestActivity.java b/src/com/android/settings/cyanogenmod/superuser/RequestActivity.java new file mode 100644 index 00000000000..e6deca49cd6 --- /dev/null +++ b/src/com/android/settings/cyanogenmod/superuser/RequestActivity.java @@ -0,0 +1,4 @@ +package com.android.settings.cyanogenmod.superuser; + +public class RequestActivity extends com.koushikdutta.superuser.RequestActivity { +} \ No newline at end of file diff --git a/src/com/android/settings/cyanogenmod/superuser/SuReceiver.java b/src/com/android/settings/cyanogenmod/superuser/SuReceiver.java new file mode 100644 index 00000000000..c4f9174b04f --- /dev/null +++ b/src/com/android/settings/cyanogenmod/superuser/SuReceiver.java @@ -0,0 +1,4 @@ +package com.android.settings.cyanogenmod.superuser; + +public class SuReceiver extends com.koushikdutta.superuser.SuReceiver { +} \ No newline at end of file diff --git a/src/com/android/settings/development/RootAccessPreferenceController.java b/src/com/android/settings/development/RootAccessPreferenceController.java index c6c1d2b891e..04bd24ffc5f 100644 --- a/src/com/android/settings/development/RootAccessPreferenceController.java +++ b/src/com/android/settings/development/RootAccessPreferenceController.java @@ -108,6 +108,13 @@ public void onRootAccessDialogDismissed() { updatePreference(); } + public static boolean isRootForAppsEnabled() { + int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 0); + boolean daemonState = + SystemProperties.get("init.svc.su_daemon", "absent").equals("running"); + return daemonState && (value == 1 || value == 3); + } + private void writeRootAccessOptions(Object newValue) { String oldValue = SystemProperties.get(ROOT_ACCESS_PROPERTY, "0"); SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());