blob: dd58ec9d0b42abedaf7784b72c47dba686c77504 [file] [log] [blame]
Arman Uguray41cc6342013-03-29 16:34:39 -07001// 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
Ben Chanc20ed132014-10-16 12:25:03 -07008#include <memory>
Arman Uguray41cc6342013-03-29 16:34:39 -07009#include <string>
10
Ben Chana0ddf462014-02-06 11:32:42 -080011#include <base/files/file_path.h>
Arman Uguray41cc6342013-03-29 16:34:39 -070012#include <gtest/gtest_prod.h> // for FRIEND_TEST
13
14#include "shill/key_file_store.h"
15
16namespace shill {
17
18class GLib;
19class 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.
27class 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,
Arman Uguray0a3e2792013-01-17 16:31:50 -080041 // This state is used in CDMA activation to indicate that OTA activation
42 // failed and was scheduled for a retry.
43 kStateFailureRetry,
Arman Uguray41cc6342013-03-29 16:34:39 -070044 kStateMax,
45 };
46
47 enum IdentifierType {
48 kIdentifierICCID,
49 kIdentifierMEID,
50 };
51
52 // Constructor performs no initialization.
53 PendingActivationStore();
54 virtual ~PendingActivationStore();
55
56 // Tries to open the underlying store interface from the given file path.
57 // Returns false if it fails to open the file.
58 //
59 // If called more than once on the same instance, the file that was already
60 // open will allways be flushed and closed, however it is not guaranteed that
61 // the file will always be successfully reopened (technically it should, but
62 // it is not guaranteed).
63 virtual bool InitStorage(GLib *glib, const base::FilePath &storage_path);
64
65 // Returns the activation state for a SIM with the given identifier. A return
66 // value of kStateUnknown indicates that the given identifier was not found.
67 virtual State GetActivationState(IdentifierType type,
68 const std::string &identifier) const;
69
70 // Sets the activation state for the given identifier. If an entry for this
71 // identifier was not found, a new entry will be created. Returns true on
72 // success.
73 virtual bool SetActivationState(IdentifierType type,
74 const std::string &identifier,
75 State state);
76
77 // Removes the entry for the given identifier from the database. Returns true
78 // if the operation was successful. If the identifier did not exist in the
79 // database, still returns true.
80 virtual bool RemoveEntry(IdentifierType type, const std::string &identifier);
81
82 private:
83 friend class PendingActivationStoreTest;
84 friend class CellularCapabilityUniversalTest;
85 FRIEND_TEST(PendingActivationStoreTest, FileInteractions);
86 FRIEND_TEST(PendingActivationStoreTest, GetActivationState);
87 FRIEND_TEST(PendingActivationStoreTest, RemoveEntry);
88 FRIEND_TEST(PendingActivationStoreTest, SetActivationState);
89
90 static const char kIccidGroupId[];
91 static const char kMeidGroupId[];
92 static const char kStorageFileName[];
93
94 static std::string IdentifierTypeToGroupId(IdentifierType type);
95
Ben Chanc20ed132014-10-16 12:25:03 -070096 std::unique_ptr<StoreInterface> storage_;
Arman Uguray41cc6342013-03-29 16:34:39 -070097
98 DISALLOW_COPY_AND_ASSIGN(PendingActivationStore);
99};
100
101} // namespace shill
102
103#endif // SHILL_PENDING_ACTIVATION_STORE_H_