OSDN Git Service

Settings: Add Superuser entry
authorKoushik Dutta <koushd@gmail.com>
Thu, 28 Feb 2013 22:49:24 +0000 (14:49 -0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 5 May 2016 10:08:45 +0000 (18:08 +0800)
Squashed commit of the following:

Author: Koushik Dutta <koushd@gmail.com>
Switch to new Superuser
Change-Id: I9d91392ad6fbc9953d19059ab59b91d214c00e0c

Author: Danny Baumann <dannybaumann@web.de>
Hide Superuser entry if root access for apps is disabled.
Change-Id: Ibb77ba5a0fccf22564a26b8b1e13f7762c65718e

Author: Ricardo Cerqueira <cyanogenmod@cerqueira.org>
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

Android.mk
AndroidManifest.xml
proguard.flags
res/xml/dashboard_categories.xml
src/com/android/settings/DevelopmentSettings.java
src/com/android/settings/SettingsActivity.java
src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java [new file with mode: 0644]
src/com/android/settings/cyanogenmod/superuser/NotifyActivity.java [new file with mode: 0644]
src/com/android/settings/cyanogenmod/superuser/PolicyNativeFragment.java [new file with mode: 0644]
src/com/android/settings/cyanogenmod/superuser/RequestActivity.java [new file with mode: 0644]
src/com/android/settings/cyanogenmod/superuser/SuReceiver.java [new file with mode: 0644]

index 7043ad4..c2c460c 100644 (file)
@@ -23,6 +23,12 @@ ifneq ($(INCREMENTAL_BUILDS),)
     LOCAL_JACK_ENABLED := incremental
 endif
 
+LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
+LOCAL_AAPT_FLAGS += --extra-packages com.koushikdutta.superuser:com.koushikdutta.widgets --auto-add-overlay
+
+LOCAL_SRC_FILES += $(call all-java-files-under,../../../external/koush/Superuser/Superuser/src) $(call all-java-files-under,../../../external/koush/Widgets/Widgets/src)
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res $(LOCAL_PATH)/../../../external/koush/Widgets/Widgets/res $(LOCAL_PATH)/../../../external/koush/Superuser/Superuser/res
+
 include frameworks/opt/setupwizard/navigationbar/common.mk
 include frameworks/opt/setupwizard/library/common.mk
 include frameworks/base/packages/SettingsLib/common.mk
index 76acedd..a920e53 100644 (file)
     <uses-permission android:name="android.permission.CHANGE_APP_IDLE_STATE" />
     <uses-permission android:name="android.permission.PEERS_MAC_ADDRESS"/>
 
+    <permission
+        android:name="android.permission.REQUEST_SUPERUSER"
+        android:protectionLevel="signature" />
+
+    <permission
+        android:name="android.permission.REPORT_SUPERUSER"
+        android:protectionLevel="signature" />
+
+    <permission-group
+        android:name="android.permission-group.SUPERUSER"
+        android:description="@string/superuser_description_more"
+        android:icon="@drawable/ic_action_permission"
+        android:label="@string/superuser"
+        android:priority="10000" />
+
+    <permission
+        android:name="android.permission.ACCESS_SUPERUSER"
+        android:description="@string/superuser_description_more"
+        android:icon="@drawable/ic_action_permission"
+        android:label="@string/superuser_description"
+        android:logo="@drawable/ic_action_permission"
+        android:permissionGroup="android.permission-group.SUPERUSER"
+        android:protectionLevel="dangerous" />
+
     <application android:label="@string/settings_label"
             android:icon="@mipmap/ic_launcher_settings"
             android:taskAffinity=""
             android:allowBackup="false"
             android:usesCleartextTraffic="true">
 
+        <!-- Only system/su can open this activity -->
+        <!-- This activity will then call the MultitaskSuRequestActivity to create a new task stack -->
+        <activity
+            android:name=".cyanogenmod.superuser.RequestActivity"
+            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:label="@string/superuser"
+            android:launchMode="singleTask"
+            android:excludeFromRecents="true"
+            android:permission="android.permission.REQUEST_SUPERUSER"
+            android:process=":superuser"
+            android:taskAffinity="com.android.settings.superuser"
+            android:theme="@style/RequestThemeDark" />
+        <!-- Only system/su can open this activity -->
+        <!-- This is activity is started in multiuser mode when the user invoking su -->
+        <!-- is not the device owner (user id 0). -->
+        <activity
+            android:name=".cyanogenmod.superuser.NotifyActivity"
+            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:label="@string/superuser"
+            android:launchMode="singleTask"
+            android:excludeFromRecents="true"
+            android:permission="android.permission.REQUEST_SUPERUSER"
+            android:process=":superuser"
+            android:taskAffinity="com.android.settings.superuser"
+            android:theme="@style/RequestThemeDark" />
+
+        <!-- Multiple instances of this activity can be running for multiple su requests -->
+        <activity
+            android:name=".cyanogenmod.superuser.MultitaskSuRequestActivity"
+            android:configChanges="keyboardHidden|orientation|screenSize"
+            android:excludeFromRecents="true"
+            android:exported="false"
+            android:label="@string/request"
+            android:process=":superuser"
+            android:taskAffinity="com.android.settings.superuser"
+            android:theme="@style/RequestThemeDark" />
+
+        <receiver
+            android:name=".cyanogenmod.superuser.SuReceiver"
+            android:permission="android.permission.REPORT_SUPERUSER" />
+
         <!-- Settings -->
 
         <activity android:name="Settings"
index 578ff4d..841bc88 100644 (file)
@@ -16,6 +16,8 @@
 -keep class com.android.settings.users.*
 -keep class com.android.settings.nfc.*
 -keep class com.android.settings.notification.*
+-keep class com.koushikdutta.**
+-keep class com.android.settings.cyanogenmod.superuser.**
 
 # Keep click responders
 -keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity {
index f46a820..d8d6212 100644 (file)
                 android:icon="@drawable/ic_settings_print"
                 />
 
+        <!-- Superuser -->
+        <dashboard-tile
+                android:id="@+id/superuser_settings"
+                android:title="@string/superuser"
+                android:fragment="com.android.settings.cyanogenmod.superuser.PolicyNativeFragment"
+                android:icon="@drawable/ic_action_permission"
+                />
+
         <!-- Development -->
         <dashboard-tile
                 android:id="@+id/development_settings"
index 3372e51..31385d5 100644 (file)
@@ -691,6 +691,13 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
                 .getStringArray(R.array.root_access_entries)[Integer.valueOf(value)]);
     }
 
