Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 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 | |
| 5 | #ifndef SHILL_PENDING_ACTIVATION_STORE_H_ |
| 6 | #define SHILL_PENDING_ACTIVATION_STORE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/file_path.h> |
| 11 | #include <base/memory/scoped_ptr.h> |
| 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 13 | |
| 14 | #include "shill/key_file_store.h" |
| 15 | |
| 16 | namespace shill { |
| 17 | |
| 18 | class GLib; |
| 19 | class StoreInterface; |
| 20 | |
| 21 | // PendingActivationStore stores the network activation status for a |
| 22 | // particular SIM. Once an online payment for the activation of a 3GPP |
| 23 | // network is successful, the associated SIM is regarded as pending |
| 24 | // activation and stored in the persistent profile. Once shill knows that |
| 25 | // the activation associated with a particular SIM is successful, it is removed |
| 26 | // from the profile and the cellular service is marked as activated. |
| 27 | class PendingActivationStore { |
| 28 | public: |
| 29 | enum State { |
| 30 | // This state indicates that information for a particular SIM was never |
| 31 | // stored in this database. |
| 32 | kStateUnknown, |
| 33 | // This state indicates that an online payment has been made but the modem |
| 34 | // has not yet been able to register with the network. |
| 35 | kStatePending, |
| 36 | // This state indicates that the modem has registered with the network but |
| 37 | // the network has not yet confirmed that the service has been activated. |
| 38 | // Currently, shill knows that activation has gone through, when a non-zero |
| 39 | // MDN has been received OTA. |
| 40 | kStateActivated, |
| 41 | // This state indicates that a timeout has expired in which the modem |
| 42 | // failed to register to a network. |
| 43 | kStatePendingTimeout, |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 44 | // This state is used in CDMA activation to indicate that OTA activation |
| 45 | // failed and was scheduled for a retry. |
| 46 | kStateFailureRetry, |
Arman Uguray | 41cc634 | 2013-03-29 16:34:39 -0700 | [diff] [blame] | 47 | kStateMax, |
| 48 | }; |
| 49 | |
| 50 | enum IdentifierType { |
| 51 | kIdentifierICCID, |
| 52 | kIdentifierMEID, |
| 53 | }; |
| 54 | |
| 55 | // Constructor performs no initialization. |
| 56 | PendingActivationStore(); |
| 57 | virtual ~PendingActivationStore(); |
| 58 | |
| 59 | // Tries to open the underlying store interface from the given file path. |
| 60 | // Returns false if it fails to open the file. |
| 61 | // |
| 62 | // If called more than once on the same instance, the file that was already |
| 63 | // open will allways be flushed and closed, however it is not guaranteed that |
| 64 | // the file will always be successfully reopened (technically it should, but |
| 65 | // it is not guaranteed). |
| 66 | virtual bool InitStorage(GLib *glib, const base::FilePath &storage_path); |
| 67 | |
| 68 | // Returns the activation state for a SIM with the given identifier. A return |
| 69 | // value of kStateUnknown indicates that the given identifier was not found. |
| 70 | virtual State GetActivationState(IdentifierType type, |
| 71 | const std::string &identifier) const; |
| 72 | |
| 73 | // Sets the activation state for the given identifier. If an entry for this |
| 74 | // identifier was not found, a new entry will be created. Returns true on |
| 75 | // success. |
| 76 | virtual bool SetActivationState(IdentifierType type, |
| 77 | const std::string &identifier, |
| 78 | State state); |
| 79 | |
| 80 | // Removes the entry for the given identifier from the database. Returns true |
| 81 | // if the operation was successful. If the identifier did not exist in the |
| 82 | // database, still returns true. |
| 83 | virtual bool RemoveEntry(IdentifierType type, const std::string &identifier); |
| 84 | |
| 85 | private: |
| 86 | friend class PendingActivationStoreTest; |
| 87 | friend class CellularCapabilityUniversalTest; |
| 88 | FRIEND_TEST(PendingActivationStoreTest, FileInteractions); |
| 89 | FRIEND_TEST(PendingActivationStoreTest, GetActivationState); |
| 90 | FRIEND_TEST(PendingActivationStoreTest, RemoveEntry); |
| 91 | FRIEND_TEST(PendingActivationStoreTest, SetActivationState); |
| 92 | |
| 93 | static const char kIccidGroupId[]; |
| 94 | static const char kMeidGroupId[]; |
| 95 | static const char kStorageFileName[]; |
| 96 | |
| 97 | static std::string IdentifierTypeToGroupId(IdentifierType type); |
| 98 | |
| 99 | scoped_ptr<StoreInterface> storage_; |
| 100 | |
| 101 | DISALLOW_COPY_AND_ASSIGN(PendingActivationStore); |
| 102 | }; |
| 103 | |
| 104 | } // namespace shill |
| 105 | |
| 106 | #endif // SHILL_PENDING_ACTIVATION_STORE_H_ |