blob: 876719efe5483cc4cccf2b2237aca41d82113ab3 [file] [log] [blame]
James Weidd2f9682020-11-09 22:42:15 +08001/*
2 * Copyright (C) 2020 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#ifndef _MTP_MOCK_DATABASE_H
17#define _MTP_MOCK_DATABASE_H
18
19#include <map>
20
21#include "IMtpDatabase.h"
22#include "MtpStorage.h"
23
24namespace android {
25
26class MtpMockDatabase : public IMtpDatabase {
27 std::map<MtpStorageID, MtpStorage*> mStorage;
28 std::vector<MtpObjectInfo*> mObjects;
29 uint32_t mLastObjectHandle;
30
31public:
32 MtpMockDatabase();
33 virtual ~MtpMockDatabase();
34
35 // MtpFuzzer methods
36 void addStorage(MtpStorage* storage) {
37 // we don't own this
38 mStorage[storage->getStorageID()] = storage;
39 }
40
41 bool hasStorage(MtpStorageID storage) { return mStorage.find(storage) != mStorage.end(); }
42
43 void addObject(MtpObjectInfo* info);
44 MtpObjectHandle allocateObjectHandle();
45
46 // libmtp interface methods
47 // Called from SendObjectInfo to reserve a database entry for the incoming
48 // file.
49 MtpObjectHandle beginSendObject(const char* path, MtpObjectFormat format,
50 MtpObjectHandle parent, MtpStorageID storage);
51
52 // Called to report success or failure of the SendObject file transfer.
53 void endSendObject(MtpObjectHandle handle, bool succeeded);
54
55 // Called to rescan a file, such as after an edit.
56 void rescanFile(const char* path, MtpObjectHandle handle, MtpObjectFormat format);
57
58 MtpObjectHandleList* getObjectList(MtpStorageID storageID, MtpObjectFormat format,
59 MtpObjectHandle parent);
60
61 int getNumObjects(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent);
62
63 // callee should delete[] the results from these
64 // results can be NULL
65 MtpObjectFormatList* getSupportedPlaybackFormats();
66 MtpObjectFormatList* getSupportedCaptureFormats();
67 MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format);
68 MtpDevicePropertyList* getSupportedDeviceProperties();
69
70 MtpResponseCode getObjectPropertyValue(MtpObjectHandle handle, MtpObjectProperty property,
71 MtpDataPacket& packet);
72
73 MtpResponseCode setObjectPropertyValue(MtpObjectHandle handle, MtpObjectProperty property,
74 MtpDataPacket& packet);
75
76 MtpResponseCode getDevicePropertyValue(MtpDeviceProperty property, MtpDataPacket& packet);
77
78 MtpResponseCode setDevicePropertyValue(MtpDeviceProperty property, MtpDataPacket& packet);
79
80 MtpResponseCode resetDeviceProperty(MtpDeviceProperty property);
81
82 MtpResponseCode getObjectPropertyList(MtpObjectHandle handle, uint32_t format,
83 uint32_t property, int groupCode, int depth,
84 MtpDataPacket& packet);
85
86 MtpResponseCode getObjectInfo(MtpObjectHandle handle, MtpObjectInfo& info);
87
88 void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize);
89
90 MtpResponseCode getObjectFilePath(MtpObjectHandle handle, MtpStringBuffer& outFilePath,
91 int64_t& outFileLength, MtpObjectFormat& outFormat);
92
93 MtpResponseCode beginDeleteObject(MtpObjectHandle handle);
94 void endDeleteObject(MtpObjectHandle handle, bool succeeded);
95
96 MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle);
97
98 MtpResponseCode setObjectReferences(MtpObjectHandle handle, MtpObjectHandleList* references);
99
100 MtpProperty* getObjectPropertyDesc(MtpObjectProperty property, MtpObjectFormat format);
101
102 MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property);
103
104 MtpResponseCode beginMoveObject(MtpObjectHandle handle, MtpObjectHandle newParent,
105 MtpStorageID newStorage);
106
107 void endMoveObject(MtpObjectHandle oldParent, MtpObjectHandle newParent,
108 MtpStorageID oldStorage, MtpStorageID newStorage, MtpObjectHandle handle,
109 bool succeeded);
110
111 MtpResponseCode beginCopyObject(MtpObjectHandle handle, MtpObjectHandle newParent,
112 MtpStorageID newStorage);
113 void endCopyObject(MtpObjectHandle handle, bool succeeded);
114};
115
116}; // namespace android
117
118#endif // _MTP_MOCK_DATABASE_H