Konubinix' opinionated web of thoughts

Android

Fleeting

tools

Using the tooling installed by buildozer, otherwise:

install the sdk

It can be downloaded from https://developer.android.com/studio (go to the bottom of the page)

https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip

I prefer using nixos and a custom flake to download what I need automatically.

missing the avd folder

the avdmanager respects the XDG_CONFIG HOME but the emulator does not. This leads to avdmanager create putting avds in some path and emulator not finding it.

test graphical interfaces

Permission Denial

java.lang.SecurityException: Permission Denial: starting Intent The full error description usually looks like ‘java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.mypackage/.myactivity.MainActivity launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } } from null (pid=11366, uid=2000) not exported from uid 10191. Such error might be the indication of the fact that the combination of application package and activity name, which has been passed to Appium as appPackage/appActivity (or auto detected implicitly), is not the correct one to start the application under test

https://github.com/appium/appium/blob/1.x/docs/en/writing-running-appium/android/activity-startup.md

appium

appium driver install uiautomator2

http://appium.io/docs/en/2.4/quickstart/uiauto2-driver/#prepare-the-device

npm i -g appium

http://appium.io/docs/en/2.4/quickstart/install/

ANDROID_SERIAL=emulator-5554 appium
pip install Appium-Python-Client
speed up the starting
additional_options = {
    "skipDeviceInitialization": not self.first_time,
    "skipServerInstallation": not self.first_time,
    "disableWindowAnimation": self.first_time,
}

It still takes some time to kill the previous run of the uiautomator2 server and start it again.

start session calls this.cleanupAutomationLeftovers

https://github.com/appium/appium-uiautomator2-driver/blob/25eeea068a1928dec32af5ac7744a967b385bf3a/lib/uiautomator2.js#L225

that in turn stops the server https://github.com/appium/appium-uiautomator2-driver/blob/25eeea068a1928dec32af5ac7744a967b385bf3a/lib/uiautomator2.js#L376

before starting it again https://github.com/appium/appium-uiautomator2-driver/blob/25eeea068a1928dec32af5ac7744a967b385bf3a/lib/uiautomator2.js#L241

socket hang up error

uiautomator2

Needs at least android 5

A lot of sites say that some uiautomatorviewer tool exist. But so far, I could not find any proof of its existence, even downloading the sdk and android studio for linux and windows.

uiautomatorviewer

uiautomatorviewer

Developer Assistant APK

Developer Assistant_1.2.2_apkcombo.com.apk

(
    TMP="$(mktemp -d)"
    trap "rm -rf '${TMP}'" 0
    ipfs get -o "${TMP}/assistant.apk" https://konubinix.eu/ipfs/bafybeicrerjola33gyk2j2sow3jqgqcha27pskkhfo3xqrdtax7aijwfs4
    adb -s emulator-5554 install "${TMP}/assistant.apk"
)

sdkmanager

The sdkmanager is quite touchy. It needs to be called in a specific directory and specifying the root.

cd ~/.buildozer/android/platform/android-sdk/tools
./bin/sdkmanager --list --sdk_root=..

avdmanager

avdmanager list

To find the possible package to give to avd create

sdkmanager --list | gi system-images
[...]

  system-images;android-34;google_apis;x86_64                                              | 12            | Google APIs Intel x86_64 Atom System Image

[...]

Then

sdkmanager --install 'system-images;android-34;google_apis;x86_64'
avdmanager create avd --device 9 --name test --package "system-images;android-34;google_apis;x86_64"

L’émulateur opère de manière optimale s’il peut utiliser le matériel de votre ordinateur, tel que le processeur, le GPU et le modem, au lieu de fonctionner comme un logiciel pur

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

appareils Android ont recours à OpenGL for Embedded Systems (OpenGL ES ou GLES) pour le rendu des graphismes 2D et 3D à l’écran.

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

L’accélération matérielle, qui est généralement plus rapide, est recommandée. Toutefois, vous devrez peut-être recourir à l’accélération logicielle si votre ordinateur utilise des pilotes graphiques non compatibles avec l’émulateur.

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

Si vous démarrez l’émulateur à partir de la ligne de commande, vous pouvez forcer le paramètre d’accélération graphique de l’AVD correspondant à cette instance d’appareil virtuel

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

