-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHANGELOG: Added Root Provider Proxy to enqueue root commands
- Loading branch information
Showing
7 changed files
with
488 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/src/main/aidl/it/dhd/oxygencustomizer/IRootProviderProxy.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// IRootProviderProxy.aidl | ||
package it.dhd.oxygencustomizer; | ||
|
||
// Declare any non-default types here with import statements | ||
|
||
interface IRootProviderProxy { | ||
/** | ||
* Demonstrates some basic types that you can use as parameters | ||
* and return values in AIDL. | ||
*/ | ||
String[] runCommand(String command); | ||
} |
81 changes: 81 additions & 0 deletions
81
app/src/main/java/it/dhd/oxygencustomizer/services/RootProviderProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package it.dhd.oxygencustomizer.services; | ||
|
||
import android.app.Service; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.os.Binder; | ||
import android.os.IBinder; | ||
import android.os.RemoteException; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.topjohnwu.superuser.Shell; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import it.dhd.oxygencustomizer.IRootProviderProxy; | ||
import it.dhd.oxygencustomizer.R; | ||
|
||
public class RootProviderProxy extends Service { | ||
@Nullable | ||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return new RootPoviderProxyIPC(this); | ||
} | ||
|
||
class RootPoviderProxyIPC extends IRootProviderProxy.Stub | ||
{ | ||
/** @noinspection unused*/ | ||
String TAG = getClass().getSimpleName(); | ||
|
||
private final List<String> rootAllowedPacks; | ||
private final boolean rootGranted; | ||
|
||
private RootPoviderProxyIPC(Context context) | ||
{ | ||
try { | ||
Shell.setDefaultBuilder(Shell.Builder.create().setFlags(Shell.FLAG_MOUNT_MASTER)); | ||
} | ||
catch (Throwable ignored){} | ||
rootGranted = Shell.getShell().isRoot(); | ||
|
||
rootAllowedPacks = Arrays.asList(context.getResources().getStringArray(R.array.xposed_scope)); | ||
} | ||
|
||
/** @noinspection RedundantThrows*/ | ||
@Override | ||
public String[] runCommand(String command) throws RemoteException { | ||
try { | ||
ensureEnvironment(); | ||
|
||
List<String> result = Shell.cmd(command).exec().getOut(); | ||
return result.toArray(new String[0]); | ||
} | ||
catch (Throwable t) | ||
{ | ||
return new String[0]; | ||
} | ||
} | ||
|
||
private void ensureEnvironment() throws RemoteException { | ||
if(!rootGranted) | ||
{ | ||
throw new RemoteException("Root permission denied"); | ||
} | ||
|
||
ensureSecurity(Binder.getCallingUid()); | ||
} | ||
|
||
private void ensureSecurity(int uid) throws RemoteException { | ||
for (String packageName : getPackageManager().getPackagesForUid(uid)) { | ||
if(rootAllowedPacks.contains(packageName)) | ||
return; | ||
} | ||
throw new RemoteException("You do know you're not supposed to use this service. So..."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.