anbox / anbox

Anbox is a container-based approach to boot a full Android system on a regular GNU/Linux system
https://anbox.io
GNU General Public License v3.0
8.86k stars 1.15k forks source link

Use emulated camera? #727

Open rodarima opened 6 years ago

rodarima commented 6 years ago

Hi, What is the support status for the emulated camera? Can be faked from an image or from the host webcam? I'm using Anbox under Arch Linux, with some modifications to run in LXC 3, using the latest commit a88faed6d3.

I'm trying to scan a QR code for WhatsApp, but when it tries to open the camera the window crashes:

05-26 21:43:19.267   118   130 I ActivityManager: START u0 {cmp=com.whatsapp/.qrcode.QrCodeActivity} from uid 10049 on display 0
05-26 21:43:19.377   456   456 I ToolbarWidgetWrapper: Progress display unsupported
05-26 21:43:19.751    35   761 D         : HostConnection::get() New Host Connection established 0x7fd77162c380, tid 761
05-26 21:43:19.782   456   747 D OpenGLRenderer: endAllActiveAnimators on 0x7f8b0cf03800 (ar$a) with handle 0x7f8b0cd60220
05-26 21:43:20.250   118   139 I ActivityManager: Displayed com.whatsapp/.qrcode.QrCodeActivity: +975ms
05-26 21:43:20.578   456   461 I art     : Do partial code cache collection, code=59KB, data=61KB
05-26 21:43:20.578   456   461 I art     : After code cache collection, code=46KB, data=53KB
05-26 21:43:20.578   456   461 I art     : Increasing code cache capacity to 256KB
05-26 21:43:27.649    47    47 I MediaPlayerService: MediaPlayerService::getOMX
05-26 21:43:27.649   118   771 I OMXClient: MuxOMX ctor
05-26 21:43:27.649   118   771 E ACodec  : Unable to instantiate a decoder for type 'audio/vorbis' with err 0xfffffffe.
05-26 21:43:27.649   118   771 E ACodec  : signalError(omxError 0xfffffffe, internalError -2)
05-26 21:43:27.649   118   771 E MediaCodec: Codec reported err 0xfffffffe, actionCode 0, while in state 1
05-26 21:43:27.649   118   769 E SoundPool: Unable to load sample
05-26 21:43:27.650   118   172 W AudioService: onLoadSoundEffects(), Error -2147483648 while loading samples
05-26 21:43:27.654    47   104 I MediaPlayerService: MediaPlayerService::getOMX
05-26 21:43:27.654   118   772 I OMXClient: MuxOMX ctor
05-26 21:43:27.654   118   772 E ACodec  : Unable to instantiate a decoder for type 'audio/vorbis' with err 0xfffffffe.
05-26 21:43:27.654   118   772 E ACodec  : signalError(omxError 0xfffffffe, internalError -2)
05-26 21:43:27.654   118   772 E MediaCodec: Codec reported err 0xfffffffe, actionCode 0, while in state 1
05-26 21:43:27.655   118   769 E SoundPool: Unable to load sample
05-26 21:43:27.712    40    40 I CameraService: CameraService::connect call (PID -1 "com.whatsapp", camera ID 0) for HAL version default and Camera API version 1
05-26 21:43:27.712    40    40 E CameraService: CameraService::connect X (PID 456) rejected (invalid camera ID 0)
05-26 21:43:27.713   456   456 W CameraBase: An error occurred while connecting to camera 0: Service not available
05-26 21:43:27.726   118   129 W ActivityManager: Duplicate finish request for ActivityRecord{749800c u0 com.whatsapp/.qrcode.QrCodeActivity t4 f}
05-26 21:43:27.945    35   189 D PermissionCache: checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (135 us)
05-26 21:43:27.980   118   129 D         : HostConnection::get() New Host Connection established 0x7f8b0dd5a8c0, tid 129
05-26 21:43:28.011    35    35 E EGL_emulation: tid 35: eglCreateSyncKHR(1315): error 0x3004 (EGL_BAD_ATTRIBUTE)
05-26 21:43:28.101   456   456 W GooglePlayServicesUtil: Google Play Store is missing.
05-26 21:43:31.225   118   118 W WindowManager: Attempted to remove non-existing token: android.os.Binder@54a2828
05-26 21:43:31.274    35   777 D         : HostConnection::get() New Host Connection established 0x7fd77162c640, tid 777
05-26 21:43:34.728   118   118 W WindowManager: Attempted to remove non-existing token: android.os.Binder@fbf7941

