Home | History | Annotate | Download | only in include
      1 // Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary
      2 // source code may only be used and distributed under the Widevine Master
      3 // License Agreement.
      4 //
      5 #ifndef CLEARKEY_MEMORY_FILE_SYSTEM_H_
      6 #define CLEARKEY_MEMORY_FILE_SYSTEM_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "ClearKeyTypes.h"
     12 
     13 namespace android {
     14 namespace hardware {
     15 namespace drm {
     16 namespace V1_2 {
     17 namespace clearkey {
     18 
     19 // Using android file system requires clearkey plugin to update
     20 // its sepolicy. However, we are unable to update sepolicy for
     21 // older vendor partitions. To provide backward compatibility,
     22 // clearkey plugin implements a very simple file system in memory.
     23 // This memory file system does not support directory structure.
     24 class MemoryFileSystem {
     25  public:
     26     struct MemoryFile {
     27         std::string fileName;  // excludes path
     28         std::string content;
     29         size_t fileSize;
     30 
     31         std::string getContent() const { return content; }
     32         size_t getFileSize() const { return fileSize; }
     33         void setContent(const std::string& file) { content = file; }
     34         void setFileName(const std::string& name) { fileName = name; }
     35         void setFileSize(size_t size) {
     36             content.resize(size); fileSize = size;
     37         }
     38     };
     39 
     40     MemoryFileSystem() {};
     41     virtual ~MemoryFileSystem() {};
     42 
     43     bool FileExists(const std::string& fileName) const;
     44     ssize_t GetFileSize(const std::string& fileName) const;
     45     std::vector<std::string> ListFiles() const;
     46     size_t Read(const std::string& pathName, std::string* buffer);
     47     bool RemoveAllFiles();
     48     bool RemoveFile(const std::string& fileName);
     49     size_t Write(const std::string& pathName, const MemoryFile& memoryFile);
     50 
     51  private:
     52     // License file name is made up of a unique keySetId, therefore,
     53     // the filename can be used as the key to locate licenses in the
     54     // memory file system.
     55     std::map<std::string, MemoryFile> mMemoryFileSystem;
     56 
     57     std::string GetFileName(const std::string& path);
     58 
     59     CLEARKEY_DISALLOW_COPY_AND_ASSIGN(MemoryFileSystem);
     60 };
     61 
     62 } // namespace clearkey
     63 } // namespace V1_2
     64 } // namespace drm
     65 } // namespace hardware
     66 } // namespace android
     67 
     68 #endif  // CLEARKEY_MEMORY_FILE_SYSTEM_H_
     69