1

I am looking to control my mobile devices that are plugged into MAC/PC via usb.

Specifically, I want to turn "Airplane Mode" on and off using just python codes.

My bad solution to control the mobile device was...

using Selenium and TeamViewer web mode.

But, as you can see, the device goes to 'offline' when I turn on the airplane mode.

Any idea?

hyukkyulee
  • 1,024
  • 1
  • 12
  • 17

1 Answers1

2

You can do it with AndroidViewClient/culebra.

Here is an example you can base your script on (autogenerated by culebra):

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018  Diego Torres Milano
Created on 2018-08-09 by Culebra v15.4.0
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import re
import sys
import os


import unittest

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase

TAG = 'CULEBRA'


class CulebraTests(CulebraTestCase):

    @classmethod
    def setUpClass(cls):
        cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
        cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'debug': {}, 'startviewserver': True, 'compresseddump': True}
        cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'concertina-config': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'aonoff.py', 'unit-test-method': None, 'interactive': False}
        cls.sleep = 5

    def setUp(self):
        super(CulebraTests, self).setUp()

    def tearDown(self):
        super(CulebraTests, self).tearDown()

    def preconditions(self):
        if not super(CulebraTests, self).preconditions():
            return False
        return True

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        self.vc.dump(window=-1)
        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')

        print >> sys.stderr, 'Now Airplane mode is ON, switching it back to OFF'
        self.vc.sleep(5)

        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')


if __name__ == '__main__':
    CulebraTests.main()
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • Thanks for the answer Diego, Isn't AndroidViewClient/culebra for test only? Not for actual use? What I mean actual is, physically plugging in my android device. I want to control my device, not simulators. – hyukkyulee Aug 11 '18 at 00:30
  • 1
    I don't know what you mean, but AVC/culebra can connect to any Android device or emulator and run scripts like this one. – Diego Torres Milano Aug 11 '18 at 05:25
  • Oh It means I am doing something wrong here, let me try to figure it out thanks again! – hyukkyulee Aug 12 '18 at 16:06
  • 1
    @DiegoTorresMilano I wonder if one can use AndroidViewClient/culebra to automate processes on an android phone? E.g. to switch of/on the airplane mode every N seconds. If not, what other software could you recommend for such automation? – NeStack Jun 13 '19 at 12:15
  • 2
    @NeStack sure you can. Most of the actions a real user can do can be automated using AndroidViewClient/culebra as it interprets the screen and send events – Diego Torres Milano Jun 13 '19 at 18:33