I tested some properties, like hw.camera and qemu.sf.fake_camera, but none of them seem to produce any effect.

morphis commented 6 years ago

What is the support status for the emulated camera? Can be faked from an image or from the host webcam?

There is no support yet to use the hosts camera.

rodarima commented 6 years ago

I tried to dig a bit more in the camera device source. First I recompiled Anbox with debug symbols to be able to use gdb. Following the parser from EmulatedCameraFactory I tried to guess the list response. I sent the string "ok:name=eye framedims=640x480 dir=back\n" using messenger_->send instead of an empty list, in camera_message_processor.cpp:

void CameraMessageProcessor::list() {

  WARNING("Only dummy camera implemented");
  char buf[1024];
  char *line = "ok:name=eye framedims=640x480 dir=back";
  sprintf(buf, "%s\n", line);
  WARNING("Sending buf of size %d : '%s'", strlen(buf), buf);
  messenger_->send(buf, strlen(buf));
}

And it seems to be sent correctly from the host:

[camera_message_processor.cpp:71@list] Sending buf of size 39 : 'ok:name=eye framedims=640x480 dir=back
'

But in the guest, there is a problem in completeQuery:

# grep -i Camera system.log
05-27 16:27:18.679   653   674 D InstalledAppProviderSer: insertAppIntoDb com.android.camera2
05-27 17:00:49.621    39    39 I cameraserver: ServiceManager: 0xf6e9af20
05-27 17:00:49.635    39    39 I CameraService: CameraService started (pid=39)
05-27 17:00:49.635    39    39 I CameraService: CameraService process starting
05-27 17:00:49.708    39    39 E EmulatedCamera_QemuClient: completeQuery: Invalid reply to the query
05-27 17:00:49.708    39    39 E EmulatedCamera_QemuClient: doQuery: Error 22 in query 'list' completion
05-27 17:00:49.708    39    39 E EmulatedCamera_QemuClient: listCameras: List cameras query failed: No error message
05-27 17:00:49.711    39    39 I CameraService: Loaded "Emulated Camera Module" camera module
05-27 17:00:49.711    39    39 E CameraService: setUpVendorTags: Vendor tag operations not fully defined. Ignoring definitions.

Seems to be failling before, in QemuClient, before the payload is read, in the ok:... :

    if (mReplyBuffer == NULL || mReplySize < 3) {
        ALOGE("%s: Invalid reply to the query", __FUNCTION__);
        mQueryDeliveryStatus = EINVAL;
        return EINVAL;
    }

What is the proper way to debug the qemu socket, so I can examine the messages sent and received? I used gdbserver inside the container, but the service seems to be loading the library dinamically:

% readelf -sW rootfs/system/lib/hw/camera.goldfish.so | grep completeQuery
   602: 000238d0   214 FUNC    GLOBAL DEFAULT   12 _ZN7android9QemuQuery13completeQueryEi

And I don't know how to restart the service cameraserver under gdb.

I could modify the QemuClient so I can get more information in the log, but I don't know how to recompile it. I guess I would need the whole Android NDK.

morphis commented 6 years ago

@rodarima You have to rebuild the entire Android system for this. See https://github.com/anbox/anbox/blob/master/docs/build-android.md for details.

See https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/camera/camera-service.c for the host implementation in the Android emulator the QemuClient talks to.

WPFilmmaker commented 6 years ago

I think webcam support would be amazing as there are many apps that use QR code for authentication.

kitingChris commented 5 years ago

Would be great... tried to use anbox for Microsoft Teams (Video conference).

voting +1 for webcam support

stravassac commented 5 years ago

voting +1 for webcam support for all video conference not support on Linux

yashtewari commented 5 years ago

+1 for emulating an image as camera input.

rizzini commented 5 years ago

voting +1 for webcam support

it-toppp commented 5 years ago

voting +1 for webcam support

cyko69 commented 5 years ago

voting +1 for webcam support

sandriaas commented 5 years ago

vote +1 for camera support, or maybe an emulated image picker

NeilPandya commented 5 years ago

Vote +100000000 if I could for webcam support!

davidvontamar commented 4 years ago

A direly needed feature to make video calls on WhatsApp.

ericmigi commented 4 years ago

If any devs are looking for added incentive to help crack this, I'll put $500 USD towards a bounty cc @morphis @rodarima if there's anyone who might be able to tackle this, I would love to support them! Thanks.

hoehermann commented 4 years ago

@ericmigi You may want to specify whether a single image suffices, a video stream is okay or you want to see an actual (read webcam) camera to be passed through for that bounty.

ericmigi commented 4 years ago

@hoehermann great point. $500 bounty is just for single image - specifically whatsapp QR code being passed through to Whatsapp.apk camera input. Happy to increase that for videostream passthrough from a webcamoid-type input on the host.

rodarima commented 4 years ago

@morphis you may want to integrate a bug bounty platform: https://en.wikipedia.org/wiki/Open-source_bounty

rizzini commented 4 years ago

Webcam on Anbox would be indeed awesome. I'm currently using Whatsapp Web with the Whastapp App inside Anbox, so I left this "webcam on anbox" idea for now. It's a pain in the ass to setup Whatsapp Web with Anbox. Works fine though..

ericmigi commented 4 years ago

@rizzini how did you get the WhatsApp web QR code to work inside anbox?

baptx commented 4 years ago

On Linux there is v4l2loopback to create a fake webcam device and use content from an image or video but I don't know if it works on Android. I also heard of fake camera Android apps but I did not get it working.

rizzini commented 4 years ago

@rizzini how did you get the WhatsApp web QR code to work inside anbox?

You'll need setup a Whatsapp account on a real phone or some emulator that supports webcam, like Genymotion. After that just enable Whatsapp Web on some browser with that account. Now we have a Whatsapp account with Whatsapp Web enabled, right? Then copy that Whatsapp account data /data/data/com.whatsapp from that phone or emulator to your Anbox using ADB(/data/data/com.whatsapp) or directly(/var/snap/anbox/common/data/data/com.whatsapp).

Directly: Keep in mind that, if you do copy the data folder directly, the permissions are not the same. The thing is that Anbox translates the permissions of the files outside to inside of the Android.

Outside Anbox permission example: 110073 Inside Anbox permission example: u0_a73

^ Find the pattern and go nuts.. I only did it with the ADB way to go.

ADB: The trick here is to maintain the com.whatsapp permissions, which is something like, for example, u0_a73. The best thing is to compress it with TAR using -p, --preserve-permissions, --same-permissions option like this: tar -cpf whatsapp_configs.tar.gz /data/data/com.whatsapp. Then just extract it to / on your Anbox using ADB too like this: tar xf whatsapp_configs.tar.gz -C /. It will be put at the same destination from when it was compressed.

The bad thing is that you won't be able to setup the Whatsapp Web on another browser and you can't clean the cookies/sessions on the current one after doing this, or you'll gonna need to do the whole process again.

I did that several times and works every time. It's ugly, but works. It's better that nothing, since we don't have a webcam support here yet...

I just recorded this to show that actually works: https://www.youtube.com/watch?v=73CnBPNy5Eo&feature=youtu.be

Edit: You need to overwrite the /data/data/com.whatsapp folder on your Anbox. Maybe tar xf whatsapp_configs.tar.gz -C / alone won't do it. Delete the original folder and extract the one with your profile whatever you want and move yourself. Don't forget to chmod -R 777 /data/data/com.whatsapp

ericmigi commented 4 years ago

@rizzini does the phone/emulator need to be rooted in order to tar up the /data/data/com.whatsapp directory? I'm not able to do it on an unrooted phone or normal AVD emulator.

ericmigi commented 4 years ago

nevermind, I'm an idiot and of course you need to root the device to extract the com.whatsapp dir. I did it on a non-Google Play AVD and it worked great. Super easy to transfer to Anbox as well. Thanks for the tip @rizzini!

lemont037 commented 4 years ago

@rizzini how did you get the WhatsApp web QR code to work inside anbox?

You'll need setup a Whatsapp account on a real phone or some emulator that supports webcam, like Genymotion. After that just enable Whatsapp Web on some browser with that account. Now we have a Whatsapp account with Whatsapp Web enabled, right? Then copy that Whatsapp account data /data/data/com.whatsapp from that phone or emulator to your Anbox using ADB(/data/data/com.whatsapp) or directly(/var/snap/anbox/common/data/data/com.whatsapp).

Directly: Keep in mind that, if you do copy the data folder directly, the permissions are not the same. The thing is that Anbox translates the permissions of the files outside to inside of the Android.

Outside Anbox permission example: 110073 Inside Anbox permission example: u0_a73

^ Find the pattern and go nuts.. I only did it with the ADB way to go.

ADB: The trick here is to maintain the com.whatsapp permissions, which is something like, for example, u0_a73. The best thing is to compress it with TAR using -p, --preserve-permissions, --same-permissions option like this: tar -cpf whatsapp_configs.tar.gz /data/data/com.whatsapp. Then just extract it to / on your Anbox using ADB too like this: tar xf whatsapp_configs.tar.gz -C /. It will be put at the same destination from when it was compressed.

The bad thing is that you won't be able to setup the Whatsapp Web on another browser and you can't clean the cookies/sessions on the current one after doing this, or you'll gonna need to do the whole process again.

I did that several times and works every time. It's ugly, but works. It's better that nothing, since we don't have a webcam support here yet...

I just recorded this to show that actually works: https://www.youtube.com/watch?v=73CnBPNy5Eo&feature=youtu.be

I tried the solution but didn't work, the App stops work after export the files compressed with the paramters of preserve the permissions and to unpack on the same path.

eduardogoncalves commented 4 years ago

Edit: You need to overwrite the /data/data/com.whatsapp folder on your Anbox. Maybe tar xf whatsapp_configs.tar.gz -C / alone won't do it. Just extract whatever you want and move yourself. Don't forget to chmod -R 777 /data/data/com.whatsapp

Thanks @rizzini. For me I just replicated /data/com.whatsapp permisions to it's subfolders and files:

root@anbox:/root# ls -lha /var/snap/anbox/common/data/data/ | grep com.whatsapp drwx------ 11 110049 110049 4.0K Jul 8 08:33 com.whatsapp

