blob: 8af31e1117256e0226014d48a6565fe91d2d1502 [file] [log] [blame]
Darin Petkovb9c99332012-01-12 13:13:00 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Chris Masone3bd3c8c2011-06-13 08:20:26 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Chan19f83972012-10-03 23:25:56 -07005#ifndef SHILL_CELLULAR_SERVICE_H_
6#define SHILL_CELLULAR_SERVICE_H_
Chris Masone3bd3c8c2011-06-13 08:20:26 -07007
8#include <map>
9#include <string>
10
11#include <base/basictypes.h>
Darin Petkovb72cf402011-11-22 14:51:39 +010012#include <gtest/gtest_prod.h> // for FRIEND_TEST
Chris Masone3bd3c8c2011-06-13 08:20:26 -070013
Darin Petkov3335b372011-08-22 11:05:32 -070014#include "shill/cellular.h"
Chris Masone2b105542011-06-22 10:58:09 -070015#include "shill/refptr_types.h"
Chris Masone3bd3c8c2011-06-13 08:20:26 -070016#include "shill/service.h"
17
18namespace shill {
19
Chris Masone6791a432011-07-12 13:23:19 -070020class ControlInterface;
Darin Petkovb100ae72011-08-24 16:19:45 -070021class Error;
Chris Masone6791a432011-07-12 13:23:19 -070022class EventDispatcher;
23class Manager;
24
Chris Masone3bd3c8c2011-06-13 08:20:26 -070025class CellularService : public Service {
26 public:
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040027 static const char kStorageAPN[];
28 static const char kStorageLastGoodAPN[];
29
Darin Petkov381928f2012-02-02 23:00:12 +010030 // Online payment portal.
31 class OLP {
32 public:
33 OLP();
34 ~OLP();
35
36 void CopyFrom(const OLP &olp);
37 bool Equals(const OLP &olp) const;
38
39 const std::string &GetURL() const;
40 void SetURL(const std::string &url);
41
42 const std::string &GetMethod() const;
43 void SetMethod(const std::string &method);
44
45 const std::string &GetPostData() const;
46 void SetPostData(const std::string &post_data);
47
48 const Stringmap &ToDict() const;
49
50 private:
51 Stringmap dict_;
52
53 DISALLOW_COPY_AND_ASSIGN(OLP);
54 };
55
Chris Masone3bd3c8c2011-06-13 08:20:26 -070056 CellularService(ControlInterface *control_interface,
57 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080058 Metrics *metrics,
Chris Masone6791a432011-07-12 13:23:19 -070059 Manager *manager,
mukesh agrawal51a7e932011-07-27 16:18:26 -070060 const CellularRefPtr &device);
Darin Petkovd9661952011-08-03 16:25:42 -070061 virtual ~CellularService();
62
Darin Petkovc408e692011-08-17 13:47:15 -070063 // Inherited from Service.
Darin Petkov4d6d9412011-08-24 13:19:54 -070064 virtual void Connect(Error *error);
Darin Petkovfb0625e2012-01-16 13:05:56 +010065 virtual void Disconnect(Error *error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050066 virtual void ActivateCellularModem(const std::string &carrier,
Eric Shienbrood9a245532012-03-07 14:20:39 -050067 Error *error,
68 const ResultCallback &callback);
Darin Petkovc408e692011-08-17 13:47:15 -070069
Darin Petkov31332412012-01-28 01:50:02 +010070 virtual std::string GetStorageIdentifier() const;
71 void SetStorageIdentifier(const std::string &identifier);
Chris Masone34af2182011-08-22 11:59:36 -070072
Ben Chan3d6de0e2012-12-10 12:01:34 -080073 void SetActivateOverNonCellularNetwork(bool state);
74 bool activate_over_non_cellular_network() const {
75 return activate_over_non_cellular_network_;
76 }
77
Darin Petkovb9c99332012-01-12 13:13:00 +010078 void SetActivationState(const std::string &state);
Darin Petkovc408e692011-08-17 13:47:15 -070079 const std::string &activation_state() const { return activation_state_; }
Chris Masone3bd3c8c2011-06-13 08:20:26 -070080
Darin Petkov381928f2012-02-02 23:00:12 +010081 void SetOLP(const OLP &olp);
82 const OLP &olp() const { return olp_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070083
Darin Petkov381928f2012-02-02 23:00:12 +010084 void SetUsageURL(const std::string &url);
Darin Petkovb27e5442011-08-16 14:36:45 -070085 const std::string &usage_url() const { return usage_url_; }
Darin Petkovb27e5442011-08-16 14:36:45 -070086
Darin Petkov9cb02682012-01-28 00:17:38 +010087 void SetServingOperator(const Cellular::Operator &oper);
Darin Petkov3335b372011-08-22 11:05:32 -070088 const Cellular::Operator &serving_operator() const;
Darin Petkov3335b372011-08-22 11:05:32 -070089
Darin Petkovb72cf402011-11-22 14:51:39 +010090 // Sets network technology to |technology| and broadcasts the property change.
91 void SetNetworkTechnology(const std::string &technology);
92 const std::string &network_technology() const { return network_technology_; }
Darin Petkovd2045802011-08-23 11:09:25 -070093
Darin Petkovb72cf402011-11-22 14:51:39 +010094 // Sets roaming state to |state| and broadcasts the property change.
95 void SetRoamingState(const std::string &state);
Darin Petkovd2045802011-08-23 11:09:25 -070096 const std::string &roaming_state() const { return roaming_state_; }
Darin Petkovd2045802011-08-23 11:09:25 -070097
Ben Chan19f83972012-10-03 23:25:56 -070098 // Overrides Load and Save from parent Service class. We will call
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040099 // the parent method.
100 virtual bool Load(StoreInterface *storage);
101 virtual bool Save(StoreInterface *storage);
102
103 Stringmap *GetUserSpecifiedApn();
104 Stringmap *GetLastGoodApn();
Jason Glasgow14521872012-05-07 19:12:15 -0400105 virtual void SetLastGoodApn(const Stringmap &apn_info);
106 virtual void ClearLastGoodApn();
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400107
Ben Chan19f83972012-10-03 23:25:56 -0700108 protected:
109 // Overrides IsAutoConnectable from parent Service class.
110 virtual bool IsAutoConnectable(const char **reason) const;
111
Paul Stewartac4ac002011-08-26 12:04:26 -0700112 private:
Arman Ugurayc9533572013-01-22 17:34:20 -0800113 friend class CellularCapabilityUniversalTest;
Darin Petkovb72cf402011-11-22 14:51:39 +0100114 friend class CellularServiceTest;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400115 FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList);
116 FRIEND_TEST(CellularCapabilityTest, TryApns);
Arman Ugurayc9533572013-01-22 17:34:20 -0800117 FRIEND_TEST(CellularCapabilityUniversalTest, UpdateStorageIdentifier);
Darin Petkovb72cf402011-11-22 14:51:39 +0100118 FRIEND_TEST(CellularTest, Connect);
Eric Shienbroodc7073302012-04-03 14:41:44 -0400119 FRIEND_TEST(CellularServiceTest, SetApn);
120 FRIEND_TEST(CellularServiceTest, ClearApn);
121 FRIEND_TEST(CellularServiceTest, LastGoodApn);
Ben Chan19f83972012-10-03 23:25:56 -0700122 FRIEND_TEST(CellularServiceTest, IsAutoConnectable);
123
Christopher Wiley1582bdd2012-11-15 11:31:14 -0800124 static const char kAutoConnActivating[];
Ben Chan19f83972012-10-03 23:25:56 -0700125 static const char kAutoConnDeviceDisabled[];
Darin Petkovb72cf402011-11-22 14:51:39 +0100126
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400127 void HelpRegisterDerivedStringmap(
128 const std::string &name,
129 Stringmap(CellularService::*get)(Error *error),
130 void(CellularService::*set)(const Stringmap &value, Error *error));
131
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800132 virtual std::string GetDeviceRpcId(Error *error);
Paul Stewartac4ac002011-08-26 12:04:26 -0700133
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400134 Stringmap GetApn(Error *error);
135 void SetApn(const Stringmap &value, Error *error);
136 static void SaveApn(StoreInterface *storage,
137 const std::string &storage_group,
138 const Stringmap *apn_info,
139 const std::string &keytag);
140 static void SaveApnField(StoreInterface *storage,
141 const std::string &storage_group,
142 const Stringmap *apn_info,
143 const std::string &keytag,
144 const std::string &apntag);
145 static void LoadApn(StoreInterface *storage,
146 const std::string &storage_group,
147 const std::string &keytag,
148 Stringmap *apn_info);
149 static bool LoadApnField(StoreInterface *storage,
150 const std::string &storage_group,
151 const std::string &keytag,
152 const std::string &apntag,
153 Stringmap *apn_info);
154
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700155 // Properties
Ben Chan3d6de0e2012-12-10 12:01:34 -0800156 bool activate_over_non_cellular_network_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700157 std::string activation_state_;
Darin Petkov3335b372011-08-22 11:05:32 -0700158 Cellular::Operator serving_operator_;
Darin Petkovb72cf402011-11-22 14:51:39 +0100159 std::string network_technology_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700160 std::string roaming_state_;
Darin Petkov381928f2012-02-02 23:00:12 +0100161 OLP olp_;
Darin Petkovb27e5442011-08-16 14:36:45 -0700162 std::string usage_url_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700163
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -0400164 Stringmap apn_info_;
165 Stringmap last_good_apn_info_;
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700166
Darin Petkov31332412012-01-28 01:50:02 +0100167 std::string storage_identifier_;
168
Chris Masone2b105542011-06-22 10:58:09 -0700169 CellularRefPtr cellular_;
Darin Petkovd9661952011-08-03 16:25:42 -0700170
Chris Masone3bd3c8c2011-06-13 08:20:26 -0700171 DISALLOW_COPY_AND_ASSIGN(CellularService);
172};
173
174} // namespace shill
175
Ben Chan19f83972012-10-03 23:25:56 -0700176#endif // SHILL_CELLULAR_SERVICE_H_