0

The (Android) app we're working on is depended on it's plugged-in (AC) status.

Because we want to run the app on a real device connected to our buildserver we need a way to fake this behaviour in order to fully test the app without actually removing the device from power.

Now I've learned about adb shell dumpsys battery ac 0|1 which allowed me to set it. But I was unable to get this working during the test itself with:

Process.run('adb', [
    'shell',
    'dumpsys',
    'battery',
    'set',
    'ac',
    '1',
  ]);

This results in the following error:

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following ProcessException was thrown running a test:
Permission denied
  Command: adb shell dumpsys battery set ac 1

I also tried it with sudo, but that resulted in the same.

SEG.Veenstra
  • 718
  • 1
  • 7
  • 18
  • Is your device rooted? I think you need this to mock battery status. – Guilherme Gabanelli Apr 29 '21 at 13:47
  • It's not rooted, but I am able to do this trough adb from my terminal. (i can successfully see the battery indicator showing the onPower icon) But I can't get it to work from the integration test itself. – SEG.Veenstra Apr 29 '21 at 18:12

0 Answers0