chown -R 110049:110049 /var/snap/anbox/common/data/data/com.whatsapp/*

WPFilmmaker commented 4 years ago

https://github.com/fython-tools/DocUIProxy-Android this project is abandoned but maybe it can be useful.

xiaobai20181017 commented 4 years ago

@rodarima You have to rebuild the entire Android system for this. See https://github.com/anbox/anbox/blob/master/docs/build-android.md for details. See https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/camera/camera-service.c for the host implementation in the Android emulator the QemuClient talks to.

What is the support status for the emulated camera? Can be faked from an image or from the host webcam?

There is no support yet to use the hosts camera.

Does the project support camera use of the host at the moment?

ericmigi commented 3 years ago

@hoehermann great point. $500 bounty is just for single image - specifically whatsapp QR code being passed through to Whatsapp.apk camera input. Happy to increase that for videostream passthrough from a webcamoid-type input on the host.

I'm ready to bump the bounty up from $500 to $1000 USD for anyone who can add camera passthrough into Anbox, to enable WhatsApp Web QR code processing.

baptx commented 3 years ago

@ericmigi posting the bounty on an open source bug bounty platform (e.g. Boutysource) like mentioned by @rodarima will give more visibility. If the earner wants to avoid fees, he could be paid using a PayPal Money Pool directly in his currency.

ShadowJonathan commented 3 years ago

You have to rebuild the entire Android system for this. See https://github.com/anbox/anbox/blob/master/docs/build-android.md for details.

See https://android.googlesource.com/platform/external/qemu/+/emu-master-dev/android/android-emu/android/camera/camera-service.c for the host implementation in the Android emulator the QemuClient talks to.

I had to track down the link, as google changed repos around, the new link is https://android.googlesource.com/platform/external/qemu/+/refs/heads/master/android/camera/camera-service.c

NinoSkopac commented 3 years ago

I’m also very interested in this.

@ericmigi Have you been able to find a way to passthrough the camera yet?

i’m wondering what is the purpose of this files: 025432A6-2C44-46AA-AEBC-6DB491E9F9BE

thank you!

ericmigi commented 3 years ago

@ShadowJonathan is maybe looking into it 😉

btlucas commented 3 years ago

Does anyone have a update to this? Maybe a easier workaround than the one @rizzini presented?

bytesWhisperer commented 3 years ago

Found finally a solution for WhatsApp:

You need a rooted phone!

Preparation:

  1. Use a phone with camera and login to your whatsapp account and connect to all whatsapp web devices you need (we can later recover it on anbox at anytime)
  2. put that phone to airplane mode and connect to pc: Terminal: adb shell su whatsapp personal: cd /data/data/com.whatsapp/databases/ whatsapp buisness: cd /data/data/com.whatsapp.w4b/databases/ cp web_sessions.db /sdcard/ cp web_sessions.db-journal /sdcard/ exit exit adb pull /sdcard/web_sessions.db /home/testuser/Downloads/ adb pull /sdcard/web_sessions.db-journal /home/testuser/Downloads/

!Delete now WhatsApp from your phone - then you can put airplane mode off!

Anbox:

  1. Transfer the files (web_sessions.db-journal & web_sessions.db) to the system where anbox is located
  2. start anbox & install whatsapp, login with your number, setup and close whatsapp
  3. open terminal adb push /home/testuser/web_sessions.db /sdcard/ adb push /home/testuser/Downloads/web_sessions.db-journal /sdcard/ adb shell su

whatsapp personal: cp /sdcard/web_sessions.db /data/data/com.whatsapp/databases/ whatsapp personal: cp /sdcard/web_sessions.db-journal /data/data/com.whatsapp/databases/

whatsapp buisness: cp /sdcard/web_sessions.db /data/data/com.whatsapp.w4b/databases/ whatsapp buisness: cp /sdcard/web_sessions.db-journal /data/data/com.whatsapp.w4b/databases/

(keep adb open for next part)

Permissions:

whatsapp personal: cd /data/data/com.whatsapp/databases whatsapp buisness: cd /data/data/com.whatsapp.w4b/databases ls -l (you will see something like: -rw-rw---- root root 4096 .... we copy root root (so owner of files, check your owner of the files and replace it in next step)) chown -R root:root web_sessions.db chown -R root:root web_sessions.db-journal exit exit

Finish! Open WhatsApp and u will see WhatsApp Web Account recovered.

Save both files carefully, you can repeat - starting from part Anbox - as long as you dont log off from destination whatsapp web computer, to recover whatsapp web accounts on anbox

(sorry for my bad english)

baptx commented 3 years ago

@Scooppt unfortunately we need an Android device for this solution. I did not try the solution of @rizzini yet but the drawback is that we need to run the proprietary software Genymotion on our computer.

Update: It seems to be possible to do it by running only open source software using Android x86 on VirtualBox and making the camera work by installing "Oracle VM VirtualBox Extension Pack": https://stackoverflow.com/questions/10950816/android-x86-virtualbox-camera/59181230#59181230 (I will need to test when I have a moment).

Update 2: In fact VirtualBox Extension Pack is not open source but I confirm that it works, we don't need Genymotion (which is using VirtualBox anyway and requires to create an account to log in). Then I was able to use WhatsApp Web by copying the data from Android x86 to Anbox, based on a previous comment: https://github.com/anbox/anbox/issues/1061#issuecomment-538642281 (by the way, chmod -R 700 seems enough, otherwise I think other Android apps can spy on WhatsApp config files). I noticed that we have to keep the WhatsApp Android app running in background in Anbox, otherwise we get disconnected from WhatsApp Web. This is not convenient but at least we can close the Anbox GUI. To completely close Anbox background apps, we have to use the command sudo snap stop anbox. If you want to do something else like logging in to a website and you are not using X11 isolation (I have not found a solution yet: https://github.com/anbox/anbox/issues/714), I recommend closing completely Anbox with the command above, otherwise a malicious Android app could track all your clipboard activity (I shared an example on https://forum.sailfishos.org/t/anbox-on-sfos-phones/2129/59) and maybe do screenshots or run a keylogger. It is currently possible to use WhatsApp Web on another web browser without scanning the QR code again, by copying the following local storage keys with their value (for example in Firefox Developer Tools): WABrowserId, WASecretBundle, WAToken1, WAToken2. For some reason, I noticed that it only worked when copying the value in the private mode of a web browser (tested with Firefox).

Update 3: I was able to copy the localStorage data to Firefox even if not in private mode, by executing JavaScript code like localStorage.setItem('WABrowserId', '"XXX"'); to set all the data at the same time (you need to clear browser data before). Now we would just need camera support in Anbox so we have an open source solution to scan the QR code and don't need to use another software.

reoccurcat commented 3 years ago

+1 for webcam support

alecbarber commented 3 years ago

I've implemented webcam support here: https://github.com/alecbarber/anbox/ for those who are happy to run Anbox manually (i.e. not as a snap). Using v4l2loopback it should be theoretically possible to pass a Whatsapp QR code into Anbox. I'm currently working on making the camera work when Anbox is packaged as a snap.

The basic idea is that Android/QEMU already comes with all the machinery required to pass the camera through (as alluded to by @NinoSkopac ), so the only thing that was needed was to plug the QEMU code into the existing Anbox session manager.

rizzini commented 3 years ago

I've implemented webcam support here: https://github.com/alecbarber/anbox/ for those who are happy to run Anbox manually (i.e. not as a snap). Using v4l2loopback it should be theoretically possible to pass a Whatsapp QR code into Anbox. I'm currently working on making the camera work when Anbox is packaged as a snap.

The basic idea is that Android/QEMU already comes with all the machinery required to pass the camera through (as alluded to by @NinoSkopac ), so the only thing that was needed was to plug the QEMU code into the existing Anbox session manager.

I tried with my real webcam and it didn't work. I'll test it with v4l2loopback.

alecbarber commented 3 years ago

I tried with my real webcam and it didn't work.

As in the QR code didn't scan, or the webcam input didn't work? One thing to be aware of is that the Android image I linked isn't the same as the mainline Anbox image; I made a couple of changes to the QEMU camera client code that runs inside Android

Update: I'm able to open Whatsapp on Anbox, and scan a QR code on a second device using my laptop's builtin webcam. I'm also able to point an external webcam at my monitor and scan a QR code on the screen. I had a lot of trouble scanning the QR code on my screen initially - turns out that my dark mode browser extension stopped the QR code from scanning, but once I turned that off it was a breeze!

whatsapp_web

rizzini commented 3 years ago

I tried with my real webcam and it didn't work.

As in the QR code didn't scan, or the webcam input didn't work? One thing to be aware of is that the Android image I linked isn't the same as the mainline Anbox image; I made a couple of changes to the QEMU camera client code that runs inside Android

Update: I'm able to open Whatsapp on Anbox, and scan a QR code on a second device using my laptop's builtin webcam. I'm also able to point an external webcam at my monitor and scan a QR code on the screen. I had a lot of trouble scanning the QR code on my screen initially - turns out that my dark mode browser extension stopped the QR code from scanning, but once I turned that off it was a breeze!

whatsapp_web

Sorry, I wasn't clear. The webcam didn't work, the msgs says couldn't be initialized. I"ll do more tests tonight.

Logcat from when I tried to open the camera:

07-12 09:19:39.258    31   124 D AudioFlinger: mixer(0xf6903180) throttle end: throttle time(99)
07-12 09:19:39.260   134   685 I ActivityManager: START u0 {cmp=com.whatsapp/.qrcode.DevicePairQrScannerActivity} from uid 10050 on display 0
07-12 09:19:39.314   576   576 I ToolbarWidgetWrapper: Progress display unsupported
07-12 09:19:39.385    32   132 I CameraService: CameraService::connect call (PID -1 "com.whatsapp", camera ID 0) for HAL version default and Camera API version 1
07-12 09:19:39.385    32   132 E CameraService: CameraService::connect X (PID 576) rejected (invalid camera ID 0)
07-12 09:19:39.385   576  1001 W CameraBase: An error occurred while connecting to camera 0: Service not available
07-12 09:19:39.413   134   160 I ActivityManager: Displayed com.whatsapp/.qrcode.DevicePairQrScannerActivity: +139ms
07-12 09:19:39.464   576   905 D OpenGLRenderer: endAllActiveAnimators on 0x7fce2b12dc00 (RippleDrawable) with handle 0x7fce2d374f60
07-12 09:19:39.490   134   685 W InputMethodManagerService: Focus gain on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@526d44b (uid=10050 pid=576)
07-12 09:19:42.929   134   134 W WindowManager: Attempted to remove non-existing token: android.os.Binder@b046d7
devheitor commented 3 years ago

@rizzini Hey man, first of all, thanks for your contributions.. it seems that a lot of people here, as I am, are trying to do the same thing. If you have any update using v4l2loopback could you tell us? I don't even know how to start.

rizzini commented 3 years ago

@Scooppt unfortunately we need an Android device for this solution. I did not try the solution of @rizzini yet but the drawback is that we need to run the proprietary software Genymotion on our computer.

If you want to avoid proprietary software, you can do it using Android SDK or a real rooted phone instead Genymotion, for example.

alecbarber commented 3 years ago

@devheitor I'd recommend starting by getting my fork of Anbox running (instructions here) and installing v4l2loopback according to the instructions at its Github. Once they're working for you, then the following steps have worked for me (sorry that it's a bit of a long procedure!)

Create the virtual camera

  1. See what camera devices you have installed: ls /dev/video*
  2. Start a virtual camera device: sudo modprobe v4l2loopback
  3. Identify the virtual device: ls /dev/video* again; there should be an extra entry for the virtual device.

Setup the Whatsapp QR code stream

  1. Open web.whatsapp.com in your browser
  2. Start a screengrab: ffmpeg -f x11grab -r 2 -video_size 800x600 -i :0.0+850,80 -f v4l2 /dev/videoNN where /dev/videoNN is your virtual camera device. Whatsapp doesn't seem to mind the low framerate.
  3. Test the screengrab using (for example) ffplay /dev/videoNN while ffmpeg is running. You might need to adjust the video size and coordinates from the previous command – the QR code should be roughly centred in the frame and should take up between 1/3 and 1/2 of the frame's height.

Connect to Whatsapp Web

  1. Set export ANBOX_HW_CAMERA_BACK=webcamNN where /dev/videoNN is your loopback device.
  2. Launch Anbox according to the instructions here. If you already had Anbox running, re-launch it.
  3. Open Whatsapp and go to the "Linked devices" page.
  4. BEFORE CLICKING "LINK DEVICE": Make sure that ffmpeg is running, and that you can see a QR code on the Whatsapp web page
  5. Click LINK DEVICE - this should open a camera view which scans the QR code!
alecbarber commented 3 years ago

@rizzini sorry I didn't see your updated logcat until just now! Unfortunately it doesn't mean very much to me on its own...

There'll be more messages in the session manager's console output. export ANBOX_LOG_LEVEL=debug and then restarting the session manager should give you a whole dump of logs. If you post those logs including the error then I'll have a look and see if I can be of more assistance!

devheitor commented 3 years ago

Hey, @alecbarber I just have to say thank you.. I'll try each thing and I'll update people here and in your project how it worked for me! big thanks!

rizzini commented 3 years ago

@devheitor I'd recommend starting by getting my fork of Anbox running (instructions here) and installing v4l2loopback according to the instructions at its Github. Once they're working for you, then the following steps have worked for me (sorry that it's a bit of a long procedure!)

Create the virtual camera

  1. See what camera devices you have installed: ls /dev/video*
  2. Start a virtual camera device: sudo modprobe v4l2loopback
  3. Identify the virtual device: ls /dev/video* again; there should be an extra entry for the virtual device.

Setup the Whatsapp QR code stream

  1. Open web.whatsapp.com in your browser
  2. Start a screengrab: ffmpeg -f x11grab -r 2 -video_size 800x600 -i :0.0+850,80 -f v4l2 /dev/videoNN where /dev/videoNN is your virtual camera device. Whatsapp doesn't seem to mind the low framerate.
  3. Test the screengrab using (for example) ffplay /dev/videoNN while ffmpeg is running. You might need to adjust the video size and coordinates from the previous command – the QR code should be roughly centred in the frame and should take up between 1/3 and 1/2 of the frame's height.

Connect to Whatsapp Web

  1. Set export ANBOX_HW_CAMERA_BACK=webcamNN where /dev/videoNN is your loopback device.
  2. Launch Anbox according to the instructions here. If you already had Anbox running, re-launch it.
  3. Open Whatsapp and go to the "Linked devices" page.
  4. BEFORE CLICKING "LINK DEVICE": Make sure that ffmpeg is running, and that you can see a QR code on the Whatsapp web page
  5. Click LINK DEVICE - this should open a camera view which scans the QR code!

Oh my god.. It worked even with my real webcam!!! It's definitely a start. Thank you so much.

tareko commented 3 years ago

@alecbarber : unfortunately this doesn't look like it compiles on 20.04 with the instructions from your repo. It seems that it fails on some tests:

[ 92%] Linking CXX executable intent_tests
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `Intent_IsValid_Test::TestBody()':
/anbox/tests/anbox/android/intent_tests.cpp:26: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:26: undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:26: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:26: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:24: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:24: undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:24: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:24: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:28: undefined reference to `testing::Message::Message()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:28: undefined reference to `testing::internal::GetBoolAssertionFailureMessage[abi:cxx11](testing::AssertionResult const&, char const*, char const*, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:28: undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:28: undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `Intent_IsValid_Test::~Intent_IsValid_Test()':
/anbox/tests/anbox/android/intent_tests.cpp:22: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `Intent_IsValid_Test::~Intent_IsValid_Test()':
/anbox/tests/anbox/android/intent_tests.cpp:22: undefined reference to `testing::Test::~Test()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `Intent_IsValid_Test::Intent_IsValid_Test()':
/anbox/tests/anbox/android/intent_tests.cpp:22: undefined reference to `testing::Test::Test()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `Intent_IsValid_Test::TestBody()':
/anbox/tests/anbox/android/intent_tests.cpp:24: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:26: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:30: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: /anbox/tests/anbox/android/intent_tests.cpp:28: undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int)':
/usr/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int)':
/usr/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: /usr/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int)':
/usr/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::IsTrue(bool)'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `_GLOBAL__sub_I_intent_tests.cpp':
/anbox/tests/anbox/android/intent_tests.cpp:22: undefined reference to `testing::internal::GetTestTypeId()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `__static_initialization_and_destruction_0':
/anbox/tests/anbox/android/intent_tests.cpp:22: undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int)':
/usr/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/include/gtest/internal/gtest-internal.h:531: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o: in function `testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int)':
/usr/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)'
/usr/bin/ld: /usr/include/gtest/internal/gtest-internal.h:516: undefined reference to `testing::internal::GTestLog::~GTestLog()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o:(.data.rel.ro._ZTI19Intent_IsValid_Test[_ZTI19Intent_IsValid_Test]+0x10): undefined reference to `typeinfo for testing::Test'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o:(.data.rel.ro._ZTV19Intent_IsValid_Test[_ZTV19Intent_IsValid_Test]+0x20): undefined reference to `testing::Test::SetUp()'
/usr/bin/ld: CMakeFiles/intent_tests.dir/intent_tests.cpp.o:(.data.rel.ro._ZTV19Intent_IsValid_Test[_ZTV19Intent_IsValid_Test]+0x28): undefined reference to `testing::Test::TearDown()'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/anbox/android/CMakeFiles/intent_tests.dir/build.make:110: tests/anbox/android/intent_tests] Error 1
make[1]: *** [CMakeFiles/Makefile2:1995: tests/anbox/android/CMakeFiles/intent_tests.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
alecbarber commented 3 years ago

@tareko I also had issues getting the tests to build. They don't relate to any of the code I've modified so I wasn't too stressed; as a hacky workaround just comment out line 141 (add_subdirectory(tests)) in the top-level CMakeLists.txt then run cmake .. again from the build directory to regenerate the makefiles without tests.

tareko commented 3 years ago

@tareko I also had issues getting the tests to build. They don't relate to any of the code I've modified so I wasn't too stressed; as a hacky workaround just comment out line 141 (add_subdirectory(tests)) in the top-level CMakeLists.txt then run cmake .. again from the build directory to regenerate the makefiles without tests.

That worked! Thank you.

tareko commented 3 years ago

I spoke too soon. Even though I have both kernel drivers loaded, I get:

[ 2021-07-20 00:25:56] [session_manager.cpp:149@operator()] Failed to start as either binder or ashmem kernel drivers are not loaded

I guess this is why docker exists. I haven't had to go through compile hell in a while :rofl:

EDIT: OK, saw the next set of instructions for the container below... I think I'm on the right track now.