Some cleanup touches
@ -5,11 +5,9 @@
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:icon="@android:drawable/sym_def_app_icon"
|
||||
android:label="LibSUExample"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
@ -20,4 +18,4 @@
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
@ -46,9 +46,9 @@ public class MainActivity extends Activity {
|
||||
public static final String TAG = "EXAMPLE";
|
||||
|
||||
static {
|
||||
// Configuration
|
||||
Shell.Config.setFlags(Shell.FLAG_REDIRECT_STDERR);
|
||||
Shell.Config.verboseLogging(BuildConfig.DEBUG);
|
||||
// BusyBoxInstaller should come first!
|
||||
Shell.Config.setInitializers(BusyBoxInstaller.class, ExampleInitializer.class);
|
||||
}
|
||||
|
||||
@ -57,32 +57,39 @@ public class MainActivity extends Activity {
|
||||
|
||||
private ITestService testIPC;
|
||||
private RootConnection conn = new RootConnection();
|
||||
private boolean queuedTest = false;
|
||||
private boolean svcTestQueued = false;
|
||||
|
||||
// Demonstrate Shell.Initializer
|
||||
static class ExampleInitializer extends Shell.Initializer {
|
||||
|
||||
@Override
|
||||
public boolean onInit(@NonNull Context context, @NonNull Shell shell) {
|
||||
Log.d(TAG, "onInit");
|
||||
// Load our init script
|
||||
shell.newJob().add(context.getResources().openRawResource(R.raw.bashrc)).exec();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Demonstrate RootService (daemon mode)
|
||||
// All code in this class (including the ITestService stub) will run in the root process.
|
||||
static class ExampleService extends RootService {
|
||||
|
||||
static {
|
||||
// Only load in root process
|
||||
// Only load the library when this class is loaded in a root process.
|
||||
// The classloader will load this class (and call this static block) in the non-root
|
||||
// process because we accessed it when constructing the Intent to send.
|
||||
// Add this check so we don't unnecessarily load native code that'll never be used.
|
||||
if (Process.myUid() == 0)
|
||||
System.loadLibrary("native-lib");
|
||||
}
|
||||
|
||||
// Demonstrate we can actually run native code via JNI with RootServices
|
||||
native int nativeGetUid();
|
||||
native String nativeReadFile(String file);
|
||||
|
||||
@Override
|
||||
public void onRebind(@NonNull Intent intent) {
|
||||
// This callback will be called when we are reusing a previously started root process
|
||||
Log.d(TAG, "onRebind, daemon process reused");
|
||||
}
|
||||
|
||||
@ -101,6 +108,8 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public String readCmdline() {
|
||||
// Normally we cannot read /proc/cmdline without root
|
||||
// Any result means we are running as root
|
||||
return nativeReadFile("/proc/cmdline");
|
||||
}
|
||||
};
|
||||
@ -108,8 +117,8 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public boolean onUnbind(@NonNull Intent intent) {
|
||||
// Enable daemon mode
|
||||
Log.d(TAG, "onUnbind, client process unbound");
|
||||
// We return true here to tell libsu that we want this service to run as a daemon
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -119,8 +128,8 @@ public class MainActivity extends Activity {
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
Log.d(TAG, "onServiceConnected");
|
||||
testIPC = ITestService.Stub.asInterface(service);
|
||||
if (queuedTest) {
|
||||
queuedTest = false;
|
||||
if (svcTestQueued) {
|
||||
svcTestQueued = false;
|
||||
testService();
|
||||
}
|
||||
}
|
||||
@ -156,7 +165,7 @@ public class MainActivity extends Activity {
|
||||
|
||||
binding.testSvc.setOnClickListener(v -> {
|
||||
if (testIPC == null) {
|
||||
queuedTest = true;
|
||||
svcTestQueued = true;
|
||||
Intent intent = new Intent(this, ExampleService.class);
|
||||
RootService.bind(intent, conn);
|
||||
return;
|
||||
@ -166,36 +175,38 @@ public class MainActivity extends Activity {
|
||||
|
||||
binding.stopSvc.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(this, ExampleService.class);
|
||||
// Use stop here instead of unbind because ExampleService is running as a daemon.
|
||||
// To verify whether the daemon actually works, kill the app and try to test the
|
||||
// service again. You should get the same PID as last time (as it was re-using the
|
||||
// previous daemon process), and in ExampleService onRebind should be called.
|
||||
// Note: re-running the app in Android Studio is not the same as kill + relaunch,
|
||||
// the root service will kill itself when it detects the client APK has updated.
|
||||
RootService.stop(intent);
|
||||
});
|
||||
|
||||
// Closing a shell is always synchronous
|
||||
binding.closeShell.setOnClickListener(v -> {
|
||||
try {
|
||||
Shell shell = Shell.getCachedShell();
|
||||
if (shell != null)
|
||||
shell.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Log.e(TAG, "Error when closing shell", e);
|
||||
}
|
||||
});
|
||||
|
||||
// Load a script from raw resources synchronously
|
||||
binding.syncScript.setOnClickListener(v ->
|
||||
Shell.sh(getResources().openRawResource(R.raw.info)).to(consoleList).exec());
|
||||
// test_sync is defined in bashrc, loaded in ExampleInitializer
|
||||
binding.testSync.setOnClickListener(v ->
|
||||
Shell.sh("test_sync").to(consoleList).exec());
|
||||
|
||||
// Load a script from raw resources asynchronously
|
||||
binding.asyncScript.setOnClickListener(v ->
|
||||
Shell.sh(getResources().openRawResource(R.raw.count)).to(consoleList).submit());
|
||||
// test_async is defined in bashrc, loaded in ExampleInitializer
|
||||
binding.testAsync.setOnClickListener(v ->
|
||||
Shell.sh("test_async").to(consoleList).submit());
|
||||
|
||||
binding.clear.setOnClickListener(v -> consoleList.clear());
|
||||
|
||||
/* Create a CallbackList to update the UI with Shell output
|
||||
* Here I demonstrate 2 ways to implement a CallbackList
|
||||
*
|
||||
* Both ContainerCallbackList or AppendCallbackList will have
|
||||
* the same behavior.
|
||||
*/
|
||||
// Create a CallbackList to update the UI with Shell output
|
||||
// Here I demonstrate 2 ways to use a CallbackList
|
||||
// Both ContainerCallbackList or AppendCallbackList have the same behavior.
|
||||
consoleList = new AppendCallbackList();
|
||||
// consoleList = new ContainerCallbackList(new ArrayList<>());
|
||||
}
|
||||
@ -223,17 +234,17 @@ public class MainActivity extends Activity {
|
||||
* This class stores all outputs to the provided List<String> every time
|
||||
* a new output is created.
|
||||
*
|
||||
* To make it behave exactly the same as AppendCallbackList, I joined
|
||||
* all output together with newline and set the whole TextView with the result.
|
||||
* To make it behave exactly the same as AppendCallbackList, all output was joined
|
||||
* together with each new line added and the whole TextView is updated with the result.
|
||||
* It doesn't make sense to do this in this scenario since we do not actually
|
||||
* need to store the output. However, it is here to demonstrate that CallbackList
|
||||
* can also be used to store outputs and behaves just like normal List<String> if
|
||||
* provided a container for storage.
|
||||
* provided a backing list for storage.
|
||||
*/
|
||||
private class ContainerCallbackList extends CallbackList<String> {
|
||||
|
||||
private ContainerCallbackList(List<String> l) {
|
||||
super(l);
|
||||
private ContainerCallbackList(List<String> base) {
|
||||
super(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,34 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
@ -1,170 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
@ -72,7 +72,7 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/sync_script"
|
||||
android:id="@+id/test_sync"
|
||||
style="?android:borderlessButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@ -80,7 +80,7 @@
|
||||
android:text="Test sync" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/async_script"
|
||||
android:id="@+id/test_async"
|
||||
style="?android:borderlessButtonStyle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 15 KiB |
@ -22,7 +22,15 @@ api_level_arch_detect() {
|
||||
if [ "$ABILONG" = "x86_64" ]; then ARCH=x64; IS64BIT=true; fi;
|
||||
}
|
||||
|
||||
api_level_arch_detect
|
||||
test_sync() {
|
||||
api_level_arch_detect
|
||||
echo "Device API: $API"
|
||||
echo "Device ABI: $ARCH"
|
||||
}
|
||||
|
||||
echo "Device API: $API"
|
||||
echo "Device ABI: $ARCH"
|
||||
test_async() {
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
echo ${i}
|
||||
sleep 1
|
||||
done
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#!/system/bin/sh
|
||||
|
||||
for i in 0 1 2 3 4 5 6 7 8 9; do
|
||||
echo ${i}
|
||||
sleep 1
|
||||
done
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">LibSUExample</string>
|
||||
</resources>
|
@ -1,8 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -49,7 +49,7 @@ import java.util.Locale;
|
||||
* These tools are available on modern Android versions with toybox, however for consistent results
|
||||
* using {@code busybox} would be desirable. Some operations could have oddities
|
||||
* without busybox due to the lack of tools or different behavior of the tools,
|
||||
* check the method descriptions for more info before using them.
|
||||
* check the method descriptions for more bashrc before using them.
|
||||
* <p>
|
||||
* There are also handy factory methods {@code SuFile.open(...)} for obtaining {@link File}
|
||||
* instances. These factory methods will return a normal {@link File} instance if the underlying
|
||||
|
@ -97,7 +97,7 @@ class IPCServer extends IRootIPC.Stub implements IBinder.DeathRecipient {
|
||||
}
|
||||
|
||||
// Monitor ANY modify event to the APK
|
||||
AppObserver createObserver() {
|
||||
private AppObserver createObserver() {
|
||||
File apk = new File(service.getPackageCodePath());
|
||||
if (apk.getParent().equals("/data/app")) {
|
||||
// No subfolder, directly monitor the APK itself
|
||||
|
@ -59,7 +59,7 @@ import java.util.concurrent.ExecutorService;
|
||||
* Unlike normal services, RootService does not have an API similar to
|
||||
* {@link Context#startService(Intent)} because root services are strictly bound only.
|
||||
* Due to this reason, the APIs to forcefully stop the service are slightly different from normal
|
||||
* services. Please refer to {@link #stop(Intent)} and {@link #stopSelf()} for more info.
|
||||
* services. Please refer to {@link #stop(Intent)} and {@link #stopSelf()} for more bashrc.
|
||||
* Also, unlike normal services, whenever you receive
|
||||
* {@link ServiceConnection#onServiceDisconnected(ComponentName)}, which means either
|
||||
* <ul>
|
||||
|