Is there an API to enable an Xposed module in Android from the shell (using ADB) and not through the device's UI.
This is constantly a bother for automation, when we need to install our module on a clean test emulator. This is currently the only step that we are required to do manually.
A simple google search + overview of the XPosed documentation didn't yield anything worth while.
As you already know, this is approach disfavored for end-users, but for testing, you have to echo the path of the apk to Xposed config file:
Pre-Lollipop:
adb shell "echo '/data/app/com.xyz.example-1.apk' >> /data/data/de.robv.android.xposed.installer/conf/modules.list"
Lollipop and newer:
adb shell "echo '/data/app/com.xyz.example-1 OR -2/base.apk' >> /data/data/de.robv.android.xposed.installer/conf/modules.list"
For these commands you need to have your emulator support root adb, type
adb root
into the command line. If your emulator doesn't support rooted/insecure adbd, you can also add a su -c before the echo to get root rights.
EDIT: the easiest way to find which number you have to use in directory name would be what #brendan suggested.
This worked for me on KitKat:
(1) Update shared_pres xml file:
If you look at the /data/data/de.robv.android.xposed.installer/shared_prefs/ directory. You will see an enabled_modules.xml file.
In my case I was only working with a single module so I would just overwrite the file. If you have several modules you may wish to do an edit/update.
I would have a local enabled_modules.xml file that looked like this:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<map>
<int name="com.companyname.xposedmodule" value="1" />
</map>
...where com.companyname.xposedmodule is the name of your module.
Then post build you can execute a simple:
adb push enabled_modules.xml /data/data/de.robv.android.xposed.installer/shared_prefs/
(2) Update modules.list config file:
You also need to do what #Maxr1998 suggested. I scripted it this way:
adb shell "[ -f /data/app/com.companyname.xposedmodule-1.apk ] && echo '/data/app/com.companyname.xposedmodule-1.apk' >> /data/data/de.robv.android.xposed.installer/conf/modules.list
adb shell "[ -f /data/app/com.companyname.xposedmodule-2.apk ] && echo '/data/app/com.companyname.xposedmodule-2.apk' >> /data/data/de.robv.android.xposed.installer/conf/modules.list
Related
Basically, I dump all data into the directory 'sdcard/2019-07-xx-xx and there are subdirectories in 2019-07-xx-xx. The Folder is named after the timestamp when dumping data, now I run the command:
adb pull '/sdcard/2019-07*'
but it prompted:
adb: error: failed to stat remote object 'sdcard/2019-07*': No such file or directory
who can help me out?
Example:
for days in 0{1..9} 1{0..9} 2{0..9} 3{0..1}; do
adb shell echo "\$EXTERNAL_STORAGE/2019-07-$days/"
done
Gives us below output:
/sdcard/2019-07-01/
/sdcard/2019-07-02/
/sdcard/2019-07-03/
/sdcard/2019-07-04/
/sdcard/2019-07-05/
......
Final: You can copy and paste
- don't forget to change source_path and dates if needed - Notice the trial slash:
for days in 0{1..9} 1{0..9} 2{0..9} 3{0..1}; do
adb pull "\$EXTERNAL_STORAGE/2019-07-$days/" ~/source_path
done
According to documentation "adb pull" command can pull file or directory from your device. There is no support for a wildcard.
But you can use xargs to accomplish this. Just check post
I have just built Libgit2 (v0.20.0) for Android (target SDK version 18, debugging on a rooted device running Cyanogenmod 10.1.2, Android 4.2.2) and a simple function like getting the version number of Libgit2 works fine through the JNI. But when I use the git_clone function it stops right after the objects/info folder is created and returns this error:
Error -1 cloning repository - Failed to set permissions on '/storage/sdcard0/it/ptt/.git/objects/info': Operation not permitted
I have given the application the WRITE_EXTERNAL_STORAGE permission but I guess it still can't chmod unless owner of the file. When I use adb shell to check out the permission mode of the info folder I get:
d---rwxr-x system sdcard_rw 2014-05-15 09:31 info
And by using pwd.h functions I get the username that the c code (that is calling git_clone) is under to be u0_a92. How am I suppose to get pass this I suppose very Android related issue? Is there a simple way to stop Libgit2 from calling p_chmod or can I give it permissions to do so?
I ended up defining p_chmod as a method always returning true to get passed the error. In the bash script I use to build libgit2 I inserted the following lines that leaves the source files in an unmodified condition after building for android:
LIBGIT2_POSIX_PATH="$LIBGIT2_SOURCE_PATH/src/posix.h"
LIBGIT2_POSIX_BACKUP_PATH="$LIBGIT2_SOURCE_PATH/src/posix_original.h"
printf "#include \"always_success.h\"\nint always_success() { return 0; }" > "$LIBGIT2_SOURCE_PATH/src/always_success.c"
printf "int always_success();" > "$LIBGIT2_SOURCE_PATH/src/always_success.h"
cp $LIBGIT2_POSIX_PATH "$LIBGIT2_POSIX_BACKUP_PATH"
sed -i "s/^#define\sp_chmod(p, m).*$/#include \"always_success.h\"\n#define p_chmod(p, m) always_success()\nextern int always_success();\n/" $LIBGIT2_POSIX_PATH
# run the build process with cmake ...
# restore chmod manipulated source header
mv $LIBGIT2_POSIX_BACKUP_PATH $LIBGIT2_POSIX_PATH
There is probably a cleaner way to solve this but at least now I dont get that error anymore. Thanks to Carlos for his help!
UPDATE
Running adb shell mount | grep sdcard I could see that the sdcard which I am trying to clone the repository into uses the vfat file system which according to this forum thread doesn't support unix-style permissions.
I am trying to run the following simple shell-script on android:
#!/system/bin/sh
echo "Hello World!"
I named the file "test", and place it in "/system/bin/" .. I change the permission to 755 and the group to shell ..
now when I try to run the script: test, it shows:
sh: test: No such file or directory
I can see the file in there and when I run bash test or sh test it works ..
what is the problem ?
Do not call it “test” because that’s a shell built-in command. Shells will call internal builtins in preference over external utilities.
Rename it to /system/bin/testx and call it as “testx” and see whether that works.
Other common pitfalls on android: 「#!/system/bin/sh」 and most directories are mounted “noexec”. But both of these do not apply to your script if you put it to /system/bin/ anyway.
I would like to use the apitrace project on android. I followed the instructions from the readme file.
But get no trace where created.
I run this command
adb shell TRACE_FILE=/data/test.trace LD_PRELOAD=/data/egltrace.so am start -n APP_NAME
How can I make it work?
I tried following the instructions in Dalvik.markdown of the original distribution of apitrace, but without success.
The instructions say to set two properties: wrap._process_name_ and debug.apitrace.procname. The former has to be set, according to those instructions, to LD_PRELOAD=/data/egltrace.so. When launching the application I still wouldn't get any trace generated nor any apitrace-related message in the logcat.
I had more success by putting the LD_PRELOAD instruction in a script and using that as the wrapper. This is the script that I use, called /data/apitrace.sh:
LD_PRELOAD=/data/egltrace.so exec $#
You can also set the TRACE_FILE environment variable to specify the path to which the trace file should be written to. Otherwise it will be _/data/app_process.trace_. For example:
TRACE_FILE=/data/apitraces/mytrace.trace LD_PRELOAD=/data/egltrace.so exec $#
I believe apitrace takes care of adding numbers to the filename to prevent overwriting existing ones. So you'll have mytrace.trace, mytrace.1.trace, and so on.
So with this script in place I set the properties like so:
adb shell setprop wrap._process_name_ /data/apitrace.sh
adb shell setprop debug.apitrace.procname _process_name_
And then I launch the application. I see in the logcat something like the following:
I/dalvikvm( 5980): Exec: /system/bin/sh -c /data/apitrace.sh /system/bin/app_process /system/bin --application '--nice-name=_process_name_' com.android.internal.os.WrapperInit 25 17 'android.app.ActivityThread'
D/apitrace( 5991): apitrace: loaded
D/apitrace( 5991): apitrace[5991]: enabled for _process_name_
D/apitrace( 5991): apitrace: tracing to /data/app_process.trace
I'm using CyanogenMod 10.1.3, which is based on Android 4.2.2.
Is there a way to list all the activities of a particular .apk file from the shell? I found this post which describes how to list all the activities in an apk but it is not for the shell.
If you can pull out the apk file to your own machine, you can use the aapt command in the Android SDK
aapt dump xmltree <apk-file> AndroidManifest.xml
The format is a bit perplexing at first, but all the info is there.
The solution from #Albin will print all the elements in AndroidManifest.xml, we need to filter the output. Here is another solution only print activities as the question ask.
aapt list -a /path/to/the/apk | sed -n '/ activity /{:loop n;s/^.*android:name.*="\([^"]\{1,\}\)".*/\1/;T loop;p;t}'