1 ## Why another Superuser?
2 * Superuser should be open source. It's the gateway to root on your device. It must be open for independent security analysis. Obscurity (closed source) is not security.
3 * Superuser should be NDK buildable. No internal Android references.
4 * Superuser should also be AOSP buildable for those that want to embed it in their ROM.
5 * Superuser should also be AOSP _embeddable_, meaning a ROM can easily embed it into their Settings app.
6 * Maintenance and updates on both the market and source repositories should be timely.
7 * I want to be able to point users of my app to a Superuser solution that I wrote, that I know works, and that I can fix if something is wrong. Yes, this is selfish: Carbon does not work with some versions of Chainsdd's Superuser. SuperSU works great, but I am not comfortable pointing a user to a closed source su implementation.
8 * Handle multiuser (4.2+) properly
9 * Handle concurrent su requests properly
11 ## Checking out the source
13 You'll need the "Widgets" dependency.
15 * $ mkdir /path/to/src
17 * $ git clone git://github.com/koush/Superuser
18 * $ git clone git://github.com/koush/Widgets
20 These repositories do not keep the actual projects in the top level directory.
21 This is because they contain tests, libs, and samples.
25 In Eclipse, import Widgets/Widgets and Superuser/Superuser. It should Just Work (TM).
31 * $ mkdir /path/to/src
33 * $ cd Superuser/Superuser
37 * bin/update.zip - Recovery installable zip
38 * bin/Superuser.apk - Superuser Android app
39 * libs/armeabi/su - ARM su binary
40 * libs/x86/su - x86 su binary
42 ## Building the su binary
44 Make sure you have the android-ndk downloaded with the tool "ndk-build" in your path.
47 * $ cd Superuser/Superuser
50 The su binary will built into Superuser/Superuser/libs/armeabi/su.
54 ## Building with AOSP, CyanogenMod, etc
56 ROM developers are welcome to distribute the official Superuser APK and binary that I publish. That will
57 allow them to receive updates with Google Play. However, you can also build Superuser as part of your
58 build, if you choose to.
60 There are two ways to include Superuser in your build. The easiest is to build the APK as a separate app.
61 To do that, simply add the local_manifest.xml as described below. The second way is by embedding it
62 into the native Android System Settings.
65 Add the [local_manifest.xml](https://github.com/koush/Superuser/blob/master/local_manifest.xml) to your .repo/local_manifests
67 #### Configuring the Package Name
68 The Superuser distributed on Google Play is in the package name com.koushikdutta.superuser.
69 To prevent conflicts with the Play store version, the build process changes the package
70 name to com.thirdparty.superuser. You can configure this value by setting the following
71 in your vendor makefile or BoardConfig:
74 SUPERUSER_PACKAGE := com.mypackagename.superuser
77 #### Advanced - Embedding Superuser into System Settings
79 You will not need to change the package name as described above. Superuser will simply go
80 into the com.android.settings package.
82 First, in a product makefile (like vendor/cm/config/common.mk), specify the following:
85 SUPERUSER_EMBEDDED := true
88 To modify the Settings app, you will need this [patch](https://gist.github.com/koush/5059098).
89 The patch simply references the sources checked out to external/koush and makes changes
90 to XML preference files and the AndroidManifest.xml. It is a very minimal change:
94 diff --git a/Android.mk b/Android.mk
95 index fe8ed2d..6dea5b0 100644
98 @@ -13,6 +13,11 @@ LOCAL_CERTIFICATE := platform
100 LOCAL_PROGUARD_FLAG_FILES := proguard.flags
102 +LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
103 +LOCAL_AAPT_FLAGS := --extra-packages com.koushikdutta.superuser:com.koushikdutta.widgets -S $(LOCAL_PATH)/../../../external/koush/Widgets/Widgets/res -S $(LOCAL_PATH)/../../../external/koush/Superuser/Superuser/res --auto-add-overlay
105 +LOCAL_SRC_FILES += $(call all-java-files-under,../../../external/koush/Superuser/Superuser/src) $(call all-java-files-under,../../../external/koush/Widgets/Widgets/src)
107 include $(BUILD_PACKAGE)
109 # Use the folloing include to make our test apk.
110 diff --git a/AndroidManifest.xml b/AndroidManifest.xml
111 index 72be71b..4171800 100644
112 --- a/AndroidManifest.xml
113 +++ b/AndroidManifest.xml
115 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
116 <uses-permission android:name="android.permission.SET_TIME" />
119 + android:name="android.permission.REQUEST_SUPERUSER"
120 + android:protectionLevel="signature" />
122 + android:name="android.permission.REPORT_SUPERUSER"
123 + android:protectionLevel="signature" />
126 + android:name="android.permission-group.SUPERUSER"
127 + android:description="@string/superuser_description_more"
128 + android:icon="@drawable/ic_action_permission"
129 + android:label="@string/superuser"
130 + android:priority="10000" />
133 + android:name="android.permission.ACCESS_SUPERUSER"
134 + android:description="@string/superuser_description_more"
135 + android:icon="@drawable/ic_action_permission"
136 + android:label="@string/superuser_description"
137 + android:logo="@drawable/ic_action_permission"
138 + android:permissionGroup="android.permission-group.SUPERUSER"
139 + android:protectionLevel="dangerous" />
141 <application android:label="@string/settings_label"
142 android:icon="@mipmap/ic_launcher_settings"
143 android:taskAffinity=""
145 android:hardwareAccelerated="true"
146 android:supportsRtl="true">
148 + <!-- Only system/su can open this activity -->
149 + <!-- This activity will then call the MultitaskSuRequestActivity to create a new task stack -->
151 + android:name="com.koushikdutta.superuser.RequestActivity"
152 + android:configChanges="keyboardHidden|orientation|screenSize"
153 + android:label="@string/superuser"
154 + android:launchMode="singleTask"
155 + android:noHistory="true"
156 + android:permission="android.permission.REQUEST_SUPERUSER"
157 + android:theme="@style/RequestTheme" />
158 + <!-- Only system/su can open this activity -->
159 + <!-- This is activity is started in multiuser mode when the user invoking su -->
160 + <!-- is not the device owner (user id 0). -->
162 + android:name="com.koushikdutta.superuser.NotifyActivity"
163 + android:configChanges="keyboardHidden|orientation|screenSize"
164 + android:label="@string/superuser"
165 + android:launchMode="singleTask"
166 + android:noHistory="true"
167 + android:permission="android.permission.REQUEST_SUPERUSER"
168 + android:theme="@style/RequestTheme" />
170 + <!-- Multiple instances of this activity can be running for multiple su requests -->
172 + android:name="com.koushikdutta.superuser.MultitaskSuRequestActivity"
173 + android:configChanges="keyboardHidden|orientation|screenSize"
174 + android:exported="false"
175 + android:label="@string/request"
176 + android:theme="@style/RequestTheme" />
179 + android:name="com.koushikdutta.superuser.SuReceiver"
180 + android:permission="android.permission.REPORT_SUPERUSER" />
185 <activity android:name="Settings"
186 diff --git a/proguard.flags b/proguard.flags
187 index 0805d68..bc0a933 100644
191 -keep class com.android.settings.accounts.*
192 -keep class com.android.settings.fuelgauge.*
193 -keep class com.android.settings.users.*
194 +-keep class com.koushikdutta.**
196 # Keep click responders
197 -keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity {
198 diff --git a/res/xml/settings_headers.xml b/res/xml/settings_headers.xml
199 index 156d63f..63b7077 100644
200 --- a/res/xml/settings_headers.xml
201 +++ b/res/xml/settings_headers.xml
203 <header android:id="@+id/system_section"
204 android:title="@string/header_category_system" />
208 + android:id="@+id/superuser"
209 + android:fragment="com.koushikdutta.superuser.PolicyNativeFragment"
210 + android:icon="@drawable/ic_action_permission"
211 + android:title="@string/superuser" />
215 android:id="@+id/date_time_settings"