• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_PENDING_ACTIVATION_STORE_H_
18 #define SHILL_PENDING_ACTIVATION_STORE_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include <base/files/file_path.h>
24 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
25 
26 namespace shill {
27 
28 class StoreInterface;
29 
30 // PendingActivationStore stores the network activation status for a
31 // particular SIM. Once an online payment for the activation of a 3GPP
32 // network is successful, the associated SIM is regarded as pending
33 // activation and stored in the persistent profile. Once shill knows that
34 // the activation associated with a particular SIM is successful, it is removed
35 // from the profile and the cellular service is marked as activated.
36 class PendingActivationStore {
37  public:
38   enum State {
39     // This state indicates that information for a particular SIM was never
40     // stored in this database.
41     kStateUnknown,
42     // This state indicates that an online payment has been made but the modem
43     // has not yet been able to register with the network.
44     kStatePending,
45     // This state indicates that the modem has registered with the network but
46     // the network has not yet confirmed that the service has been activated.
47     // Currently, shill knows that activation has gone through, when a non-zero
48     // MDN has been received OTA.
49     kStateActivated,
50     // This state is used in CDMA activation to indicate that OTA activation
51     // failed and was scheduled for a retry.
52     kStateFailureRetry,
53     kStateMax,
54   };
55 
56   enum IdentifierType {
57     kIdentifierICCID,
58     kIdentifierMEID,
59   };
60 
61   // Constructor performs no initialization.
62   PendingActivationStore();
63   virtual ~PendingActivationStore();
64 
65   // Tries to open the underlying store interface from the given file path.
66   // Returns false if it fails to open the file.
67   //
68   // If called more than once on the same instance, the file that was already
69   // open will allways be flushed and closed, however it is not guaranteed that
70   // the file will always be successfully reopened (technically it should, but
71   // it is not guaranteed).
72   virtual bool InitStorage(const base::FilePath& storage_path);
73 
74   // Returns the activation state for a SIM with the given identifier. A return
75   // value of kStateUnknown indicates that the given identifier was not found.
76   virtual State GetActivationState(IdentifierType type,
77                                    const std::string& identifier) const;
78 
79   // Sets the activation state for the given identifier. If an entry for this
80   // identifier was not found, a new entry will be created. Returns true on
81   // success.
82   virtual bool SetActivationState(IdentifierType type,
83                                   const std::string& identifier,
84                                   State state);
85 
86   // Removes the entry for the given identifier from the database. Returns true
87   // if the operation was successful. If the identifier did not exist in the
88   // database, still returns true.
89   virtual bool RemoveEntry(IdentifierType type, const std::string& identifier);
90 
91  private:
92   friend class PendingActivationStoreTest;
93   friend class CellularCapabilityUniversalTest;
94   FRIEND_TEST(PendingActivationStoreTest, FileInteractions);
95   FRIEND_TEST(PendingActivationStoreTest, GetActivationState);
96   FRIEND_TEST(PendingActivationStoreTest, RemoveEntry);
97   FRIEND_TEST(PendingActivationStoreTest, SetActivationState);
98 
99   static const char kIccidGroupId[];
100   static const char kMeidGroupId[];
101   static const char kStorageFileName[];
102 
103   static std::string IdentifierTypeToGroupId(IdentifierType type);
104 
105   std::unique_ptr<StoreInterface> storage_;
106 
107   DISALLOW_COPY_AND_ASSIGN(PendingActivationStore);
108 };
109 
110 }  // namespace shill
111 
112 #endif  // SHILL_PENDING_ACTIVATION_STORE_H_
113