Pour spécifier un type d’accélération graphique lorsque vous exécutez un AVD à partir de la ligne de commande, incluez l’option -gpu, comme illustré dans l’exemple suivant :

emulator -avd avd_name -gpu mode [{-option [value]} … ]

La valeur de

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

Lorsque vous utilisez des images pour le niveau d’API 27 ou supérieur, l’émulateur peut afficher l’UI Android avec Skia. Skia aide l’émulateur à afficher les graphiques de manière plus fluide et plus efficace.

Pour activer le rendu Skia, utilisez les commandes suivantes dans le shell adb : su setprop debug.hwui.renderer skiagl stop start

https://developer.android.com/studio/run/emulator-acceleration?hl=fr

emulator

sdkmanager --install emulator

May need to sudo apt install libx11-dev to get libx11.so

Using the name of the avd installed with avdmanager (see above).

emulator -avd test -qemu -enable-kvm -gpu host
INFO    | Android emulator version 33.1.24.0 (build_id 11237101) (CL:N/A)
INFO    | AVD test has path /home/sam/.android/avd/../avd/test.avd
INFO    | trying to check whether /home/sam/.buildozer/android/platform/android-sdk is a valid sdk root
WARNING | /home/sam/.buildozer/android/platform/android-sdk/android-sdk/system-images/android-34/google_apis/x86_64/ is not a valid directory.
WARNING | emulator has searched the above paths but found no valid sdk root directory.
PANIC: Broken AVD system path. Check your ANDROID_SDK_ROOT value [/home/sam/.buildozer/android/platform/android-sdk]!

Strange. Hopefully, this can be easily circumvented

ln -s ~/.buildozer/android/platform/android-sdk ~/.buildozer/android/platform/android-sdk/android-sdk

Also, to enable keyboard in the avd

sed -i 's/hw.keyboard = no/hw.keyboard = yes/' ~/.android/avd/test.avd/config.ini

If the emulator restarted

adb disconnect emulator-5554

run in x11vnc

x11vnc -create -nopw -gone 'pkill -f "qemu-system-x86_64 -avd test" -SIGTERM' -env X11VNC_FINDDISPLAY_ALWAYS_FAILS=1 -env FD_PROG="emulator -avd test"

Then, on the remote side

xtightvncviewer localhost:5900

This uses xvfb under the hood

The good thing here is that the application starts only when connecting to the vnc server, not before.

This is not enough, as closing the window won’t send SIGTERM to the running emulator.

run in xvfb

apktool

Extract some apk with

apktool d my.apk

It creates the folder my

Then, make some changes, then

apktool b my

The new apk is in the my/dist/ folder

Connect Android to PC using debian and udev :

  • Get the code of the constructor
    • either get the code from http://developer.android.com/tools/device.html
    • or find the line [.] usb .: New USB device found, idVendor=04e8, . in the output of dmesg when you plug the phone. (for the example, my samsung phone indicates the vendor 04e8)
  • create an udev rule for the android phone when it plugs in
    • edit the new file /etc/udev/rules.d/50-android.rules and put into it SUBSYSTEM==“usb”, ATTR{idVendor}==“04e8”, MODE=“0666”, GROUP=“plugdev”
    • restart udev with
      service udev restart
      
  • re plug the phone

4

5

7

8.1

mindthegapps > 8.1

11

13

automation (with adb)

adb exec-out screencap -p > screen.png adb shell input keyevent keycode # voir les keycodes ici https://developer.android.com/reference/android/view/KeyEvent adb shell input tap x y adb shell input text letexte adb shell getevent -l # pour récup une macro adb shell sendevent <periph de getevent> adb shell input swipe 224 548 $((0x000001dd)) $((0x00000206)) # some times you have to reverse x and y

scrcpy

use the developer option to see the interraction on the screen then try and error with several swipes adb shell input swipe 200 200 200 300

adb shell input keyevent KEYCODE_POWER adb shell input keyevent KEYCODE_BACK

https://stackoverflow.com/questions/17259809/can-anyone-explain-this-command-fully-adb-shell-sendevent-device-type-code

A method to get what I want

https://stackoverflow.com/questions/25363526/fire-a-pinch-in-out-command-to-android-phone-using-adb

keep my screen unlocked during USB debugging?

change display brightness using adb

get the Android device screen size from the adb command line?

Notes linking here