• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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
5import logging
6
7import connect_machine
8import pm_errors
9
10from autotest_lib.client.cros.cellular import mm1_constants
11
12class ConnectCdmaMachine(connect_machine.ConnectMachine):
13    """
14    ConnectCdmaMachine handles CDMA specific logic that is involved in
15    connecting to a network.
16
17    """
18    def _HandleRegisteredState(self):
19        logging.info('ConnectCdmaMachine: Modem is REGISTERED.')
20        assert not self._modem.IsPendingDisconnect()
21        assert not self._modem.IsPendingEnable()
22        assert not self._modem.IsPendingDisable()
23        assert not self._modem.IsPendingRegister()
24
25        # Check here that the network is activated. The UI should prevent
26        # connecting to an unactivated service, but for tests, we want to be
27        # sure that connect fails.
28        network = self._modem.GetHomeNetwork()
29        if not network.activated:
30            logging.info('ConnectCdmaMachine: Service is not activated. Cannot'
31                         ' connect.')
32            self.raise_cb(pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED,
33                                                'Service not activated.'))
34            return False
35
36        logging.info('ConnectCdmaMachine: Setting state to CONNECTING.')
37        reason = mm1_constants.MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED
38        self._modem.ChangeState(mm1_constants.MM_MODEM_STATE_CONNECTING,
39                                reason)
40        return True
41
42
43    def _GetModemStateFunctionMap(self):
44        fmap = super(ConnectCdmaMachine, self)._GetModemStateFunctionMap()
45        fmap[mm1_constants.MM_MODEM_STATE_REGISTERED] = \
46            ConnectCdmaMachine._HandleRegisteredState
47        return fmap
48