shill: cellular: Modify ActivatingIccidStore to keep track of MEIDs separately.
Renamed ActivatingIccidStore to PendingActivationStore. Modified the
public interface to interact with MEIDs separately from ICCIDs.
BUG=chromium:225135
TEST=1. Build and run unittests.
2. On link, verify that LTE activation still works. Make sure that
the ICCID gets written to a file called
"activating_iccid_store.profile" in /var/cache/shill.
Change-Id: I383bd80d222f43d354cc72b437e6b037fc40492f
Reviewed-on: https://gerrit.chromium.org/gerrit/46954
Reviewed-by: Thieu Le <thieule@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Arman Uguray <armansito@chromium.org>
Tested-by: Arman Uguray <armansito@chromium.org>
diff --git a/pending_activation_store.h b/pending_activation_store.h
new file mode 100644
index 0000000..633283b
--- /dev/null
+++ b/pending_activation_store.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_PENDING_ACTIVATION_STORE_H_
+#define SHILL_PENDING_ACTIVATION_STORE_H_
+
+#include <string>
+
+#include <base/file_path.h>
+#include <base/memory/scoped_ptr.h>
+#include <gtest/gtest_prod.h> // for FRIEND_TEST
+
+#include "shill/key_file_store.h"
+
+namespace shill {
+
+class GLib;
+class StoreInterface;
+
+// PendingActivationStore stores the network activation status for a
+// particular SIM. Once an online payment for the activation of a 3GPP
+// network is successful, the associated SIM is regarded as pending
+// activation and stored in the persistent profile. Once shill knows that
+// the activation associated with a particular SIM is successful, it is removed
+// from the profile and the cellular service is marked as activated.
+class PendingActivationStore {
+ public:
+ enum State {
+ // This state indicates that information for a particular SIM was never
+ // stored in this database.
+ kStateUnknown,
+ // This state indicates that an online payment has been made but the modem
+ // has not yet been able to register with the network.
+ kStatePending,
+ // This state indicates that the modem has registered with the network but
+ // the network has not yet confirmed that the service has been activated.
+ // Currently, shill knows that activation has gone through, when a non-zero
+ // MDN has been received OTA.
+ kStateActivated,
+ // This state indicates that a timeout has expired in which the modem
+ // failed to register to a network.
+ kStatePendingTimeout,
+ kStateMax,
+ };
+
+ enum IdentifierType {
+ kIdentifierICCID,
+ kIdentifierMEID,
+ };
+
+ // Constructor performs no initialization.
+ PendingActivationStore();
+ virtual ~PendingActivationStore();
+
+ // Tries to open the underlying store interface from the given file path.
+ // Returns false if it fails to open the file.
+ //
+ // If called more than once on the same instance, the file that was already
+ // open will allways be flushed and closed, however it is not guaranteed that
+ // the file will always be successfully reopened (technically it should, but
+ // it is not guaranteed).
+ virtual bool InitStorage(GLib *glib, const base::FilePath &storage_path);
+
+ // Returns the activation state for a SIM with the given identifier. A return
+ // value of kStateUnknown indicates that the given identifier was not found.
+ virtual State GetActivationState(IdentifierType type,
+ const std::string &identifier) const;
+
+ // Sets the activation state for the given identifier. If an entry for this
+ // identifier was not found, a new entry will be created. Returns true on
+ // success.
+ virtual bool SetActivationState(IdentifierType type,
+ const std::string &identifier,
+ State state);
+
+ // Removes the entry for the given identifier from the database. Returns true
+ // if the operation was successful. If the identifier did not exist in the
+ // database, still returns true.
+ virtual bool RemoveEntry(IdentifierType type, const std::string &identifier);
+
+ private:
+ friend class PendingActivationStoreTest;
+ friend class CellularCapabilityUniversalTest;
+ FRIEND_TEST(PendingActivationStoreTest, FileInteractions);
+ FRIEND_TEST(PendingActivationStoreTest, GetActivationState);
+ FRIEND_TEST(PendingActivationStoreTest, RemoveEntry);
+ FRIEND_TEST(PendingActivationStoreTest, SetActivationState);
+
+ static const char kIccidGroupId[];
+ static const char kMeidGroupId[];
+ static const char kStorageFileName[];
+
+ static std::string IdentifierTypeToGroupId(IdentifierType type);
+
+ scoped_ptr<StoreInterface> storage_;
+
+ DISALLOW_COPY_AND_ASSIGN(PendingActivationStore);
+};
+
+} // namespace shill
+
+#endif // SHILL_PENDING_ACTIVATION_STORE_H_