+    /* package */ static boolean isRootForAppsEnabled() {
+        int value = SystemProperties.getInt(ROOT_ACCESS_PROPERTY, 1);
+        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, "1");
         SystemProperties.set(ROOT_ACCESS_PROPERTY, newValue.toString());
index 01b027a..991fcae 100644 (file)
@@ -1296,6 +1296,10 @@ public class SettingsActivity extends Activity
                     if (!hasPrintingSupport) {
                         removeTile = true;
                     }
+                } else if (id == R.id.superuser_settings) {
+                    if (!DevelopmentSettings.isRootForAppsEnabled()) {
+                        removeTile = true;
+                    }
                 } else if (id == R.id.development_settings) {
                     if (!showDev || um.hasUserRestriction(
                             UserManager.DISALLOW_DEBUGGING_FEATURES)) {
diff --git a/src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java b/src/com/android/settings/cyanogenmod/superuser/MultitaskSuRequestActivity.java
new file mode 100644 (file)
index 0000000..0103076
--- /dev/null
@@ -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 (file)
index 0000000..23aa6a7
--- /dev/null
@@ -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 (file)
index 0000000..1c74543
--- /dev/null
@@ -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 (file)
index 0000000..e6deca4
--- /dev/null
@@ -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 (file)
index 0000000..c4f9174
--- /dev/null
@@ -0,0 +1,4 @@
+package com.android.settings.cyanogenmod.superuser;
+
+public class SuReceiver extends com.koushikdutta.superuser.SuReceiver {
+}
\ No newline at end of file