1 # Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import dbus 6 import dbus.types 7 import time 8 9 from autotest_lib.client.cros.cellular import mm1_constants 10 from autotest_lib.client.cros.cellular.pseudomodem import modem_3gpp 11 from autotest_lib.client.cros.cellular.pseudomodem import sim 12 from autotest_lib.client.cros.cellular.pseudomodem import utils as pm_utils 13 14 I_ACTIVATION_TEST = 'Interface.LTEActivationTest' 15 16 class TestModem(modem_3gpp.Modem3gpp): 17 """ 18 Base class for the custom 3GPP fake modems that are defined in this test. 19 This modem boots up as unprovisioned & becomes activated only if it has 20 been explicitly activated by calling CompleteCellularActivation 21 22 """ 23 def __init__(self, 24 state_machine_factory=None, 25 bus=None, 26 device='pseudomodem0', 27 index=0, 28 roaming_networks=None, 29 config=None): 30 super(TestModem, self).__init__(state_machine_factory, 31 bus=bus, 32 device=device, 33 roaming_networks=roaming_networks, 34 config=config) 35 # Update the registered susbscription state as unprovisioned 36 # for this activation test 37 self._cached_registered_subscription_state = ( 38 mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_UNPROVISIONED) 39 40 41 def _InitializeProperties(self): 42 props = modem_3gpp.Modem3gpp._InitializeProperties(self) 43 modem_props = props[mm1_constants.I_MODEM] 44 modem_props['OwnNumbers'] = ['0000000000'] 45 modem_props['AccessTechnologies'] = dbus.types.UInt32( 46 mm1_constants.MM_MODEM_ACCESS_TECHNOLOGY_LTE) 47 modem_props['ModemCapabilities'] = dbus.types.UInt32( 48 mm1_constants.MM_MODEM_CAPABILITY_LTE) 49 modem_props['CurrentCapabilities'] = dbus.types.UInt32( 50 mm1_constants.MM_MODEM_CAPABILITY_LTE) 51 52 # For the purposes of this test, introduce a property to help 53 # verify that a reset has taken place. Expose this under a test 54 # specific interface. 55 if hasattr(self, '_properties'): 56 reset_called = \ 57 self._properties[I_ACTIVATION_TEST]['ResetCalled'] 58 else: 59 reset_called = False 60 props[I_ACTIVATION_TEST] = { 61 'ResetCalled' : dbus.types.Boolean(reset_called) 62 } 63 return props 64 65 66 @pm_utils.log_dbus_method() 67 def Reset(self): 68 self.Set( 69 I_ACTIVATION_TEST, 'ResetCalled', dbus.types.Boolean(True)) 70 modem_3gpp.Modem3gpp.Reset(self) 71 72 73 class ResetRequiredForActivationModem(TestModem): 74 """ 75 Fake modem boots up as unprovisioned & becomes activated only if it has 76 been explicitly activated by calling CompleteCellularActivation 77 and has been reset at least once after initiating activatation 78 """ 79 def RegisterWithNetwork( 80 self, operator_id='', return_cb=None, raise_cb=None): 81 if self.Get(I_ACTIVATION_TEST, 'ResetCalled'): 82 modem_3gpp.Modem3gpp.RegisterWithNetwork( 83 self, operator_id, return_cb, raise_cb) 84 85 86 class TestSIM(sim.SIM): 87 """ SIM instantiated with the default test network, for ease of use. """ 88 def __init__(self): 89 # Shill's activating ICCID store tracks which SIM identifiers are in 90 # the process of activation. If we use the same SIM identifier for 91 # every test pass, then a failed test may leave a stale entry in the 92 # activating ICCD store which will erroneously mark the SIM as pending 93 # activation. So, to avoid this, try to use a unique SIM identifier 94 # each time. 95 sim_identifier = int(time.time()) 96 sim.SIM.__init__( 97 self, 98 sim.SIM.Carrier('test'), 99 mm1_constants.MM_MODEM_ACCESS_TECHNOLOGY_LTE, 100 msin=str(sim_identifier)) 101