OSDN Git Service

Update README.md
[android-x86/external-koush-Superuser.git] / README.md
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
10
11 ## Checking out the source
12
13 You'll need the "Widgets" dependency.
14
15 * $ mkdir /path/to/src
16 * $ cd /path/to/src
17 * $ git clone git://github.com/koush/Superuser
18 * $ git clone git://github.com/koush/Widgets
19
20 These repositories do not keep the actual projects in the top level directory.
21 This is because they contain tests, libs, and samples.
22
23 ## Eclipse
24
25 In Eclipse, import Widgets/Widgets and Superuser/Superuser. It should Just Work (TM).
26
27 ## Ant
28
29 Same old, same old.
30
31 * $ mkdir /path/to/src
32 * $ cd /path/to/src
33 * $ cd Superuser/Superuser
34 * $ ant release
35
36 Outputs:
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
41
42 ## Building the su binary
43
44 Make sure you have the android-ndk downloaded with the tool "ndk-build" in your path.
45
46 * $ cd /path/to/src/
47 * $ cd Superuser/Superuser
48 * $ ndk-build
49
50 The su binary will built into Superuser/Superuser/libs/armeabi/su.
51
52
53
54 ## Building with AOSP, CyanogenMod, etc
55
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.
59
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.
63
64 #### Repo Setup
65 Add the [local_manifest.xml](https://github.com/koush/Superuser/blob/master/local_manifest.xml) to your .repo/local_manifests
66
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:
72
73 ```
74 SUPERUSER_PACKAGE := com.mypackagename.superuser
75 ```
76
77 #### Advanced - Embedding Superuser into System Settings
78
79 You will not need to change the package name as described above. Superuser will simply go
80 into the com.android.settings package. To modify the Settings app, you will need this [patch](https://gist.github.com/koush/5059098):
81
82 ```diff
83
84 diff --git a/Android.mk b/Android.mk
85 index fe8ed2d..6dea5b0 100644
86 --- a/Android.mk
87 +++ b/Android.mk
88 @@ -13,6 +13,11 @@ LOCAL_CERTIFICATE := platform
89  
90  LOCAL_PROGUARD_FLAG_FILES := proguard.flags
91  
92 +LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
93 +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
94 +
95 +LOCAL_SRC_FILES += $(call all-java-files-under,../../../external/koush/Superuser/Superuser/src) $(call all-java-files-under,../../../external/koush/Widgets/Widgets/src)
96 +
97  include $(BUILD_PACKAGE)
98  
99  # Use the folloing include to make our test apk.
100 diff --git a/AndroidManifest.xml b/AndroidManifest.xml
101 index 72be71b..4171800 100644
102 --- a/AndroidManifest.xml
103 +++ b/AndroidManifest.xml
104 @@ -64,6 +64,29 @@
105      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
106      <uses-permission android:name="android.permission.SET_TIME" />
107  
108 +    <permission
109 +        android:name="android.permission.REQUEST_SUPERUSER"
110 +        android:protectionLevel="signature" />
111 +    <permission
112 +        android:name="android.permission.REPORT_SUPERUSER"
113 +        android:protectionLevel="signature" />
114 +
115 +    <permission-group
116 +        android:name="android.permission-group.SUPERUSER"
117 +        android:description="@string/superuser_description_more"
118 +        android:icon="@drawable/ic_action_permission"
119 +        android:label="@string/superuser"
120 +        android:priority="10000" />
121 +
122 +    <permission
123 +        android:name="android.permission.ACCESS_SUPERUSER"
124 +        android:description="@string/superuser_description_more"
125 +        android:icon="@drawable/ic_action_permission"
126 +        android:label="@string/superuser_description"
127 +        android:logo="@drawable/ic_action_permission"
128 +        android:permissionGroup="android.permission-group.SUPERUSER"
129 +        android:protectionLevel="dangerous" />
130 +
131      <application android:label="@string/settings_label"
132              android:icon="@mipmap/ic_launcher_settings"
133              android:taskAffinity=""
134 @@ -72,6 +95,41 @@
135              android:hardwareAccelerated="true"
136              android:supportsRtl="true">
137  
138 +        <!-- Only system/su can open this activity -->
139 +        <!-- This activity will then call the MultitaskSuRequestActivity to create a new task stack -->
140 +        <activity
141 +            android:name="com.koushikdutta.superuser.RequestActivity"
142 +            android:configChanges="keyboardHidden|orientation|screenSize"
143 +            android:label="@string/superuser"
144 +            android:launchMode="singleTask"
145 +            android:noHistory="true"
146 +            android:permission="android.permission.REQUEST_SUPERUSER"
147 +            android:theme="@style/RequestTheme" />
148 +        <!-- Only system/su can open this activity -->
149 +        <!-- This is activity is started in multiuser mode when the user invoking su -->
150 +        <!-- is not the device owner (user id 0). -->
151 +        <activity
152 +            android:name="com.koushikdutta.superuser.NotifyActivity"
153 +            android:configChanges="keyboardHidden|orientation|screenSize"
154 +            android:label="@string/superuser"
155 +            android:launchMode="singleTask"
156 +            android:noHistory="true"
157 +            android:permission="android.permission.REQUEST_SUPERUSER"
158 +            android:theme="@style/RequestTheme" />
159 +
160 +        <!-- Multiple instances of this activity can be running for multiple su requests -->
161 +        <activity
162 +            android:name="com.koushikdutta.superuser.MultitaskSuRequestActivity"
163 +            android:configChanges="keyboardHidden|orientation|screenSize"
164 +            android:exported="false"
165 +            android:label="@string/request"
166 +            android:theme="@style/RequestTheme" />
167 +
168 +        <receiver
169 +            android:name="com.koushikdutta.superuser.SuReceiver"
170 +            android:permission="android.permission.REPORT_SUPERUSER" />
171 +
172 +
173          <!-- Settings -->
174  
175          <activity android:name="Settings"
176 diff --git a/proguard.flags b/proguard.flags
177 index 0805d68..bc0a933 100644
178 --- a/proguard.flags
179 +++ b/proguard.flags
180 @@ -12,6 +12,7 @@
181  -keep class com.android.settings.accounts.*
182  -keep class com.android.settings.fuelgauge.*
183  -keep class com.android.settings.users.*
184 +-keep class com.koushikdutta.**
185  
186  # Keep click responders
187  -keepclassmembers class com.android.settings.inputmethod.UserDictionaryAddWordActivity {
188 diff --git a/res/xml/settings_headers.xml b/res/xml/settings_headers.xml
189 index 156d63f..6a903e3 100644
190 --- a/res/xml/settings_headers.xml
191 +++ b/res/xml/settings_headers.xml
192 @@ -215,6 +215,13 @@
193  
194      <!-- Date & Time -->
195      <header
196 +        android:id="@+id/superuser"
197 +        android:fragment="com.koushikdutta.superuser.PolicyNativeFragment"
198 +        android:icon="@drawable/ic_action_permission"
199 +        android:title="@string/superuser" />
200 +
201 +    <!-- Date & Time -->
202 +    <header
203          android:id="@+id/date_time_settings"
204          android:fragment="com.android.settings.DateTimeSettings"
205          android:icon="@drawable/ic_settings_date_time"
206
207 ```