privacy-tech-lab / gpc-android

Code and dynamic analysis scripts for GPC on Android
https://privacytechlab.org/
MIT License
5 stars 1 forks source link

Prevent monkey from disabling wifi #74

Closed kasnder closed 1 year ago

kasnder commented 1 year ago

Possible approaches:

  1. ADB settings (preferred): https://stackoverflow.com/questions/39952410/how-to-prevent-monkey-test-from-opening-notification-panel-and-turning-off-wifi
  2. Overlays (use ChatGPT to implement this, in case 1. does not work): https://stackoverflow.com/questions/13346111/draw-overlay-in-android-system-wide
  3. Use DroidBot, which is much more advanced: https://github.com/honeynet/droidbot
wesley-tan commented 1 year ago

So, I tried using various approaches to solve this problem (mostly because I was curious as to whether Method 2 was possible, I tried Method 2 before Method 1, although Method 1 was definitely more straightforward). For Method 1 (changing the adb commands):

For the adb -s emulator-5554 shell monkey -v -p com.logomaster.logomaker --throttle 30 --pct-syskeys 5 3000 command, why this did not work is because the Monkey is still able to "swipe down". To avoid such unwanted actions during your testing, we can adjust the command by reducing the percentage of system key events to minimize the likelihood of triggering actions like pulling down the status bar. Additionally, we should exclude the --pct-appswitch option, as it generates events for switching between different applications, which may interrupt testing flow.

I found that adb -s emulator-5554 shell monkey -v -p com.logomaster.logomaker --pct-touch 100 --pct-syskeys 0 3000

 and adb -s emulator-5554 shell monkey -v -p com.logomaster.logomaker --pct-touch 100 --pct-motion 0 --pct-trackball 0 --pct-syskeys 0 --pct-nav 0 --pct-majornav 0 --pct-appswitch 0 --pct-flip 0 --pct-anyevent 0 --pct-pinchzoom 0 --pct-permission 0 3000 were both effective. The core principle is just that all event percentages except for --pct-touch are set to 0. This means no events of those types will be generated. By setting all other event percentages to 0, we ensure that only touch events (taps) are generated, eliminating any unwanted actions caused by other event types like motion, trackball, or system keys. The video recordings are below:

Command which worked

https://github.com/privacy-tech-lab/gpc-android/assets/98197696/73787b32-676d-491f-8bde-3cd3dacf9613

Command which did not work

https://github.com/privacy-tech-lab/gpc-android/assets/98197696/177c6f88-ee45-40c7-8f81-639c1be82c17

Of course, just to be sure, I will run it a few more times just to be sure the Monkey does not swipe down.

wesley-tan commented 1 year ago

Method 2 (overlay app that runs in background) was unsuccessful, but more interesting (this is quite unrelated to our project but I found it interesting at least 😆 ) I put together an app which tried to place an overlay. The basic functionality of the app can be seen in the video below ( I can put the code in a branch if needed!)

I tried a few strategies:

  1. The SYSTEM_UI_FLAG_HIDE_NAVIGATION and SYSTEM_UI_FLAG_FULLSCREEN flags hide the navigation and status bars respectively. The SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag hides the navigation and status bars until the user swipes from the edge where the bar is located. When this happens, the bars appear semi-transparently, and then hide again once the system decides it's appropriate.
  2. Use of the WifiLock, which would keep the Wi-Fi awake even when the screen turns off.
  3. Lastly, the overlay permission (Settings.canDrawOverlays()) is needed for apps to draw over other apps or the system UI, but this doesn't mean they can block the system UI.

However the app doesn’t really work because Android doesn't allow apps to block or disable the status bar or navigation bar for security and usability reasons (and I suppose this is logical, would be pretty horrifying if an app could be programmed to disallow you to swipe down). The user always needs to have control over the system and be able to leave any app.

https://github.com/privacy-tech-lab/gpc-android/assets/98197696/eb48adf7-a2be-4592-a647-ccc91ee6d17e

wesley-tan commented 1 year ago

Basically, the commands --pct-touch 100 --pct-syskeys 0 or --pct-touch 100 --pct-motion 0 --pct-trackball 0 --pct-syskeys 0 --pct-nav 0 --pct-majornav 0 --pct-appswitch 0 --pct-flip 0 --pct-anyevent 0 --pct-pinchzoom 0 --pct-permission 0 for the adb Exercise Monkey do work. I will confirm this with more testing and see if there's anyway to improve this (e.g. throttle etc). But I think this issue can be closed soon.

I'll also look into DroidBot (https://github.com/honeynet/droidbot); and see if this offers any further utility or data collected that would be useful

SebastianZimmeck commented 1 year ago

Thanks, @wesley-tan. Since we may not use the Monkey Exerciser after all, I would suggest not spending too much time on it and address the other issues instead.

SebastianZimmeck commented 1 year ago

@wesley-tan will close this issue once we are 100% sure that we do not want to use the Exerciser UI Monkey.