RikkaApps / Shizuku

Using system APIs directly with adb/root privileges from normal apps through a Java process started with app_process.
Apache License 2.0
8.96k stars 531 forks source link

Inquiry: how does shizuku connect to ADB? #502

Closed ComputerElite closed 3 weeks ago

ComputerElite commented 1 month ago

Hi, I want to create a own app which connected to the phone via adb so it can modify files in the /Android/data /Android/obb folders so it can backup apps and games and restore them. I couldn't figure out how to connect to adb via my C# xamarin app. So far I tried various nuget packages and invoking the linux adb binary but just got "access denied". Could someone give me insight on how it is done in shizuku? Thanks!

petermg commented 3 weeks ago

Hi, I want to create a own app which connected to the phone via adb so it can modify files in the /Android/data /Android/obb folders so it can backup apps and games and restore them. I couldn't figure out how to connect to adb via my C# xamarin app. So far I tried various nuget packages and invoking the linux adb binary but just got "access denied". Could someone give me insight on how it is done in shizuku? Thanks!

I have this exact feature in my app for the Quest here: https://github.com/petermg/TheOcularMigraineMCP

petermg commented 3 weeks ago

You have to use a wrapper that sets the home directory to a place it has write permissions. Here is the wrapper I use, which I got from XDA:

#!/system/bin/sh
# adb: wrapper to run adb from terminal
# osm0sis @ xda-developers

dir="$(cd "$(dirname "$0")"; pwd)";

export HOME=/sdcard;
export TMPDIR=/sdcard;
$dir/libadb.so "$@";

So this wrapper points to the binary "libadb.so" and when I want to run an adb command I just run this wrapper, which in turn runs the adb binary after settings the home and temp directories.

petermg commented 3 weeks ago

Also I learned a lot from this app: https://github.com/thedroidgeek/oculus-wireless-adb You can see it has a good adb binary here: https://github.com/thedroidgeek/oculus-wireless-adb/tree/main/app/src/main/jniLibs/arm64-v8a and it looks like it sets the home and temp directory environment variables here: https://github.com/thedroidgeek/oculus-wireless-adb/blob/main/app/src/main/java/tdg/oculuswirelessadb/MainActivity.kt I don't know kotlin but it seems that last file is doing something similar to what the wrapper does as you can see both the "HOME" and "TMPDIR" environment variables referenced in it in lines 240 and 241.

ComputerElite commented 3 weeks ago

You still have to pair with the phone over wireless adb, right?

petermg commented 3 weeks ago

Yes. I copied the method used in the other app I referenced in order to do that. I just looked at his code and saw what he was doing.

On Thu, Jun 13, 2024, 11:00 PM ComputerElite @.***> wrote:

You still have to pair with the phone over wireless adb, right?

— Reply to this email directly, view it on GitHub https://github.com/RikkaApps/Shizuku/issues/502#issuecomment-2167268545, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE6NOTNORX5RVIDCUKH6WE3ZHKBJDAVCNFSM6AAAAABH4IQDWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRXGI3DQNJUGU . You are receiving this because you commented.Message ID: @.***>

ComputerElite commented 3 weeks ago

Alright. Thank you very much for your help! Have a great day