4 // key names for properties we use
6 extern const char* key;
7 extern const char* ref;
8 extern const char* is_default;
12 * Class to store data on the unencrypted folder of a device.
13 * Note that the folder must exist before this class is constructed.
14 * All names must be valid single level (no '/') file or directory names
15 * Data is organized hierarchically so we can get a child folder
17 class UnencryptedProperties
20 // Get path of folder. Must create before using any properties
21 // This is to allow proper setting of SELinux policy
22 static std::string GetPath(const char* device);
24 // Opens properties folder on named device.
25 // If folder does not exist, OK will return false, all
26 // getters will return default properties and setters will fail.
27 UnencryptedProperties(const char* device);
29 // Get named object. Return default if object does not exist or error.
30 template<typename t> t Get(const char* name, t default_value = t()) const;
32 // Set named object. Return true if success, false otherwise
33 template<typename t> bool Set(const char* name, t const& value);
35 // Get child properties
36 UnencryptedProperties GetChild(const char* name) const;
38 // Remove named object
39 bool Remove(const char* name);
45 UnencryptedProperties();
50 template<typename t> t UnencryptedProperties::Get(const char* name,
51 t default_value) const
53 if (!OK()) return default_value;
54 t value = default_value;
55 std::ifstream(folder_ + "/" + name) >> value;
59 template<typename t> bool UnencryptedProperties::Set(const char* name,
62 if (!OK()) return false;
63 std::ofstream o(folder_ + "/" + name);
68 // Specialized getters/setters for strings
69 template<> std::string UnencryptedProperties::Get(const char* name,
70 std::string default_value) const;
72 template<> bool UnencryptedProperties::Set(const char* name,
73 std::string const& value);