Home | History | Annotate | Download | only in files
      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 gobject
      8 
      9 from autotest_lib.client.cros.cellular.pseudomodem import modem_cdma
     10 from autotest_lib.client.cros.cellular.pseudomodem import pm_errors
     11 from autotest_lib.client.cros.cellular.pseudomodem import utils as pm_utils
     12 
     13 I_ACTIVATION_TEST = 'Interface.CDMAActivationTest'
     14 
     15 class UnactivatedCdmaModem(modem_cdma.ModemCdma):
     16     """ A |ModemCDMA| subclass that starts off unactivated. """
     17     def __init__(self):
     18         super(UnactivatedCdmaModem, self).__init__(
     19                 home_network=modem_cdma.ModemCdma.CdmaNetwork(activated=False))
     20 
     21 
     22 class ActivationRetryModem(modem_cdma.ModemCdma):
     23     """
     24     TestModem to test that shill retries OTASP activation until it succeeds.
     25 
     26     """
     27     def __init__(self, num_activate_retries):
     28         # This assignment is needed before the call to super.__init__(...)
     29         self.activate_count = 0
     30         super(ActivationRetryModem, self).__init__(
     31                 home_network=modem_cdma.ModemCdma.CdmaNetwork(activated=False))
     32         self._num_activate_retries = num_activate_retries
     33 
     34 
     35     def _InitializeProperties(self):
     36         props = super(ActivationRetryModem, self)._InitializeProperties()
     37 
     38         # For the purposes of this test, introduce a property that
     39         # stores how many times "Activate" has been called on this
     40         # modem.
     41         props[I_ACTIVATION_TEST] = {
     42             'ActivateCount' : dbus.types.UInt32(self.activate_count)
     43         }
     44         return props
     45 
     46 
     47     def _IncrementActivateCount(self):
     48         self.activate_count += 1
     49         self.Set(I_ACTIVATION_TEST,
     50                  'ActivateCount',
     51                  self.activate_count)
     52 
     53 
     54     @pm_utils.log_dbus_method(return_cb_arg='return_cb',
     55                               raise_cb_arg='raise_cb')
     56     def Activate(self, carrier, return_cb, raise_cb):
     57         """
     58         Activation will only succeed on the NUM_ACTIVATE_RETRIESth try.
     59 
     60         """
     61         self._IncrementActivateCount()
     62         if (self.activate_count == self._num_activate_retries):
     63             super(ActivationRetryModem, self).Activate(
     64                     carrier, return_cb, raise_cb)
     65         else:
     66             def _raise_activation_error():
     67                 raise_cb(pm_errors.MMCdmaActivationError(
     68                          pm_errors.MMCdmaActivationError.START_FAILED))
     69             gobject.idle_add(_raise_activation_error)
     70