Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_SERVICE_H_ |
| 6 | #define SHILL_CELLULAR_SERVICE_H_ |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/basictypes.h> |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 12 | #include <base/time.h> |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 15 | #include "shill/cellular.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 16 | #include "shill/refptr_types.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 17 | #include "shill/service.h" |
| 18 | |
| 19 | namespace shill { |
| 20 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 21 | class ControlInterface; |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 22 | class Error; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 23 | class EventDispatcher; |
| 24 | class Manager; |
| 25 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | class CellularService : public Service { |
| 27 | public: |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 28 | static const char kStorageAPN[]; |
| 29 | static const char kStorageLastGoodAPN[]; |
| 30 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 31 | // Online payment portal. |
| 32 | class OLP { |
| 33 | public: |
| 34 | OLP(); |
| 35 | ~OLP(); |
| 36 | |
| 37 | void CopyFrom(const OLP &olp); |
| 38 | bool Equals(const OLP &olp) const; |
| 39 | |
| 40 | const std::string &GetURL() const; |
| 41 | void SetURL(const std::string &url); |
| 42 | |
| 43 | const std::string &GetMethod() const; |
| 44 | void SetMethod(const std::string &method); |
| 45 | |
| 46 | const std::string &GetPostData() const; |
| 47 | void SetPostData(const std::string &post_data); |
| 48 | |
| 49 | const Stringmap &ToDict() const; |
| 50 | |
| 51 | private: |
| 52 | Stringmap dict_; |
| 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(OLP); |
| 55 | }; |
| 56 | |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 57 | CellularService(ModemInfo *modem_info, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 58 | const CellularRefPtr &device); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 59 | virtual ~CellularService(); |
| 60 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 61 | // Inherited from Service. |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 62 | virtual void AutoConnect(); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 63 | virtual void Connect(Error *error, const char *reason); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 64 | virtual void Disconnect(Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 65 | virtual void ActivateCellularModem(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 66 | Error *error, |
| 67 | const ResultCallback &callback); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 68 | virtual void CompleteCellularActivation(Error *error); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 69 | virtual void SetState(ConnectState new_state); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 70 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 71 | virtual std::string GetStorageIdentifier() const; |
| 72 | void SetStorageIdentifier(const std::string &identifier); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 73 | |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 74 | void SetActivateOverNonCellularNetwork(bool state); |
| 75 | bool activate_over_non_cellular_network() const { |
| 76 | return activate_over_non_cellular_network_; |
| 77 | } |
| 78 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 79 | virtual void SetActivationState(const std::string &state); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 80 | const std::string &activation_state() const { return activation_state_; } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 81 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 82 | void SetOLP(const OLP &olp); |
| 83 | const OLP &olp() const { return olp_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 84 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 85 | void SetUsageURL(const std::string &url); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 86 | const std::string &usage_url() const { return usage_url_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 87 | |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 88 | void SetServingOperator(const Cellular::Operator &oper); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 89 | const Cellular::Operator &serving_operator() const; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 90 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 91 | // Sets network technology to |technology| and broadcasts the property change. |
| 92 | void SetNetworkTechnology(const std::string &technology); |
| 93 | const std::string &network_technology() const { return network_technology_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 94 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 95 | // Sets roaming state to |state| and broadcasts the property change. |
| 96 | void SetRoamingState(const std::string &state); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 97 | const std::string &roaming_state() const { return roaming_state_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 98 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 99 | bool is_auto_connecting() const { |
| 100 | return is_auto_connecting_; |
| 101 | } |
| 102 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 103 | void set_enforce_out_of_credits_detection(bool state) { |
| 104 | enforce_out_of_credits_detection_ = state; |
| 105 | } |
mukesh agrawal | 81599e0 | 2013-04-22 16:40:00 -0700 | [diff] [blame] | 106 | bool out_of_credits() const { return out_of_credits_; } |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 107 | void SetOutOfCredits(bool state); |
| 108 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 109 | // Overrides Load and Save from parent Service class. We will call |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 110 | // the parent method. |
| 111 | virtual bool Load(StoreInterface *storage); |
| 112 | virtual bool Save(StoreInterface *storage); |
| 113 | |
| 114 | Stringmap *GetUserSpecifiedApn(); |
| 115 | Stringmap *GetLastGoodApn(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 116 | virtual void SetLastGoodApn(const Stringmap &apn_info); |
| 117 | virtual void ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 118 | |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 119 | virtual void OnAfterResume(); |
| 120 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 121 | protected: |
| 122 | // Overrides IsAutoConnectable from parent Service class. |
| 123 | virtual bool IsAutoConnectable(const char **reason) const; |
| 124 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 125 | private: |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 126 | friend class CellularCapabilityUniversalTest; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 127 | friend class CellularServiceTest; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 128 | FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList); |
| 129 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 130 | FRIEND_TEST(CellularCapabilityUniversalMainTest, |
| 131 | UpdatePendingActivationState); |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 132 | FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateServiceName); |
| 133 | FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 134 | FRIEND_TEST(CellularTest, Connect); |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 135 | FRIEND_TEST(CellularTest, OnConnectionHealthCheckerResult); |
Eric Shienbrood | c707330 | 2012-04-03 14:41:44 -0400 | [diff] [blame] | 136 | FRIEND_TEST(CellularServiceTest, SetApn); |
| 137 | FRIEND_TEST(CellularServiceTest, ClearApn); |
| 138 | FRIEND_TEST(CellularServiceTest, LastGoodApn); |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 139 | FRIEND_TEST(CellularServiceTest, IsAutoConnectable); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 140 | FRIEND_TEST(CellularServiceTest, OutOfCreditsDetected); |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 141 | FRIEND_TEST(CellularServiceTest, |
| 142 | OutOfCreditsDetectionNotSkippedAfterSlowResume); |
Thieu Le | 3a8683d | 2013-04-17 13:57:24 -0700 | [diff] [blame] | 143 | FRIEND_TEST(CellularServiceTest, OutOfCreditsDetectionSkippedAfterResume); |
| 144 | FRIEND_TEST(CellularServiceTest, |
| 145 | OutOfCreditsDetectionSkippedAlreadyOutOfCredits); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 146 | FRIEND_TEST(CellularServiceTest, |
| 147 | OutOfCreditsDetectionSkippedExplicitDisconnect); |
| 148 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotDetectedConnectionNotDropped); |
| 149 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotDetectedIntermittentNetwork); |
| 150 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotEnforced); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 151 | FRIEND_TEST(CellularServiceTest, CustomSetterNoopChange); |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 152 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 153 | static const char kAutoConnActivating[]; |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 154 | static const char kAutoConnDeviceDisabled[]; |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 155 | static const char kAutoConnOutOfCredits[]; |
| 156 | static const char kAutoConnOutOfCreditsDetectionInProgress[]; |
| 157 | static const int64 kOutOfCreditsConnectionDropSeconds; |
| 158 | static const int kOutOfCreditsMaxConnectAttempts; |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 159 | static const int64 kOutOfCreditsResumeIgnoreSeconds; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 160 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 161 | void HelpRegisterDerivedStringmap( |
| 162 | const std::string &name, |
| 163 | Stringmap(CellularService::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 164 | bool(CellularService::*set)(const Stringmap &value, Error *error)); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 165 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 166 | virtual std::string GetDeviceRpcId(Error *error); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 167 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 168 | Stringmap GetApn(Error *error); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 169 | bool SetApn(const Stringmap &value, Error *error); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 170 | static void SaveApn(StoreInterface *storage, |
| 171 | const std::string &storage_group, |
| 172 | const Stringmap *apn_info, |
| 173 | const std::string &keytag); |
| 174 | static void SaveApnField(StoreInterface *storage, |
| 175 | const std::string &storage_group, |
| 176 | const Stringmap *apn_info, |
| 177 | const std::string &keytag, |
| 178 | const std::string &apntag); |
| 179 | static void LoadApn(StoreInterface *storage, |
| 180 | const std::string &storage_group, |
| 181 | const std::string &keytag, |
| 182 | Stringmap *apn_info); |
| 183 | static bool LoadApnField(StoreInterface *storage, |
| 184 | const std::string &storage_group, |
| 185 | const std::string &keytag, |
| 186 | const std::string &apntag, |
| 187 | Stringmap *apn_info); |
| 188 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 189 | void PerformOutOfCreditsDetection(ConnectState curr_state, |
| 190 | ConnectState new_state); |
| 191 | void OutOfCreditsReconnect(); |
| 192 | void ResetOutOfCreditsState(); |
| 193 | |
| 194 | base::WeakPtrFactory<CellularService> weak_ptr_factory_; |
| 195 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 196 | // Properties |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 197 | bool activate_over_non_cellular_network_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 198 | std::string activation_state_; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 199 | Cellular::Operator serving_operator_; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 200 | std::string network_technology_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 201 | std::string roaming_state_; |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 202 | OLP olp_; |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 203 | std::string usage_url_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 204 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 205 | Stringmap apn_info_; |
| 206 | Stringmap last_good_apn_info_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 207 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 208 | std::string storage_identifier_; |
| 209 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 210 | CellularRefPtr cellular_; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 211 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 212 | // Flag indicating that a connect request is an auto-connect request. |
| 213 | // Note: Since Connect() is asynchronous, this flag is only set during the |
| 214 | // call to Connect(). It does not remain set while the async request is |
| 215 | // in flight. |
| 216 | bool is_auto_connecting_; |
| 217 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 218 | // Flag indicating whether we need to perform out-of-credits detection. |
| 219 | bool enforce_out_of_credits_detection_; |
| 220 | // Time when the last connect request started. |
| 221 | base::Time connect_start_time_; |
| 222 | // Number of connect attempts. |
| 223 | int num_connect_attempts_; |
| 224 | // Flag indicating whether out-of-credits detection is in progress. |
| 225 | bool out_of_credits_detection_in_progress_; |
| 226 | // Flag indicating if the SIM is out-of-credits. |
| 227 | bool out_of_credits_; |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 228 | // Time when the last resume occurred. |
| 229 | base::Time resume_start_time_; |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 230 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 231 | DISALLOW_COPY_AND_ASSIGN(CellularService); |
| 232 | }; |
| 233 | |
| 234 | } // namespace shill |
| 235 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 236 | #endif // SHILL_CELLULAR_SERVICE_H_ |