Users browsing this thread: 4 Guest(s)
z3bra
Grey Hair Nixers
Hello there fellow nixers,

We are living weird times, and I need to run an android application in "server mode". That is, run all the time, as a service if possible.

I know that I'm asking a lot, and I think the closest I can get for that is an android VM running "headless" , and managed from the cli via `adb`. My servers are running OpenBSD right now, and it seems that vmd can boot android x86 iso. I'm wondering if any of you had tips on how I would go about doing that, or if it's even possible ?

I found the following: https://github.com/tulir/mautrix-whatsap...d-VM-Setup

Which is exactly what I want to do. But it uses the qemu version shipped with the android sdk, and I'm fairly sure I can't use that on OpenBSD.
BANGARANG, MOTHERFUCKER
z3bra
Grey Hair Nixers
Here are some updates on the topic, even though no one seemed interrested:

I gave up on OpenBSD. Getting the emulator running on Debian was painful enough, that I didn't want to fight it on OpenBSD. I found a thread stating that someone managed to get the emulator running on OpenBSD, and that has the linux compatibility mode as a hard requirement (to run ELF binaries), and that was removed from base in 6.0 (I'm running 6.7 everywhere). At this point I was about to spin up a linux VM on my OpenBSD, in order to run Android VM on it… So I decided to rent a cheap bare metal server (500Gb HDD, 4Gb Ram, Intel Avoton with VT-x support). You must take the following into account:
  • Emulator won't start if there isn't at least 2Gb of free memory
  • Emulator won't start if there is "no enough diskspace" (I think around 8Gb)
  • Running the emulator from a virtual machine means no VM acceleration available (use --no-accel), resulting in a slower VM

I slapped a Debian 10 on that VPS and installed "android-sdk" from the repo. It pulled a JDK 11 as a dependency, which seems to work correctly (despite the warning on the mautrix link). I also needed the following packages for the emulator to start (libs shipped with the emulator didn't work):
  • libopengl0
  • libegl1-mesa
  • libgl1
  • libtinfo5
  • libxdamage1

The sdk is installed to /usr/lib/android-sdk. I grabbed the CLI tools for android (not in the debian repo) from here: https://developer.android.com/studio/command-line. I unpacked it in my $HOME directory, and used the tool "sdkmanager" to install all the needed stuff to my SDK root:

Code:
# First bootstrap the cmdline tools properly
sudo ./sdkmanager --sdk_root=/usr/lib/android-sdk 'cmdline-tools;2.1'
sudo ln -s /usr/lib/android-sdk/cmdline-tools/2.1/bin/sdkmanager /usr/bin/sdkmanager
sudo ln -s /usr/lib/android-sdk/cmdline-tools/2.1/bin/avdmanager /usr/bin/avdmanager

sudo sdkmanager emulator
sudo sdkmanager platform-tools
sudo sdkmanager 'system-images;android-30;google_apis_playstore;x86_64'
sudo sdkmanager --update

sudo ln -s /usr/lib/android-sdk/emulator/emulator /usr/bin/emulator

Now that the SDK is ready, you must create and android VM, and install/configure Whatsapp on it. This MUST be done on a system with graphical interface, as you need to use the touchscreen of the device. The above steps can be used to install the Android SDK on your local machine.

Create and launch the VM:

Code:
avdmanager create avd -n whatsapp -k 'system-images;android-30;google_apis_playstore;x86_64'
emulator -avd whatsapp
[code]

Don't forget to allow the USB fingerprint key when the phone starts. You'll need it for connecting to the emulator on your server with "adb".

Then you can use the emulator to install whatever app you want, and configure it. For my needs, I installed whatsapp and configured it with my account using the v4l2loopback kernel driver to hook the device camera to a running ffmpeg recording my desktop. This is needed to scan a QR code. Whatever.

When you're done, shutdown the device, and rsync the whole ~/.android directory to your server. You should then be able to run the emulator, headless on your server:

[code]
nohup emulator -avd whatsapp -no-audio -no-window > emulator.log &
until adb shell; do sleep 1; done

To connect successfully using "adb", you need to have accepted the fingerprint key on your local computer, and use the same ~/.android/adbkey file on your server. As "adb" is required to push a new key, you need to have it configured BEFORE you need to use it on the server.

It is possible that your device doesn't have internet access after boot. That was my case, and it is due to the wlan0 interface being down. You can enable it with:

Code:
adb shell "svc wifi enable"

You need to wait for the device to finish booting before doing that, or it will complain that the "wifi" service doesn't exist. It took so freaking long on the qemu-based VPS I used first that I though it was an issue with the emulator-within-virtualmachine, and switched to a baremetal server. Turns out after a loooong time (few hours?), I tried to enable it on the qemu-based one, and it worked. Just took really long because there was no hardware acceleration.

I now have a fully running android VM on my server ! I can use the adb shell to start applications, and do whatever is possible from the adb shell.

Happy hacking !
octahedral
Members
I'm curious, why did you need to run an Android app as a service in the first place?
z3bra
Grey Hair Nixers
I was organizing my brother's birthday, and most people involved use Whatsapp (I don't). Instead of being the asshole again and trying to get them use telegram or IRC, I decided to adapt, and bridge whatsapp with telegram and IRC, so I could lead the group from the comfort of my setup. I use matterbridge for this.

The only caveat with whatsapp is that your only way to interact with it is using the web access, and that require the "official" application running in parallel. So for that, I setup the VM with whatsapp started, just so it can relay the messages from the bridge.
jkl
Long time nixers
Telegram is not any better than WhatsApp.

--
<mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen
wolf
Members
(07-07-2020, 04:29 AM)z3bra Wrote: Instead of being the asshole again and trying to get them use telegram or IRC, I decided to adapt, and bridge whatsapp with telegram and IRC, so I could lead the group from the comfort of my setup. I use matterbridge for this.

Hey... that's pretty good ..

Well, I was trying to bring libwa to OpenBSD, with no luck until now.
z3bra
Grey Hair Nixers
(07-07-2020, 01:31 PM)jkl Wrote: Telegram is not any better than WhatsApp.

Thanks for that well-detailed intervention ☺️
I still prefer telegram over whatsapp as it's not owned by facebook. And the bridge is also linked to my own IRC server as well.

Quote:Well, I was trying to bring libwa to OpenBSD, with no luck until now.

That's a nice lib ! Thanks for sharing.
jkl
Long time nixers
(08-07-2020, 04:46 AM)z3bra Wrote: Thanks for that well-detailed intervention ☺️

https://gizmodo.com/why-you-should-stop-...1782557415

Not being made by Facebook does not make it a privacy-friendly software.

--
<mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen
z3bra
Grey Hair Nixers
This is true. I'm fine with these "flaws" though.