• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #pragma once
17 
18 #include <android-base/macros.h>
19 #include <android-base/thread_annotations.h>
20 
21 #include <map>
22 #include <set>
23 #include <span>
24 
25 namespace android::hardware::radio::minimal::sim {
26 
27 class Filesystem {
28   public:
29     /** 3GPP TS 27.007 8.18 */
30     struct Path {
31         int32_t fileId;
32         std::string pathId;
33         auto operator<=>(const Path&) const = default;
34         std::string toString() const;
35     };
36 
37     typedef std::span<uint8_t const> FileView;
38 
39   private:
40     mutable std::mutex mFilesGuard;
41     std::map<Path, std::vector<uint8_t>> mFiles GUARDED_BY(mFilesGuard);
42     std::set<int32_t> mUpdates GUARDED_BY(mFilesGuard);
43 
44     DISALLOW_COPY_AND_ASSIGN(Filesystem);
45 
46   public:
47     Filesystem();
48 
49     void write(const Path& path, FileView contents);
50     void write(const Path& path, std::string_view contents);
51     void write(const Path& path, std::vector<uint8_t>&& contents);
52     std::optional<FileView> read(const Path& path) const;
53 
54     void writeBch(const Path& path, std::string_view contents);
55     std::optional<std::string> readBch(const Path& path) const;
56 
57     std::optional<Path> find(uint16_t fileId);
58 
59     std::set<int32_t> fetchAndClearUpdates();
60 };
61 
62 namespace paths {
63 
64 extern const Filesystem::Path mf;
65 extern const Filesystem::Path fplmn;
66 extern const Filesystem::Path iccid;
67 extern const Filesystem::Path msisdn;
68 extern const Filesystem::Path pl;
69 extern const Filesystem::Path arr;
70 extern const Filesystem::Path ad;
71 
72 }  // namespace paths
73 
74 }  // namespace android::hardware::radio::minimal::sim
75