Skip to content

Instantly share code, notes, and snippets.

@odmnk
Last active June 27, 2021 20:50
Show Gist options
  • Save odmnk/58b95868dffb5792f2648b88a0f61120 to your computer and use it in GitHub Desktop.
Save odmnk/58b95868dffb5792f2648b88a0f61120 to your computer and use it in GitHub Desktop.
A very nasty hack to make sure all communication with the device goes over USB when NOT profiling and over WiFi when profiling.
diff --git a/AndroidRunner/Plugins/monsoon/Monsoon.py b/AndroidRunner/Plugins/monsoon/Monsoon.py
index 474d4af..4eb2037 100644
--- a/AndroidRunner/Plugins/monsoon/Monsoon.py
+++ b/AndroidRunner/Plugins/monsoon/Monsoon.py
@@ -3,8 +3,10 @@ import os
import os.path as op
import time
from collections import OrderedDict
-
+import datetime
+import subprocess
from AndroidRunner import util
+from AndroidRunner import Adb
from AndroidRunner.Plugins.Profiler import Profiler
from AndroidRunner.Plugins.monsoon.script.power_device import power_meter
@@ -22,13 +24,21 @@ class Monsoon(Profiler):
def load(self, device):
return
+ def set_file(self, value):
+ profiling_file = "/home/user/android-runner/profiling.txt"
+ with open(profiling_file, 'w') as filetowrite:
+ filetowrite.write(value)
+
def start_profiling(self, device, **kwargs):
"""Start the profiling process"""
+ # Set that we are profiling so all communications with the device go over WiFi.
+ self.set_file("1")
+
+ # Disable USB port of the Monsoon.
+ power_meter.monsoon_usb_enabled(False)
- # Quickly let the mobile device sleep and wake up so a run can take up to 30 minutes.
- device.shell("input keyevent KEYCODE_SLEEP")
- device.shell("input keyevent KEYCODE_WAKEUP")
time.sleep(5)
+
self.profile = True
power_meter.start()
@@ -37,11 +47,20 @@ class Monsoon(Profiler):
self.results = power_meter.stop()
self.profile = False
+ time.sleep(5)
+
+ # Enable the USB port of the Monsoon again.
+ power_meter.monsoon_usb_enabled(True)
+
+ # Set that we stopped profiling so all communicaitons with the device go over USB once again.
+ self.set_file("0")
+
# Quickly let the mobile device sleep and wake up so the device is awake for 30 minutes.
- # This solves the issue of certain commands sent to the device blocking the execution of the program.
device.shell("input keyevent KEYCODE_SLEEP")
+ time.sleep(3)
device.shell("input keyevent KEYCODE_WAKEUP")
- time.sleep(5)
+ time.sleep(3)
+
def collect_results(self, device):
"""Collect the data and clean up extra files on the device, save data in location set by 'set_output' """
diff --git a/AndroidRunner/pyand/ADB.py b/AndroidRunner/pyand/ADB.py
index 9e003dc..7791016 100644
--- a/AndroidRunner/pyand/ADB.py
+++ b/AndroidRunner/pyand/ADB.py
@@ -72,9 +72,26 @@ class ADB(object):
a.insert(0, self.__adb_path)
if self.__target is not None:
# add target device arguments to the command
+
+
+ profiling_file = "/home/user/android-runner/profiling.txt"
+ with open(profiling_file) as filetowrite:
+ content = filetowrite.read()
+
+ print("profiling: ", content)
+
+ if content == "1\n" or content == "1":
+ self.__target = "192.168.2.10:5555"
+ else:
+ self.__target = "01ca4c64db5d1014"
+ print("after")
+
a.insert(1, '-s')
a.insert(2, self.__target)
+ print(self.__target)
+ print(a)
+
return a
def run_cmd(self, cmd):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment