Merge lp:~cyphermox/mtp/images into lp:mtp
- images
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Ricardo Salveti |
Approved revision: | 24 |
Merged at revision: | 24 |
Proposed branch: | lp:~cyphermox/mtp/images |
Merge into: | lp:mtp |
Diff against target: |
1573 lines (+1152/-95) 20 files modified
.bzr-builddeb/default.conf (+2/-0) CMakeLists.txt (+8/-1) debian/changelog (+2/-2) debian/control (+10/-5) debian/mtp-server.conf (+18/-0) debian/mtp-server.install (+2/-1) debian/mtp-server.mtp-server-bootup.upstart (+27/-0) debian/rules (+5/-7) server/CMakeLists.txt (+6/-1) server/UbuntuMtpDatabase.h (+189/-66) server/server.cpp (+32/-12) src/MtpUtils.cpp (+1/-0) tests/CMakeLists.txt (+91/-0) tests/MockMtpDatabase.h (+358/-0) tests/TestMtpDebug.cpp (+49/-0) tests/TestMtpPacket.cpp (+50/-0) tests/TestMtpProperty.cpp (+95/-0) tests/TestMtpServer.cpp (+72/-0) tests/TestMtpStorage.cpp (+87/-0) tests/TestMtpUtils.cpp (+48/-0) |
To merge this branch: | bzr merge lp:~cyphermox/mtp/images |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Salveti (community) | Approve | ||
Review via email: mp+184868@code.launchpad.net |
Commit message
Description of the change
Ricardo Salveti (rsalveti) wrote : | # |
40 -mtp (0.0.1-1) raring; urgency=low
41 -
42 - * Initial release
43 -
44 - -- Thomas Voß <email address hidden> Mon, 10 June 2013 11:43:05 +0200
45 +mtp (0.0.4-0ubuntu1) UNRELEASED; urgency=low
Coming from 0.0.1 to 0.0.4, would probably be better to use 0.1 instead as you're replacing the changelog anyway.
Mathieu Trudel-Lapierre (cyphermox) wrote : | # |
> You don't need to go over the timeout logic if setprop is not available.
Well, the timeout is more important, since this could possibly start before the android settings service is available to do something with the request. Should I jsut remove the check for the existence of setprop?
- 19. By Mathieu Trudel-Lapierre
-
Un-hardcode paths and user info.
- 20. By Mathieu Trudel-Lapierre
-
Fix saving files to the root MTP directory.
- 21. By Mathieu Trudel-Lapierre
-
Only check for property service if setprop is executable at all
- 22. By Mathieu Trudel-Lapierre
-
Fix changelog for archive release
- 23. By Mathieu Trudel-Lapierre
-
Add libboost-test-dev as a Build-Depends.
Ricardo Salveti (rsalveti) wrote : | # |
747 +++ tests/MockMtpDa
Mind adding copyright in this file?
- 24. By Mathieu Trudel-Lapierre
-
Fix changelog license for the files we added that are not from the Android library.
Ricardo Salveti (rsalveti) wrote : | # |
Looks good, thanks!
Preview Diff
1 | === added directory '.bzr-builddeb' | |||
2 | === added file '.bzr-builddeb/default.conf' | |||
3 | --- .bzr-builddeb/default.conf 1970-01-01 00:00:00 +0000 | |||
4 | +++ .bzr-builddeb/default.conf 2013-09-11 16:32:38 +0000 | |||
5 | @@ -0,0 +1,2 @@ | |||
6 | 1 | [BUILDDEB] | ||
7 | 2 | split = True | ||
8 | 0 | 3 | ||
9 | === modified file 'CMakeLists.txt' | |||
10 | --- CMakeLists.txt 2013-06-13 10:22:21 +0000 | |||
11 | +++ CMakeLists.txt 2013-09-11 16:32:38 +0000 | |||
12 | @@ -10,6 +10,8 @@ | |||
13 | 10 | set(MTP_VERSION_MINOR 0) | 10 | set(MTP_VERSION_MINOR 0) |
14 | 11 | set(MTP_VERSION_PATCH 0) | 11 | set(MTP_VERSION_PATCH 0) |
15 | 12 | 12 | ||
16 | 13 | find_package(Boost REQUIRED COMPONENTS system filesystem unit_test_framework) | ||
17 | 14 | |||
18 | 13 | set( | 15 | set( |
19 | 14 | MTP_HEADERS | 16 | MTP_HEADERS |
20 | 15 | include/MtpDatabase.h | 17 | include/MtpDatabase.h |
21 | @@ -53,6 +55,7 @@ | |||
22 | 53 | include_directories( | 55 | include_directories( |
23 | 54 | include/ | 56 | include/ |
24 | 55 | libusbhost/include | 57 | libusbhost/include |
25 | 58 | ${Boost_INCLUDE_DIRS} | ||
26 | 56 | ) | 59 | ) |
27 | 57 | 60 | ||
28 | 58 | add_library( | 61 | add_library( |
29 | @@ -80,5 +83,9 @@ | |||
30 | 80 | PUBLIC_HEADER DESTINATION include/mtp | 83 | PUBLIC_HEADER DESTINATION include/mtp |
31 | 81 | ) | 84 | ) |
32 | 82 | 85 | ||
33 | 86 | enable_testing() | ||
34 | 87 | |||
35 | 83 | add_subdirectory(libusbhost) | 88 | add_subdirectory(libusbhost) |
37 | 84 | add_subdirectory(examples) | 89 | add_subdirectory(server) |
38 | 90 | add_subdirectory(tests) | ||
39 | 91 | |||
40 | 85 | 92 | ||
41 | === modified file 'debian/changelog' | |||
42 | --- debian/changelog 2013-06-13 10:22:21 +0000 | |||
43 | +++ debian/changelog 2013-09-11 16:32:38 +0000 | |||
44 | @@ -1,5 +1,5 @@ | |||
46 | 1 | mtp (0.0.1-1) raring; urgency=low | 1 | mtp (0.0.1-0ubuntu1) UNRELEASED; urgency=low |
47 | 2 | 2 | ||
48 | 3 | * Initial release | 3 | * Initial release |
49 | 4 | 4 | ||
51 | 5 | -- Thomas Voß <thomas.voss@canonical.com> Mon, 10 June 2013 11:43:05 +0200 | 5 | -- Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Fri, 06 Sep 2013 16:07:38 -0400 |
52 | 6 | 6 | ||
53 | === modified file 'debian/control' | |||
54 | --- debian/control 2013-06-13 10:22:21 +0000 | |||
55 | +++ debian/control 2013-09-11 16:32:38 +0000 | |||
56 | @@ -1,8 +1,13 @@ | |||
57 | 1 | Source: mtp | 1 | Source: mtp |
60 | 2 | Priority: extra | 2 | Section: utils |
61 | 3 | Maintainer: Thomas Voß <thomas.voss@canonical.com> | 3 | Priority: optional |
62 | 4 | Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> | ||
63 | 5 | XSBC-Original-Maintainer: Thomas Voß <thomas.voss@canonical.com> | ||
64 | 4 | Build-Depends: debhelper (>= 8.0.0), | 6 | Build-Depends: debhelper (>= 8.0.0), |
66 | 5 | cmake, | 7 | cmake, |
67 | 8 | libboost-dev, | ||
68 | 9 | libboost-filesystem-dev, | ||
69 | 10 | libboost-test-dev, | ||
70 | 6 | Standards-Version: 3.9.4 | 11 | Standards-Version: 3.9.4 |
71 | 7 | Homepage: http://launchpad.net/mtp | 12 | Homepage: http://launchpad.net/mtp |
72 | 8 | 13 | ||
73 | @@ -24,12 +29,12 @@ | |||
74 | 24 | . | 29 | . |
75 | 25 | Contains header files required to develop actual services. | 30 | Contains header files required to develop actual services. |
76 | 26 | 31 | ||
78 | 27 | Package: mtp-examples | 32 | Package: mtp-server |
79 | 28 | Architecture: any | 33 | Architecture: any |
80 | 29 | Depends: ${misc:Depends}, | 34 | Depends: ${misc:Depends}, |
81 | 30 | ${shlibs:Depends} | 35 | ${shlibs:Depends} |
82 | 31 | Description: A server-implementation of MTP. | 36 | Description: A server-implementation of MTP. |
83 | 32 | Exposes phone storage over MTP. | 37 | Exposes phone storage over MTP. |
84 | 33 | . | 38 | . |
86 | 34 | Contains example executables | 39 | Contains a simple MTP server that exposes images, videos, and music. |
87 | 35 | 40 | ||
88 | 36 | 41 | ||
89 | === added file 'debian/mtp-server.conf' | |||
90 | --- debian/mtp-server.conf 1970-01-01 00:00:00 +0000 | |||
91 | +++ debian/mtp-server.conf 2013-09-11 16:32:38 +0000 | |||
92 | @@ -0,0 +1,18 @@ | |||
93 | 1 | description "MTP protocol server" | ||
94 | 2 | |||
95 | 3 | start on :sys:android_usb-device-changed | ||
96 | 4 | |||
97 | 5 | expect fork | ||
98 | 6 | respawn | ||
99 | 7 | |||
100 | 8 | pre-start script | ||
101 | 9 | state=`cat /sys/class/android_usb/android0/state` | ||
102 | 10 | if [ "$state" = "DISCONNECTED" ]; then | ||
103 | 11 | stop | ||
104 | 12 | exit 0 | ||
105 | 13 | fi | ||
106 | 14 | |||
107 | 15 | rm -f ~/.cache/upstart/mtp-server.log | ||
108 | 16 | end script | ||
109 | 17 | |||
110 | 18 | exec /usr/bin/mtp-server & | ||
111 | 0 | 19 | ||
112 | === renamed file 'debian/mtp-examples.install' => 'debian/mtp-server.install' | |||
113 | --- debian/mtp-examples.install 2013-06-13 10:22:21 +0000 | |||
114 | +++ debian/mtp-server.install 2013-09-11 16:32:38 +0000 | |||
115 | @@ -1,1 +1,2 @@ | |||
116 | 1 | usr/bin/mtp-server | ||
117 | 2 | \ No newline at end of file | 1 | \ No newline at end of file |
118 | 2 | usr/bin/mtp-server | ||
119 | 3 | debian/mtp-server.conf /usr/share/upstart/sessions/ | ||
120 | 3 | 4 | ||
121 | === added file 'debian/mtp-server.mtp-server-bootup.upstart' | |||
122 | --- debian/mtp-server.mtp-server-bootup.upstart 1970-01-01 00:00:00 +0000 | |||
123 | +++ debian/mtp-server.mtp-server-bootup.upstart 2013-09-11 16:32:38 +0000 | |||
124 | @@ -0,0 +1,27 @@ | |||
125 | 1 | description "MTP protocol server bootup" | ||
126 | 2 | |||
127 | 3 | start on android | ||
128 | 4 | |||
129 | 5 | task | ||
130 | 6 | |||
131 | 7 | emits android_usb-device-changed | ||
132 | 8 | |||
133 | 9 | script | ||
134 | 10 | if [ -x /usr/bin/setprop ]; then | ||
135 | 11 | timeout=10 | ||
136 | 12 | # loop 10 times and then exit, if the property service | ||
137 | 13 | # isnt up after 80 sec # it is likely not starting at all | ||
138 | 14 | while [ ! -e /dev/socket/property_service ]; do | ||
139 | 15 | sleep 8 | ||
140 | 16 | if [ "$timeout" -le 0 ]; then | ||
141 | 17 | stop | ||
142 | 18 | exit 0 | ||
143 | 19 | fi | ||
144 | 20 | timeout=$(($timeout - 1)) | ||
145 | 21 | done | ||
146 | 22 | |||
147 | 23 | /usr/bin/setprop sys.usb.config mtp,adb | ||
148 | 24 | fi | ||
149 | 25 | |||
150 | 26 | initctl emit android_usb-device-changed | ||
151 | 27 | end script | ||
152 | 0 | 28 | ||
153 | === modified file 'debian/rules' | |||
154 | --- debian/rules 2013-06-13 10:22:21 +0000 | |||
155 | +++ debian/rules 2013-09-11 16:32:38 +0000 | |||
156 | @@ -1,13 +1,11 @@ | |||
157 | 1 | #!/usr/bin/make -f | 1 | #!/usr/bin/make -f |
158 | 2 | # -*- makefile -*- | ||
159 | 3 | # Sample debian/rules that uses debhelper. | ||
160 | 4 | # This file was originally written by Joey Hess and Craig Small. | ||
161 | 5 | # As a special exception, when this file is copied by dh-make into a | ||
162 | 6 | # dh-make output file, you may use that output file without restriction. | ||
163 | 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. | ||
164 | 8 | 2 | ||
165 | 9 | # Uncomment this to turn on verbose mode. | 3 | # Uncomment this to turn on verbose mode. |
166 | 10 | # export DH_VERBOSE=1 | 4 | # export DH_VERBOSE=1 |
167 | 11 | 5 | ||
168 | 12 | %: | 6 | %: |
169 | 13 | dh $@ | ||
170 | 14 | \ No newline at end of file | 7 | \ No newline at end of file |
171 | 8 | dh $@ | ||
172 | 9 | |||
173 | 10 | override_dh_installinit: | ||
174 | 11 | dh_installinit -pmtp-server --name=mtp-server-bootup | ||
175 | 12 | dh_installinit | ||
176 | 15 | 13 | ||
177 | === renamed directory 'examples' => 'server' | |||
178 | === modified file 'server/CMakeLists.txt' | |||
179 | --- examples/CMakeLists.txt 2013-06-13 10:22:21 +0000 | |||
180 | +++ server/CMakeLists.txt 2013-09-11 16:32:38 +0000 | |||
181 | @@ -5,13 +5,18 @@ | |||
182 | 5 | server.cpp | 5 | server.cpp |
183 | 6 | ) | 6 | ) |
184 | 7 | 7 | ||
185 | 8 | set_target_properties(mtp-server PROPERTIES COMPILE_FLAGS -fPIC) | ||
186 | 9 | |||
187 | 8 | target_link_libraries( | 10 | target_link_libraries( |
188 | 9 | mtp-server | 11 | mtp-server |
189 | 10 | mtp | 12 | mtp |
190 | 11 | usbhost | 13 | usbhost |
191 | 14 | ${Boost_LIBRARIES} | ||
192 | 15 | ${Boost_system_LIBRARIES} | ||
193 | 16 | ${Boost_filesystem_LIBRARIES} | ||
194 | 12 | ) | 17 | ) |
195 | 13 | 18 | ||
196 | 14 | install( | 19 | install( |
197 | 15 | TARGETS mtp-server | 20 | TARGETS mtp-server |
198 | 16 | RUNTIME DESTINATION bin | 21 | RUNTIME DESTINATION bin |
199 | 17 | ) | ||
200 | 18 | \ No newline at end of file | 22 | \ No newline at end of file |
201 | 23 | ) | ||
202 | 19 | 24 | ||
203 | === renamed file 'examples/StubMtpDatabase.h' => 'server/UbuntuMtpDatabase.h' | |||
204 | --- examples/StubMtpDatabase.h 2013-06-13 10:22:21 +0000 | |||
205 | +++ server/UbuntuMtpDatabase.h 2013-09-11 16:32:38 +0000 | |||
206 | @@ -1,3 +1,19 @@ | |||
207 | 1 | /* | ||
208 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
209 | 3 | * | ||
210 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
211 | 5 | * you may not use this file except in compliance with the License. | ||
212 | 6 | * You may obtain a copy of the License at | ||
213 | 7 | * | ||
214 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
215 | 9 | * | ||
216 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
217 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
218 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
219 | 13 | * See the License for the specific language governing permissions and | ||
220 | 14 | * limitations under the License. | ||
221 | 15 | */ | ||
222 | 16 | |||
223 | 1 | #ifndef STUB_MTP_DATABASE_H_ | 17 | #ifndef STUB_MTP_DATABASE_H_ |
224 | 2 | #define STUB_MTP_DATABASE_H_ | 18 | #define STUB_MTP_DATABASE_H_ |
225 | 3 | 19 | ||
226 | @@ -7,73 +23,106 @@ | |||
227 | 7 | #include <MtpObjectInfo.h> | 23 | #include <MtpObjectInfo.h> |
228 | 8 | #include <MtpProperty.h> | 24 | #include <MtpProperty.h> |
229 | 9 | 25 | ||
230 | 26 | #include <cstdlib> | ||
231 | 10 | #include <cstring> | 27 | #include <cstring> |
232 | 11 | #include <iostream> | 28 | #include <iostream> |
233 | 12 | #include <map> | 29 | #include <map> |
234 | 30 | #include <vector> | ||
235 | 13 | #include <string> | 31 | #include <string> |
236 | 14 | #include <tuple> | 32 | #include <tuple> |
237 | 15 | 33 | ||
238 | 34 | #include <boost/foreach.hpp> | ||
239 | 35 | #include <boost/filesystem.hpp> | ||
240 | 36 | #include <boost/range/adaptors.hpp> | ||
241 | 37 | #include <boost/range/algorithm.hpp> | ||
242 | 38 | |||
243 | 39 | using namespace boost::filesystem; | ||
244 | 40 | |||
245 | 16 | namespace android | 41 | namespace android |
246 | 17 | { | 42 | { |
248 | 18 | class StubMtpDatabase : public android::MtpDatabase { | 43 | class UbuntuMtpDatabase : public android::MtpDatabase { |
249 | 19 | private: | 44 | private: |
250 | 20 | struct DbEntry | 45 | struct DbEntry |
251 | 21 | { | 46 | { |
252 | 22 | MtpStorageID storage_id; | 47 | MtpStorageID storage_id; |
253 | 23 | std::string object_name; | 48 | std::string object_name; |
254 | 24 | MtpObjectFormat object_format; | 49 | MtpObjectFormat object_format; |
255 | 50 | MtpObjectHandle parent; | ||
256 | 25 | size_t object_size; | 51 | size_t object_size; |
257 | 26 | size_t width; | ||
258 | 27 | size_t height; | ||
259 | 28 | size_t bit_depth; | ||
260 | 29 | std::string display_name; | 52 | std::string display_name; |
261 | 30 | std::string path; | 53 | std::string path; |
262 | 31 | }; | 54 | }; |
263 | 32 | 55 | ||
264 | 33 | enum PngImageHandles | ||
265 | 34 | { | ||
266 | 35 | png_image_1, | ||
267 | 36 | png_image_2, | ||
268 | 37 | png_image_3, | ||
269 | 38 | png_image_4, | ||
270 | 39 | png_image_5, | ||
271 | 40 | png_image_6, | ||
272 | 41 | png_image_7, | ||
273 | 42 | png_image_8, | ||
274 | 43 | png_image_9, | ||
275 | 44 | png_image_10, | ||
276 | 45 | png_image_size | ||
277 | 46 | }; | ||
278 | 47 | static const uint32_t reserved_slots = png_image_size; | ||
279 | 48 | |||
280 | 49 | uint32_t counter; | 56 | uint32_t counter; |
282 | 50 | std::map<std::tuple<MtpStorageID, MtpObjectFormat>, MtpObjectHandleList> db = | 57 | std::map<MtpObjectHandle, DbEntry> db; |
283 | 58 | |||
284 | 59 | void parse_directory(path p, MtpObjectHandle parent) | ||
285 | 51 | { | 60 | { |
286 | 61 | DbEntry entry; | ||
287 | 62 | std::vector<path> v; | ||
288 | 63 | |||
289 | 64 | copy(directory_iterator(p), directory_iterator(), std::back_inserter(v)); | ||
290 | 65 | |||
291 | 66 | for (std::vector<path>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) | ||
292 | 52 | { | 67 | { |
295 | 53 | std::make_tuple(MTP_STORAGE_REMOVABLE_RAM, MTP_FORMAT_PNG), | 68 | MtpObjectHandle handle = counter; |
296 | 54 | {png_image_1, png_image_2, png_image_3, png_image_4, png_image_5, png_image_6, png_image_7, png_image_8, png_image_9, png_image_10} | 69 | |
297 | 70 | counter++; | ||
298 | 71 | |||
299 | 72 | std::cout << " " << *it << " handle: " << handle << " parent: " << parent << std::endl; | ||
300 | 73 | |||
301 | 74 | entry.storage_id = MTP_STORAGE_FIXED_RAM; | ||
302 | 75 | entry.parent = parent; | ||
303 | 76 | entry.object_name = it->filename().string(); | ||
304 | 77 | entry.display_name = it->filename().string(); | ||
305 | 78 | entry.path = it->string(); | ||
306 | 79 | |||
307 | 80 | if (is_regular_file (*it)) { | ||
308 | 81 | entry.object_format = MTP_FORMAT_DEFINED; | ||
309 | 82 | entry.object_size = file_size(*it); | ||
310 | 83 | |||
311 | 84 | db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); | ||
312 | 85 | } else if (is_directory (*it)) { | ||
313 | 86 | entry.object_format = MTP_FORMAT_ASSOCIATION; | ||
314 | 87 | entry.object_size = 0; | ||
315 | 88 | |||
316 | 89 | db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); | ||
317 | 90 | |||
318 | 91 | parse_directory (*it, handle); | ||
319 | 92 | } | ||
320 | 55 | } | 93 | } |
324 | 56 | }; | 94 | } |
325 | 57 | 95 | ||
326 | 58 | std::map<MtpObjectHandle, DbEntry> entries = | 96 | void readFiles(const std::string& sourcedir) |
327 | 59 | { | 97 | { |
340 | 60 | {png_image_1, {MTP_STORAGE_REMOVABLE_RAM, "png_image_1", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_1", "png_image_1.png"}}, | 98 | path p (sourcedir); |
341 | 61 | {png_image_2, {MTP_STORAGE_REMOVABLE_RAM, "png_image_2", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_2", "png_image_2.png"}}, | 99 | |
342 | 62 | {png_image_3, {MTP_STORAGE_REMOVABLE_RAM, "png_image_3", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_3", "png_image_3.png"}}, | 100 | try { |
343 | 63 | {png_image_4, {MTP_STORAGE_REMOVABLE_RAM, "png_image_4", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_4", "png_image_4.png"}}, | 101 | if (exists(p)) { |
344 | 64 | {png_image_5, {MTP_STORAGE_REMOVABLE_RAM, "png_image_5", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_5", "png_image_5.png"}}, | 102 | if (is_directory(p)) { |
345 | 65 | {png_image_6, {MTP_STORAGE_REMOVABLE_RAM, "png_image_6", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_6", "png_image_6.png"}}, | 103 | std::cout << p << " is a directory containing:\n"; |
346 | 66 | {png_image_7, {MTP_STORAGE_REMOVABLE_RAM, "png_image_7", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_7", "png_image_7.png"}}, | 104 | |
347 | 67 | {png_image_8, {MTP_STORAGE_REMOVABLE_RAM, "png_image_8", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_8", "png_image_8.png"}}, | 105 | parse_directory (p, MTP_PARENT_ROOT); |
348 | 68 | {png_image_9, {MTP_STORAGE_REMOVABLE_RAM, "png_image_9", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_9", "png_image_9.png"}}, | 106 | } |
349 | 69 | {png_image_10, {MTP_STORAGE_REMOVABLE_RAM, "png_image_10", MTP_FORMAT_PNG, 20 * 20 * 4, 20, 20, 4, "png_image_10", "png_image_10.png"}} | 107 | } else |
350 | 70 | }; | 108 | std::cout << p << " does not exist\n"; |
351 | 71 | 109 | } | |
352 | 110 | catch (const filesystem_error& ex) { | ||
353 | 111 | std::cout << ex.what() << '\n'; | ||
354 | 112 | } | ||
355 | 113 | |||
356 | 114 | } | ||
357 | 115 | |||
358 | 72 | public: | 116 | public: |
360 | 73 | StubMtpDatabase() : counter(StubMtpDatabase::reserved_slots) | 117 | UbuntuMtpDatabase(const char *dir) : counter(1) |
361 | 74 | { | 118 | { |
362 | 119 | db = std::map<MtpObjectHandle, DbEntry>(); | ||
363 | 120 | readFiles(std::string(dir)); | ||
364 | 121 | |||
365 | 122 | std::cout << __PRETTY_FUNCTION__ << ": object count:" << db.size() << std::endl; | ||
366 | 75 | } | 123 | } |
368 | 76 | virtual ~StubMtpDatabase() {} | 124 | |
369 | 125 | virtual ~UbuntuMtpDatabase() {} | ||
370 | 77 | 126 | ||
371 | 78 | // called from SendObjectInfo to reserve a database entry for the incoming file | 127 | // called from SendObjectInfo to reserve a database entry for the incoming file |
372 | 79 | virtual MtpObjectHandle beginSendObject( | 128 | virtual MtpObjectHandle beginSendObject( |
373 | @@ -84,8 +133,25 @@ | |||
374 | 84 | uint64_t size, | 133 | uint64_t size, |
375 | 85 | time_t modified) | 134 | time_t modified) |
376 | 86 | { | 135 | { |
379 | 87 | std::cout << __PRETTY_FUNCTION__ << ": " << path << std::endl; | 136 | DbEntry entry; |
380 | 88 | return counter++; | 137 | MtpObjectHandle handle = counter; |
381 | 138 | MtpObjectHandle parent_id = parent == 0 ? MTP_PARENT_ROOT : parent; | ||
382 | 139 | |||
383 | 140 | std::cout << __PRETTY_FUNCTION__ << ": " << path << " - " << parent << std::endl; | ||
384 | 141 | |||
385 | 142 | entry.storage_id = storage; | ||
386 | 143 | entry.parent = parent_id; | ||
387 | 144 | entry.object_name = std::string(basename(path.c_str())); | ||
388 | 145 | entry.display_name = std::string(basename(path.c_str())); | ||
389 | 146 | entry.path = path; | ||
390 | 147 | entry.object_format = format; | ||
391 | 148 | entry.object_size = size; | ||
392 | 149 | |||
393 | 150 | db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); | ||
394 | 151 | |||
395 | 152 | counter++; | ||
396 | 153 | |||
397 | 154 | return handle; | ||
398 | 89 | } | 155 | } |
399 | 90 | 156 | ||
400 | 91 | // called to report success or failure of the SendObject file transfer | 157 | // called to report success or failure of the SendObject file transfer |
401 | @@ -98,6 +164,10 @@ | |||
402 | 98 | bool succeeded) | 164 | bool succeeded) |
403 | 99 | { | 165 | { |
404 | 100 | std::cout << __PRETTY_FUNCTION__ << ": " << path << std::endl; | 166 | std::cout << __PRETTY_FUNCTION__ << ": " << path << std::endl; |
405 | 167 | |||
406 | 168 | if (!succeeded) { | ||
407 | 169 | db.erase(handle); | ||
408 | 170 | } | ||
409 | 101 | } | 171 | } |
410 | 102 | 172 | ||
411 | 103 | virtual MtpObjectHandleList* getObjectList( | 173 | virtual MtpObjectHandleList* getObjectList( |
412 | @@ -109,7 +179,14 @@ | |||
413 | 109 | MtpObjectHandleList* list = nullptr; | 179 | MtpObjectHandleList* list = nullptr; |
414 | 110 | try | 180 | try |
415 | 111 | { | 181 | { |
417 | 112 | list = new MtpObjectHandleList(db.at(std::make_tuple(storageID, MTP_FORMAT_PNG))); | 182 | std::vector<MtpObjectHandle> keys; |
418 | 183 | |||
419 | 184 | BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { | ||
420 | 185 | if (db.at(i).parent == parent) | ||
421 | 186 | keys.push_back(i); | ||
422 | 187 | } | ||
423 | 188 | |||
424 | 189 | list = new MtpObjectHandleList(keys); | ||
425 | 113 | } catch(...) | 190 | } catch(...) |
426 | 114 | { | 191 | { |
427 | 115 | list = new MtpObjectHandleList(); | 192 | list = new MtpObjectHandleList(); |
428 | @@ -126,7 +203,7 @@ | |||
429 | 126 | std::cout << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent << std::endl; | 203 | std::cout << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent << std::endl; |
430 | 127 | try | 204 | try |
431 | 128 | { | 205 | { |
433 | 129 | return db.at(std::make_tuple(storageID, MTP_FORMAT_PNG)).size(); | 206 | return db.size(); |
434 | 130 | } catch(...) | 207 | } catch(...) |
435 | 131 | { | 208 | { |
436 | 132 | } | 209 | } |
437 | @@ -153,12 +230,15 @@ | |||
438 | 153 | virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format) | 230 | virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format) |
439 | 154 | { | 231 | { |
440 | 155 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 232 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
441 | 233 | /* | ||
442 | 156 | if (format != MTP_FORMAT_PNG) | 234 | if (format != MTP_FORMAT_PNG) |
443 | 157 | return nullptr; | 235 | return nullptr; |
444 | 236 | */ | ||
445 | 158 | 237 | ||
446 | 159 | static const MtpObjectPropertyList list = | 238 | static const MtpObjectPropertyList list = |
447 | 160 | { | 239 | { |
448 | 161 | MTP_PROPERTY_STORAGE_ID, | 240 | MTP_PROPERTY_STORAGE_ID, |
449 | 241 | MTP_PROPERTY_PARENT_OBJECT, | ||
450 | 162 | MTP_PROPERTY_OBJECT_FORMAT, | 242 | MTP_PROPERTY_OBJECT_FORMAT, |
451 | 163 | MTP_PROPERTY_OBJECT_SIZE, | 243 | MTP_PROPERTY_OBJECT_SIZE, |
452 | 164 | MTP_PROPERTY_WIDTH, | 244 | MTP_PROPERTY_WIDTH, |
453 | @@ -185,13 +265,11 @@ | |||
454 | 185 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 265 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
455 | 186 | switch(property) | 266 | switch(property) |
456 | 187 | { | 267 | { |
464 | 188 | case MTP_PROPERTY_STORAGE_ID: packet.putUInt32(entries.at(handle).storage_id); break; | 268 | case MTP_PROPERTY_STORAGE_ID: packet.putUInt32(db.at(handle).storage_id); break; |
465 | 189 | case MTP_PROPERTY_OBJECT_FORMAT: packet.putUInt32(entries.at(handle).object_format); break; | 269 | case MTP_PROPERTY_PARENT_OBJECT: packet.putUInt32(db.at(handle).parent); break; |
466 | 190 | case MTP_PROPERTY_OBJECT_SIZE: packet.putUInt32(entries.at(handle).object_size); break; | 270 | case MTP_PROPERTY_OBJECT_FORMAT: packet.putUInt32(db.at(handle).object_format); break; |
467 | 191 | case MTP_PROPERTY_WIDTH: packet.putUInt32(entries.at(handle).width); break; | 271 | case MTP_PROPERTY_OBJECT_SIZE: packet.putUInt32(db.at(handle).object_size); break; |
468 | 192 | case MTP_PROPERTY_HEIGHT: packet.putUInt32(entries.at(handle).height); break; | 272 | case MTP_PROPERTY_DISPLAY_NAME: packet.putString(db.at(handle).display_name.c_str()); break; |
462 | 193 | case MTP_PROPERTY_IMAGE_BIT_DEPTH: packet.putUInt32(entries.at(handle).bit_depth); break; | ||
463 | 194 | case MTP_PROPERTY_DISPLAY_NAME: packet.putString(entries.at(handle).display_name.c_str()); break; | ||
469 | 195 | default: return MTP_RESPONSE_GENERAL_ERROR; break; | 273 | default: return MTP_RESPONSE_GENERAL_ERROR; break; |
470 | 196 | } | 274 | } |
471 | 197 | 275 | ||
472 | @@ -248,22 +326,22 @@ | |||
473 | 248 | { | 326 | { |
474 | 249 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 327 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
475 | 250 | info.mHandle = handle; | 328 | info.mHandle = handle; |
478 | 251 | info.mStorageID = entries.at(handle).storage_id; | 329 | info.mStorageID = db.at(handle).storage_id; |
479 | 252 | info.mFormat = entries.at(handle).object_format; | 330 | info.mFormat = db.at(handle).object_format; |
480 | 253 | info.mProtectionStatus = 0x0; | 331 | info.mProtectionStatus = 0x0; |
481 | 254 | info.mCompressedSize = 0; | 332 | info.mCompressedSize = 0; |
483 | 255 | info.mThumbFormat = entries.at(handle).object_format; | 333 | info.mThumbFormat = db.at(handle).object_format; |
484 | 256 | info.mThumbCompressedSize = 20*20*4; | 334 | info.mThumbCompressedSize = 20*20*4; |
485 | 257 | info.mThumbPixWidth = 20; | 335 | info.mThumbPixWidth = 20; |
486 | 258 | info.mThumbPixHeight =20; | 336 | info.mThumbPixHeight =20; |
487 | 259 | info.mImagePixWidth = 20; | 337 | info.mImagePixWidth = 20; |
488 | 260 | info.mImagePixHeight = 20; | 338 | info.mImagePixHeight = 20; |
489 | 261 | info.mImagePixDepth = 4; | 339 | info.mImagePixDepth = 4; |
491 | 262 | info.mParent = MTP_PARENT_ROOT; | 340 | info.mParent = db.at(handle).parent; |
492 | 263 | info.mAssociationType = 0; | 341 | info.mAssociationType = 0; |
493 | 264 | info.mAssociationDesc = 0; | 342 | info.mAssociationDesc = 0; |
494 | 265 | info.mSequenceNumber = 0; | 343 | info.mSequenceNumber = 0; |
496 | 266 | info.mName = ::strdup("test"); | 344 | info.mName = ::strdup(db.at(handle).object_name.c_str()); |
497 | 267 | info.mDateCreated = 0; | 345 | info.mDateCreated = 0; |
498 | 268 | info.mDateModified = 0; | 346 | info.mDateModified = 0; |
499 | 269 | info.mKeywords = ::strdup("ubuntu,touch"); | 347 | info.mKeywords = ::strdup("ubuntu,touch"); |
500 | @@ -273,10 +351,11 @@ | |||
501 | 273 | 351 | ||
502 | 274 | virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize) | 352 | virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize) |
503 | 275 | { | 353 | { |
508 | 276 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 354 | void* result; |
509 | 277 | outThumbSize = 20*20*4; | 355 | |
510 | 278 | void* result = malloc(20*20*4); | 356 | outThumbSize = 0; |
511 | 279 | memset(result, 0, 20*20*4); | 357 | memset(result, 0, outThumbSize); |
512 | 358 | |||
513 | 280 | return result; | 359 | return result; |
514 | 281 | } | 360 | } |
515 | 282 | 361 | ||
516 | @@ -286,17 +365,61 @@ | |||
517 | 286 | int64_t& outFileLength, | 365 | int64_t& outFileLength, |
518 | 287 | MtpObjectFormat& outFormat) | 366 | MtpObjectFormat& outFormat) |
519 | 288 | { | 367 | { |
520 | 368 | DbEntry entry = db.at(handle); | ||
521 | 369 | |||
522 | 289 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 370 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
526 | 290 | outFilePath = entries.at(handle).path; | 371 | |
527 | 291 | outFileLength = 1024; | 372 | outFilePath = std::string(entry.path); |
528 | 292 | outFormat = entries.at(handle).object_format; | 373 | outFileLength = entry.object_size; |
529 | 374 | outFormat = entry.object_format; | ||
530 | 375 | |||
531 | 376 | return MTP_RESPONSE_OK; | ||
532 | 293 | } | 377 | } |
533 | 294 | 378 | ||
534 | 295 | virtual MtpResponseCode deleteFile(MtpObjectHandle handle) | 379 | virtual MtpResponseCode deleteFile(MtpObjectHandle handle) |
535 | 296 | { | 380 | { |
539 | 297 | std::cout << __PRETTY_FUNCTION__ << std::endl; | 381 | size_t orig_size = db.size(); |
540 | 298 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | 382 | size_t new_size; |
541 | 299 | } | 383 | |
542 | 384 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
543 | 385 | |||
544 | 386 | new_size = db.erase(handle); | ||
545 | 387 | |||
546 | 388 | if (orig_size > new_size) { | ||
547 | 389 | /* Recursively remove children object from the DB as well. | ||
548 | 390 | * we can safely ignore failures here, since the objects | ||
549 | 391 | * would not be reachable anyway. | ||
550 | 392 | */ | ||
551 | 393 | BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { | ||
552 | 394 | if (db.at(i).parent == handle) | ||
553 | 395 | db.erase(i); | ||
554 | 396 | } | ||
555 | 397 | return MTP_RESPONSE_OK; | ||
556 | 398 | } | ||
557 | 399 | else | ||
558 | 400 | return MTP_RESPONSE_GENERAL_ERROR; | ||
559 | 401 | } | ||
560 | 402 | |||
561 | 403 | /* | ||
562 | 404 | virtual MtpResponseCode moveFile(MtpObjectHandle handle, MtpObjectHandle new_parent) | ||
563 | 405 | { | ||
564 | 406 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
565 | 407 | |||
566 | 408 | // change parent | ||
567 | 409 | |||
568 | 410 | return MTP_RESPONSE_OK | ||
569 | 411 | } | ||
570 | 412 | |||
571 | 413 | virtual MtpResponseCode copyFile(MtpObjectHandle handle, MtpObjectHandle new_parent) | ||
572 | 414 | { | ||
573 | 415 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
574 | 416 | |||
575 | 417 | // duplicate DbEntry | ||
576 | 418 | // change parent | ||
577 | 419 | |||
578 | 420 | return MTP_RESPONSE_OK | ||
579 | 421 | } | ||
580 | 422 | */ | ||
581 | 300 | 423 | ||
582 | 301 | virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle) | 424 | virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle) |
583 | 302 | { | 425 | { |
584 | 303 | 426 | ||
585 | === modified file 'server/server.cpp' | |||
586 | --- examples/server.cpp 2013-06-13 10:22:21 +0000 | |||
587 | +++ server/server.cpp 2013-09-11 16:32:38 +0000 | |||
588 | @@ -1,4 +1,20 @@ | |||
590 | 1 | #include "StubMtpDatabase.h" | 1 | /* |
591 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
592 | 3 | * | ||
593 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
594 | 5 | * you may not use this file except in compliance with the License. | ||
595 | 6 | * You may obtain a copy of the License at | ||
596 | 7 | * | ||
597 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
598 | 9 | * | ||
599 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
600 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
601 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
602 | 13 | * See the License for the specific language governing permissions and | ||
603 | 14 | * limitations under the License. | ||
604 | 15 | */ | ||
605 | 16 | |||
606 | 17 | #include "UbuntuMtpDatabase.h" | ||
607 | 2 | 18 | ||
608 | 3 | #include <MtpServer.h> | 19 | #include <MtpServer.h> |
609 | 4 | #include <MtpStorage.h> | 20 | #include <MtpStorage.h> |
610 | @@ -10,27 +26,23 @@ | |||
611 | 10 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
612 | 11 | #include <fcntl.h> | 27 | #include <fcntl.h> |
613 | 12 | #include <unistd.h> | 28 | #include <unistd.h> |
614 | 29 | #include <pwd.h> | ||
615 | 13 | 30 | ||
616 | 14 | namespace | 31 | namespace |
617 | 15 | { | 32 | { |
618 | 16 | struct FileSystemConfig | 33 | struct FileSystemConfig |
619 | 17 | { | 34 | { |
620 | 18 | static const int file_group = 1023; // Taken from android's config. Might need to be adjusted. | ||
621 | 19 | static const int file_perm = 0664; | 35 | static const int file_perm = 0664; |
622 | 20 | static const int directory_perm = 0755; | 36 | static const int directory_perm = 0755; |
623 | 21 | }; | 37 | }; |
624 | 22 | 38 | ||
632 | 23 | android::MtpStorage* removable_storage = new android::MtpStorage( | 39 | android::MtpStorage* home_storage; |
633 | 24 | MTP_STORAGE_REMOVABLE_RAM, | 40 | |
627 | 25 | ".", | ||
628 | 26 | "Dummy storage", | ||
629 | 27 | 1024 * 1024 * 1024 * 200, | ||
630 | 28 | true, | ||
631 | 29 | 1024 * 1024 * 1024); | ||
634 | 30 | } | 41 | } |
635 | 31 | 42 | ||
636 | 32 | int main(int argc, char** argv) | 43 | int main(int argc, char** argv) |
637 | 33 | { | 44 | { |
638 | 45 | struct passwd *userdata = getpwuid (getuid()); | ||
639 | 34 | int fd = open("/dev/mtp_usb", O_RDWR); | 46 | int fd = open("/dev/mtp_usb", O_RDWR); |
640 | 35 | 47 | ||
641 | 36 | if (fd < 0) | 48 | if (fd < 0) |
642 | @@ -38,17 +50,25 @@ | |||
643 | 38 | std::cout << "Error opening /dev/mtp_usb, aborting now..." << std::endl; | 50 | std::cout << "Error opening /dev/mtp_usb, aborting now..." << std::endl; |
644 | 39 | } | 51 | } |
645 | 40 | 52 | ||
646 | 53 | home_storage = new android::MtpStorage( | ||
647 | 54 | MTP_STORAGE_FIXED_RAM, | ||
648 | 55 | userdata->pw_dir, | ||
649 | 56 | userdata->pw_name, | ||
650 | 57 | 1024 * 1024 * 100, /* 100 MB reserved space, to avoid filling the disk */ | ||
651 | 58 | false, | ||
652 | 59 | 1024 * 1024 * 1024 * 2 /* 2GB arbitrary max file size */); | ||
653 | 60 | |||
654 | 41 | std::shared_ptr<android::MtpServer> server | 61 | std::shared_ptr<android::MtpServer> server |
655 | 42 | { | 62 | { |
656 | 43 | new android::MtpServer( | 63 | new android::MtpServer( |
657 | 44 | fd, | 64 | fd, |
659 | 45 | new android::StubMtpDatabase(), | 65 | new android::UbuntuMtpDatabase(userdata->pw_dir), |
660 | 46 | false, | 66 | false, |
662 | 47 | FileSystemConfig::file_group, | 67 | userdata->pw_gid, |
663 | 48 | FileSystemConfig::file_perm, | 68 | FileSystemConfig::file_perm, |
664 | 49 | FileSystemConfig::directory_perm) | 69 | FileSystemConfig::directory_perm) |
665 | 50 | }; | 70 | }; |
667 | 51 | server->addStorage(removable_storage); | 71 | server->addStorage(home_storage); |
668 | 52 | server->run(); | 72 | server->run(); |
669 | 53 | 73 | ||
670 | 54 | /* | 74 | /* |
671 | 55 | 75 | ||
672 | === modified file 'src/MtpUtils.cpp' | |||
673 | --- src/MtpUtils.cpp 2013-06-13 10:22:21 +0000 | |||
674 | +++ src/MtpUtils.cpp 2013-09-11 16:32:38 +0000 | |||
675 | @@ -49,6 +49,7 @@ | |||
676 | 49 | 49 | ||
677 | 50 | // hack to compute timezone | 50 | // hack to compute timezone |
678 | 51 | time_t dummy; | 51 | time_t dummy; |
679 | 52 | tzset(); | ||
680 | 52 | localtime_r(&dummy, &tm); | 53 | localtime_r(&dummy, &tm); |
681 | 53 | 54 | ||
682 | 54 | tm.tm_sec = second; | 55 | tm.tm_sec = second; |
683 | 55 | 56 | ||
684 | === added directory 'tests' | |||
685 | === added file 'tests/CMakeLists.txt' | |||
686 | --- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
687 | +++ tests/CMakeLists.txt 2013-09-11 16:32:38 +0000 | |||
688 | @@ -0,0 +1,91 @@ | |||
689 | 1 | |||
690 | 2 | # MtpUtils | ||
691 | 3 | add_executable( | ||
692 | 4 | test-utils | ||
693 | 5 | TestMtpUtils.cpp | ||
694 | 6 | ) | ||
695 | 7 | |||
696 | 8 | target_link_libraries( | ||
697 | 9 | test-utils | ||
698 | 10 | mtp | ||
699 | 11 | usbhost | ||
700 | 12 | ${Boost_LIBRARIES} | ||
701 | 13 | ${Boost_unit_test_framework_LIBRARIES} | ||
702 | 14 | ) | ||
703 | 15 | add_test(test-utils test-utils) | ||
704 | 16 | |||
705 | 17 | # MtpDebug | ||
706 | 18 | add_executable( | ||
707 | 19 | test-debug | ||
708 | 20 | TestMtpDebug.cpp | ||
709 | 21 | ) | ||
710 | 22 | |||
711 | 23 | target_link_libraries( | ||
712 | 24 | test-debug | ||
713 | 25 | mtp | ||
714 | 26 | usbhost | ||
715 | 27 | ${Boost_LIBRARIES} | ||
716 | 28 | ${Boost_unit_test_framework_LIBRARIES} | ||
717 | 29 | ) | ||
718 | 30 | add_test(test-debug test-debug) | ||
719 | 31 | |||
720 | 32 | # MtpPacket | ||
721 | 33 | add_executable( | ||
722 | 34 | test-packet | ||
723 | 35 | TestMtpPacket.cpp | ||
724 | 36 | ) | ||
725 | 37 | |||
726 | 38 | target_link_libraries( | ||
727 | 39 | test-packet | ||
728 | 40 | mtp | ||
729 | 41 | usbhost | ||
730 | 42 | ${Boost_LIBRARIES} | ||
731 | 43 | ${Boost_unit_test_framework_LIBRARIES} | ||
732 | 44 | ) | ||
733 | 45 | add_test(test-packet test-packet) | ||
734 | 46 | |||
735 | 47 | # MtpProperty | ||
736 | 48 | add_executable( | ||
737 | 49 | test-property | ||
738 | 50 | TestMtpProperty.cpp | ||
739 | 51 | ) | ||
740 | 52 | |||
741 | 53 | target_link_libraries( | ||
742 | 54 | test-property | ||
743 | 55 | mtp | ||
744 | 56 | usbhost | ||
745 | 57 | ${Boost_LIBRARIES} | ||
746 | 58 | ${Boost_unit_test_framework_LIBRARIES} | ||
747 | 59 | ) | ||
748 | 60 | add_test(test-property test-property) | ||
749 | 61 | |||
750 | 62 | # MtpStorage | ||
751 | 63 | add_executable( | ||
752 | 64 | test-storage | ||
753 | 65 | TestMtpStorage.cpp | ||
754 | 66 | ) | ||
755 | 67 | |||
756 | 68 | target_link_libraries( | ||
757 | 69 | test-storage | ||
758 | 70 | mtp | ||
759 | 71 | usbhost | ||
760 | 72 | ${Boost_LIBRARIES} | ||
761 | 73 | ${Boost_unit_test_framework_LIBRARIES} | ||
762 | 74 | ) | ||
763 | 75 | add_test(test-storage test-storage) | ||
764 | 76 | |||
765 | 77 | # MtpServer | ||
766 | 78 | add_executable( | ||
767 | 79 | test-server | ||
768 | 80 | TestMtpServer.cpp | ||
769 | 81 | ) | ||
770 | 82 | |||
771 | 83 | target_link_libraries( | ||
772 | 84 | test-server | ||
773 | 85 | mtp | ||
774 | 86 | usbhost | ||
775 | 87 | ${Boost_LIBRARIES} | ||
776 | 88 | ${Boost_unit_test_framework_LIBRARIES} | ||
777 | 89 | ) | ||
778 | 90 | add_test(test-server test-server) | ||
779 | 91 | |||
780 | 0 | 92 | ||
781 | === added file 'tests/MockMtpDatabase.h' | |||
782 | --- tests/MockMtpDatabase.h 1970-01-01 00:00:00 +0000 | |||
783 | +++ tests/MockMtpDatabase.h 2013-09-11 16:32:38 +0000 | |||
784 | @@ -0,0 +1,358 @@ | |||
785 | 1 | /* | ||
786 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
787 | 3 | * | ||
788 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
789 | 5 | * you may not use this file except in compliance with the License. | ||
790 | 6 | * You may obtain a copy of the License at | ||
791 | 7 | * | ||
792 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
793 | 9 | * | ||
794 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
795 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
796 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
797 | 13 | * See the License for the specific language governing permissions and | ||
798 | 14 | * limitations under the License. | ||
799 | 15 | */ | ||
800 | 16 | |||
801 | 17 | #ifndef STUB_MOCK_MTP_DATABASE_H_ | ||
802 | 18 | #define STUB_MOCK_MTP_DATABASE_H_ | ||
803 | 19 | |||
804 | 20 | #include <mtp.h> | ||
805 | 21 | #include <MtpDatabase.h> | ||
806 | 22 | #include <MtpDataPacket.h> | ||
807 | 23 | #include <MtpObjectInfo.h> | ||
808 | 24 | #include <MtpProperty.h> | ||
809 | 25 | |||
810 | 26 | #include <cstdlib> | ||
811 | 27 | #include <cstring> | ||
812 | 28 | #include <iostream> | ||
813 | 29 | #include <map> | ||
814 | 30 | #include <vector> | ||
815 | 31 | #include <string> | ||
816 | 32 | #include <tuple> | ||
817 | 33 | |||
818 | 34 | #include <boost/foreach.hpp> | ||
819 | 35 | #include <boost/filesystem.hpp> | ||
820 | 36 | #include <boost/range/adaptors.hpp> | ||
821 | 37 | #include <boost/range/algorithm.hpp> | ||
822 | 38 | |||
823 | 39 | namespace android | ||
824 | 40 | { | ||
825 | 41 | class MockMtpDatabase : public android::MtpDatabase { | ||
826 | 42 | private: | ||
827 | 43 | struct DbEntry | ||
828 | 44 | { | ||
829 | 45 | MtpStorageID storage_id; | ||
830 | 46 | std::string object_name; | ||
831 | 47 | MtpObjectFormat object_format; | ||
832 | 48 | MtpObjectHandle parent; | ||
833 | 49 | size_t object_size; | ||
834 | 50 | std::string display_name; | ||
835 | 51 | std::string path; | ||
836 | 52 | }; | ||
837 | 53 | |||
838 | 54 | uint32_t counter; | ||
839 | 55 | std::map<MtpObjectHandle, DbEntry> db; | ||
840 | 56 | |||
841 | 57 | public: | ||
842 | 58 | MockMtpDatabase() : counter(1) | ||
843 | 59 | { | ||
844 | 60 | DbEntry entry; | ||
845 | 61 | db = std::map<MtpObjectHandle, DbEntry>(); | ||
846 | 62 | |||
847 | 63 | entry.storage_id = 666; | ||
848 | 64 | entry.object_name = std::string("Test Object"); | ||
849 | 65 | entry.object_format = MTP_FORMAT_PNG; | ||
850 | 66 | entry.parent = MTP_PARENT_ROOT; | ||
851 | 67 | entry.object_size = 666; | ||
852 | 68 | entry.display_name = std::string("Test Object"); | ||
853 | 69 | entry.path = std::string("TestObject"); | ||
854 | 70 | |||
855 | 71 | db.insert( std::pair<MtpObjectHandle, DbEntry>(counter, entry) ); | ||
856 | 72 | } | ||
857 | 73 | |||
858 | 74 | virtual ~MockMtpDatabase() {} | ||
859 | 75 | |||
860 | 76 | virtual MtpObjectHandle beginSendObject( | ||
861 | 77 | const MtpString& path, | ||
862 | 78 | MtpObjectFormat format, | ||
863 | 79 | MtpObjectHandle parent, | ||
864 | 80 | MtpStorageID storage, | ||
865 | 81 | uint64_t size, | ||
866 | 82 | time_t modified) | ||
867 | 83 | { | ||
868 | 84 | return 1; | ||
869 | 85 | } | ||
870 | 86 | |||
871 | 87 | virtual void endSendObject( | ||
872 | 88 | const MtpString& path, | ||
873 | 89 | MtpObjectHandle handle, | ||
874 | 90 | MtpObjectFormat format, | ||
875 | 91 | bool succeeded) | ||
876 | 92 | { | ||
877 | 93 | std::cout << __PRETTY_FUNCTION__ << ": " << path << std::endl; | ||
878 | 94 | |||
879 | 95 | if (!succeeded) { | ||
880 | 96 | db.erase(handle); | ||
881 | 97 | } | ||
882 | 98 | } | ||
883 | 99 | |||
884 | 100 | virtual MtpObjectHandleList* getObjectList( | ||
885 | 101 | MtpStorageID storageID, | ||
886 | 102 | MtpObjectFormat format, | ||
887 | 103 | MtpObjectHandle parent) | ||
888 | 104 | { | ||
889 | 105 | MtpObjectHandleList* list = nullptr; | ||
890 | 106 | |||
891 | 107 | if (db.empty()) { | ||
892 | 108 | list = new MtpObjectHandleList(); | ||
893 | 109 | } else { | ||
894 | 110 | std::vector<MtpObjectHandle> keys; | ||
895 | 111 | keys.push_back(1); | ||
896 | 112 | list = new MtpObjectHandleList(keys); | ||
897 | 113 | } | ||
898 | 114 | |||
899 | 115 | return list; | ||
900 | 116 | } | ||
901 | 117 | |||
902 | 118 | virtual int getNumObjects( | ||
903 | 119 | MtpStorageID storageID, | ||
904 | 120 | MtpObjectFormat format, | ||
905 | 121 | MtpObjectHandle parent) | ||
906 | 122 | { | ||
907 | 123 | return db.size(); | ||
908 | 124 | } | ||
909 | 125 | |||
910 | 126 | virtual MtpObjectFormatList* getSupportedPlaybackFormats() | ||
911 | 127 | { | ||
912 | 128 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
913 | 129 | static const MtpObjectFormatList list = {MTP_FORMAT_PNG}; | ||
914 | 130 | return new MtpObjectFormatList{list}; | ||
915 | 131 | } | ||
916 | 132 | |||
917 | 133 | virtual MtpObjectFormatList* getSupportedCaptureFormats() | ||
918 | 134 | { | ||
919 | 135 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
920 | 136 | static const MtpObjectFormatList list = {MTP_FORMAT_ASSOCIATION, MTP_FORMAT_PNG}; | ||
921 | 137 | return new MtpObjectFormatList{list}; | ||
922 | 138 | } | ||
923 | 139 | |||
924 | 140 | virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format) | ||
925 | 141 | { | ||
926 | 142 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
927 | 143 | |||
928 | 144 | static const MtpObjectPropertyList list = | ||
929 | 145 | { | ||
930 | 146 | MTP_PROPERTY_STORAGE_ID, | ||
931 | 147 | MTP_PROPERTY_PARENT_OBJECT, | ||
932 | 148 | MTP_PROPERTY_OBJECT_FORMAT, | ||
933 | 149 | MTP_PROPERTY_OBJECT_SIZE, | ||
934 | 150 | MTP_PROPERTY_WIDTH, | ||
935 | 151 | MTP_PROPERTY_HEIGHT, | ||
936 | 152 | MTP_PROPERTY_IMAGE_BIT_DEPTH, | ||
937 | 153 | MTP_PROPERTY_DISPLAY_NAME | ||
938 | 154 | }; | ||
939 | 155 | |||
940 | 156 | return new MtpObjectPropertyList{list}; | ||
941 | 157 | } | ||
942 | 158 | |||
943 | 159 | virtual MtpDevicePropertyList* getSupportedDeviceProperties() | ||
944 | 160 | { | ||
945 | 161 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
946 | 162 | static const MtpDevicePropertyList list = { MTP_DEVICE_PROPERTY_UNDEFINED }; | ||
947 | 163 | return new MtpDevicePropertyList{list}; | ||
948 | 164 | } | ||
949 | 165 | |||
950 | 166 | virtual MtpResponseCode getObjectPropertyValue( | ||
951 | 167 | MtpObjectHandle handle, | ||
952 | 168 | MtpObjectProperty property, | ||
953 | 169 | MtpDataPacket& packet) | ||
954 | 170 | { | ||
955 | 171 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
956 | 172 | switch(property) | ||
957 | 173 | { | ||
958 | 174 | case MTP_PROPERTY_STORAGE_ID: packet.putUInt32(db.at(handle).storage_id); break; | ||
959 | 175 | case MTP_PROPERTY_PARENT_OBJECT: packet.putUInt32(db.at(handle).parent); break; | ||
960 | 176 | case MTP_PROPERTY_OBJECT_FORMAT: packet.putUInt32(db.at(handle).object_format); break; | ||
961 | 177 | case MTP_PROPERTY_OBJECT_SIZE: packet.putUInt32(db.at(handle).object_size); break; | ||
962 | 178 | case MTP_PROPERTY_DISPLAY_NAME: packet.putString(db.at(handle).display_name.c_str()); break; | ||
963 | 179 | default: return MTP_RESPONSE_GENERAL_ERROR; break; | ||
964 | 180 | } | ||
965 | 181 | |||
966 | 182 | return MTP_RESPONSE_OK; | ||
967 | 183 | } | ||
968 | 184 | |||
969 | 185 | virtual MtpResponseCode setObjectPropertyValue( | ||
970 | 186 | MtpObjectHandle handle, | ||
971 | 187 | MtpObjectProperty property, | ||
972 | 188 | MtpDataPacket& packet) | ||
973 | 189 | { | ||
974 | 190 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
975 | 191 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | ||
976 | 192 | } | ||
977 | 193 | |||
978 | 194 | virtual MtpResponseCode getDevicePropertyValue( | ||
979 | 195 | MtpDeviceProperty property, | ||
980 | 196 | MtpDataPacket& packet) | ||
981 | 197 | { | ||
982 | 198 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
983 | 199 | return MTP_RESPONSE_GENERAL_ERROR; | ||
984 | 200 | } | ||
985 | 201 | |||
986 | 202 | virtual MtpResponseCode setDevicePropertyValue( | ||
987 | 203 | MtpDeviceProperty property, | ||
988 | 204 | MtpDataPacket& packet) | ||
989 | 205 | { | ||
990 | 206 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
991 | 207 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | ||
992 | 208 | } | ||
993 | 209 | |||
994 | 210 | virtual MtpResponseCode resetDeviceProperty( | ||
995 | 211 | MtpDeviceProperty property) | ||
996 | 212 | { | ||
997 | 213 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
998 | 214 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | ||
999 | 215 | } | ||
1000 | 216 | |||
1001 | 217 | virtual MtpResponseCode getObjectPropertyList( | ||
1002 | 218 | MtpObjectHandle handle, | ||
1003 | 219 | uint32_t format, | ||
1004 | 220 | uint32_t property, | ||
1005 | 221 | int groupCode, | ||
1006 | 222 | int depth, | ||
1007 | 223 | MtpDataPacket& packet) | ||
1008 | 224 | { | ||
1009 | 225 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1010 | 226 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | ||
1011 | 227 | } | ||
1012 | 228 | |||
1013 | 229 | virtual MtpResponseCode getObjectInfo( | ||
1014 | 230 | MtpObjectHandle handle, | ||
1015 | 231 | MtpObjectInfo& info) | ||
1016 | 232 | { | ||
1017 | 233 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1018 | 234 | info.mHandle = handle; | ||
1019 | 235 | info.mStorageID = db.at(handle).storage_id; | ||
1020 | 236 | info.mFormat = db.at(handle).object_format; | ||
1021 | 237 | info.mProtectionStatus = 0x0; | ||
1022 | 238 | info.mCompressedSize = 0; | ||
1023 | 239 | info.mThumbFormat = db.at(handle).object_format; | ||
1024 | 240 | info.mThumbCompressedSize = 20*20*4; | ||
1025 | 241 | info.mThumbPixWidth = 20; | ||
1026 | 242 | info.mThumbPixHeight =20; | ||
1027 | 243 | info.mImagePixWidth = 20; | ||
1028 | 244 | info.mImagePixHeight = 20; | ||
1029 | 245 | info.mImagePixDepth = 4; | ||
1030 | 246 | info.mParent = db.at(handle).parent; | ||
1031 | 247 | info.mAssociationType = 0; | ||
1032 | 248 | info.mAssociationDesc = 0; | ||
1033 | 249 | info.mSequenceNumber = 0; | ||
1034 | 250 | info.mName = ::strdup(db.at(handle).object_name.c_str()); | ||
1035 | 251 | info.mDateCreated = 0; | ||
1036 | 252 | info.mDateModified = 0; | ||
1037 | 253 | info.mKeywords = ::strdup("test"); | ||
1038 | 254 | |||
1039 | 255 | return MTP_RESPONSE_OK; | ||
1040 | 256 | } | ||
1041 | 257 | |||
1042 | 258 | virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize) | ||
1043 | 259 | { | ||
1044 | 260 | void* result; | ||
1045 | 261 | |||
1046 | 262 | outThumbSize = 0; | ||
1047 | 263 | memset(result, 0, outThumbSize); | ||
1048 | 264 | |||
1049 | 265 | return result; | ||
1050 | 266 | } | ||
1051 | 267 | |||
1052 | 268 | virtual MtpResponseCode getObjectFilePath( | ||
1053 | 269 | MtpObjectHandle handle, | ||
1054 | 270 | MtpString& outFilePath, | ||
1055 | 271 | int64_t& outFileLength, | ||
1056 | 272 | MtpObjectFormat& outFormat) | ||
1057 | 273 | { | ||
1058 | 274 | DbEntry entry = db.at(handle); | ||
1059 | 275 | |||
1060 | 276 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1061 | 277 | |||
1062 | 278 | outFilePath = std::string(entry.path); | ||
1063 | 279 | outFileLength = entry.object_size; | ||
1064 | 280 | outFormat = entry.object_format; | ||
1065 | 281 | |||
1066 | 282 | return MTP_RESPONSE_OK; | ||
1067 | 283 | } | ||
1068 | 284 | |||
1069 | 285 | virtual MtpResponseCode deleteFile(MtpObjectHandle handle) | ||
1070 | 286 | { | ||
1071 | 287 | size_t orig_size = db.size(); | ||
1072 | 288 | size_t new_size; | ||
1073 | 289 | |||
1074 | 290 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1075 | 291 | |||
1076 | 292 | new_size = db.erase(handle); | ||
1077 | 293 | |||
1078 | 294 | if (orig_size > new_size) { | ||
1079 | 295 | BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { | ||
1080 | 296 | if (db.at(i).parent == handle) | ||
1081 | 297 | db.erase(i); | ||
1082 | 298 | } | ||
1083 | 299 | return MTP_RESPONSE_OK; | ||
1084 | 300 | } | ||
1085 | 301 | else | ||
1086 | 302 | return MTP_RESPONSE_GENERAL_ERROR; | ||
1087 | 303 | } | ||
1088 | 304 | |||
1089 | 305 | virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle) | ||
1090 | 306 | { | ||
1091 | 307 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1092 | 308 | return nullptr; | ||
1093 | 309 | } | ||
1094 | 310 | |||
1095 | 311 | virtual MtpResponseCode setObjectReferences( | ||
1096 | 312 | MtpObjectHandle handle, | ||
1097 | 313 | MtpObjectHandleList* references) | ||
1098 | 314 | { | ||
1099 | 315 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1100 | 316 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; | ||
1101 | 317 | } | ||
1102 | 318 | |||
1103 | 319 | virtual MtpProperty* getObjectPropertyDesc( | ||
1104 | 320 | MtpObjectProperty property, | ||
1105 | 321 | MtpObjectFormat format) | ||
1106 | 322 | { | ||
1107 | 323 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1108 | 324 | MtpProperty* result = nullptr; | ||
1109 | 325 | switch(property) | ||
1110 | 326 | { | ||
1111 | 327 | case MTP_PROPERTY_STORAGE_ID: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1112 | 328 | case MTP_PROPERTY_OBJECT_FORMAT: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1113 | 329 | case MTP_PROPERTY_OBJECT_SIZE: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1114 | 330 | case MTP_PROPERTY_WIDTH: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1115 | 331 | case MTP_PROPERTY_HEIGHT: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1116 | 332 | case MTP_PROPERTY_IMAGE_BIT_DEPTH: result = new MtpProperty(property, MTP_TYPE_UINT32); break; | ||
1117 | 333 | case MTP_PROPERTY_DISPLAY_NAME: result = new MtpProperty(property, MTP_TYPE_STR); break; | ||
1118 | 334 | default: break; | ||
1119 | 335 | } | ||
1120 | 336 | |||
1121 | 337 | return result; | ||
1122 | 338 | } | ||
1123 | 339 | |||
1124 | 340 | virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property) | ||
1125 | 341 | { | ||
1126 | 342 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1127 | 343 | return new MtpProperty(MTP_DEVICE_PROPERTY_UNDEFINED, MTP_TYPE_UNDEFINED); | ||
1128 | 344 | } | ||
1129 | 345 | |||
1130 | 346 | virtual void sessionStarted() | ||
1131 | 347 | { | ||
1132 | 348 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1133 | 349 | } | ||
1134 | 350 | |||
1135 | 351 | virtual void sessionEnded() | ||
1136 | 352 | { | ||
1137 | 353 | std::cout << __PRETTY_FUNCTION__ << std::endl; | ||
1138 | 354 | } | ||
1139 | 355 | }; | ||
1140 | 356 | } | ||
1141 | 357 | |||
1142 | 358 | #endif // STUB_MOCK_MTP_DATABASE_H_ | ||
1143 | 0 | 359 | ||
1144 | === added file 'tests/TestMtpDebug.cpp' | |||
1145 | --- tests/TestMtpDebug.cpp 1970-01-01 00:00:00 +0000 | |||
1146 | +++ tests/TestMtpDebug.cpp 2013-09-11 16:32:38 +0000 | |||
1147 | @@ -0,0 +1,49 @@ | |||
1148 | 1 | /* | ||
1149 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1150 | 3 | * | ||
1151 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1152 | 5 | * you may not use this file except in compliance with the License. | ||
1153 | 6 | * You may obtain a copy of the License at | ||
1154 | 7 | * | ||
1155 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1156 | 9 | * | ||
1157 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1158 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1159 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1160 | 13 | * See the License for the specific language governing permissions and | ||
1161 | 14 | * limitations under the License. | ||
1162 | 15 | */ | ||
1163 | 16 | |||
1164 | 17 | #define BOOST_TEST_DYN_LINK | ||
1165 | 18 | #define BOOST_TEST_MAIN | ||
1166 | 19 | #include <boost/test/unit_test.hpp> | ||
1167 | 20 | |||
1168 | 21 | #include "mtp.h" | ||
1169 | 22 | #include "MtpDebug.h" | ||
1170 | 23 | |||
1171 | 24 | using namespace android; | ||
1172 | 25 | |||
1173 | 26 | BOOST_AUTO_TEST_CASE(DebugGetOperationCodeName) | ||
1174 | 27 | { | ||
1175 | 28 | BOOST_CHECK_EQUAL( MtpDebug::getOperationCodeName(MTP_OPERATION_GET_DEVICE_INFO), "MTP_OPERATION_GET_DEVICE_INFO" ); | ||
1176 | 29 | } | ||
1177 | 30 | |||
1178 | 31 | BOOST_AUTO_TEST_CASE(DebugGetFormatCodeName) | ||
1179 | 32 | { | ||
1180 | 33 | BOOST_CHECK_EQUAL( MtpDebug::getFormatCodeName(MTP_FORMAT_PNG), "MTP_FORMAT_PNG" ); | ||
1181 | 34 | } | ||
1182 | 35 | |||
1183 | 36 | BOOST_AUTO_TEST_CASE(DebugGetObjectPropCodeName) | ||
1184 | 37 | { | ||
1185 | 38 | BOOST_CHECK_EQUAL( MtpDebug::getObjectPropCodeName(MTP_PROPERTY_STORAGE_ID), "MTP_PROPERTY_STORAGE_ID" ); | ||
1186 | 39 | } | ||
1187 | 40 | |||
1188 | 41 | BOOST_AUTO_TEST_CASE(DebugGetDevicePropCodeName) | ||
1189 | 42 | { | ||
1190 | 43 | BOOST_CHECK_EQUAL( MtpDebug::getDevicePropCodeName(MTP_DEVICE_PROPERTY_BATTERY_LEVEL), "MTP_DEVICE_PROPERTY_BATTERY_LEVEL" ); | ||
1191 | 44 | } | ||
1192 | 45 | |||
1193 | 46 | BOOST_AUTO_TEST_CASE(DebugGetCodeNameUnknown) | ||
1194 | 47 | { | ||
1195 | 48 | BOOST_CHECK_EQUAL( MtpDebug::getOperationCodeName (1), "UNKNOWN"); | ||
1196 | 49 | } | ||
1197 | 0 | 50 | ||
1198 | === added file 'tests/TestMtpPacket.cpp' | |||
1199 | --- tests/TestMtpPacket.cpp 1970-01-01 00:00:00 +0000 | |||
1200 | +++ tests/TestMtpPacket.cpp 2013-09-11 16:32:38 +0000 | |||
1201 | @@ -0,0 +1,50 @@ | |||
1202 | 1 | /* | ||
1203 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1204 | 3 | * | ||
1205 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1206 | 5 | * you may not use this file except in compliance with the License. | ||
1207 | 6 | * You may obtain a copy of the License at | ||
1208 | 7 | * | ||
1209 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1210 | 9 | * | ||
1211 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1212 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1213 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1214 | 13 | * See the License for the specific language governing permissions and | ||
1215 | 14 | * limitations under the License. | ||
1216 | 15 | */ | ||
1217 | 16 | |||
1218 | 17 | #define BOOST_TEST_DYN_LINK | ||
1219 | 18 | #define BOOST_TEST_MAIN | ||
1220 | 19 | #include <boost/test/unit_test.hpp> | ||
1221 | 20 | |||
1222 | 21 | #include "mtp.h" | ||
1223 | 22 | #include "MtpPacket.h" | ||
1224 | 23 | |||
1225 | 24 | using namespace android; | ||
1226 | 25 | |||
1227 | 26 | BOOST_AUTO_TEST_CASE(Packet) | ||
1228 | 27 | { | ||
1229 | 28 | MtpPacket *p = new MtpPacket (4); | ||
1230 | 29 | |||
1231 | 30 | BOOST_REQUIRE(p); | ||
1232 | 31 | } | ||
1233 | 32 | |||
1234 | 33 | BOOST_AUTO_TEST_CASE(PacketReset) | ||
1235 | 34 | { | ||
1236 | 35 | MtpPacket *p = new MtpPacket (MTP_CONTAINER_PARAMETER_OFFSET + 4); | ||
1237 | 36 | uint32_t value = UINT32_MAX; | ||
1238 | 37 | uint32_t result; | ||
1239 | 38 | |||
1240 | 39 | BOOST_REQUIRE(p); | ||
1241 | 40 | |||
1242 | 41 | p->setParameter(1, value); | ||
1243 | 42 | result = p->getParameter(1); | ||
1244 | 43 | BOOST_CHECK_EQUAL (value, result); | ||
1245 | 44 | |||
1246 | 45 | p->reset(); | ||
1247 | 46 | |||
1248 | 47 | result = p->getParameter(1); | ||
1249 | 48 | BOOST_CHECK (value != result); | ||
1250 | 49 | BOOST_CHECK (result == 0); | ||
1251 | 50 | } | ||
1252 | 0 | 51 | ||
1253 | === added file 'tests/TestMtpProperty.cpp' | |||
1254 | --- tests/TestMtpProperty.cpp 1970-01-01 00:00:00 +0000 | |||
1255 | +++ tests/TestMtpProperty.cpp 2013-09-11 16:32:38 +0000 | |||
1256 | @@ -0,0 +1,95 @@ | |||
1257 | 1 | /* | ||
1258 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1259 | 3 | * | ||
1260 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1261 | 5 | * you may not use this file except in compliance with the License. | ||
1262 | 6 | * You may obtain a copy of the License at | ||
1263 | 7 | * | ||
1264 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1265 | 9 | * | ||
1266 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1267 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1268 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1269 | 13 | * See the License for the specific language governing permissions and | ||
1270 | 14 | * limitations under the License. | ||
1271 | 15 | */ | ||
1272 | 16 | |||
1273 | 17 | #define BOOST_TEST_DYN_LINK | ||
1274 | 18 | #define BOOST_TEST_MAIN | ||
1275 | 19 | #include <boost/test/unit_test.hpp> | ||
1276 | 20 | |||
1277 | 21 | #include "mtp.h" | ||
1278 | 22 | #include "MtpProperty.h" | ||
1279 | 23 | #include "MtpStringBuffer.h" | ||
1280 | 24 | |||
1281 | 25 | using namespace android; | ||
1282 | 26 | |||
1283 | 27 | BOOST_AUTO_TEST_CASE(PropertyConstructorString) | ||
1284 | 28 | { | ||
1285 | 29 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_NAME, MTP_TYPE_STR, false); | ||
1286 | 30 | |||
1287 | 31 | BOOST_CHECK (prop); | ||
1288 | 32 | BOOST_CHECK (prop->mType == MTP_TYPE_STR); | ||
1289 | 33 | BOOST_CHECK (prop->mCode == MTP_PROPERTY_NAME); | ||
1290 | 34 | BOOST_CHECK (prop->mWriteable == false); | ||
1291 | 35 | |||
1292 | 36 | BOOST_CHECK (prop->mDefaultValue.u.u64 == 0); | ||
1293 | 37 | BOOST_CHECK (prop->mCurrentValue.u.u64 == 0); | ||
1294 | 38 | } | ||
1295 | 39 | |||
1296 | 40 | BOOST_AUTO_TEST_CASE(PropertyConstructorUInt32) | ||
1297 | 41 | { | ||
1298 | 42 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, true, 42); | ||
1299 | 43 | |||
1300 | 44 | BOOST_CHECK (prop); | ||
1301 | 45 | BOOST_CHECK (prop->mType == MTP_TYPE_UINT32); | ||
1302 | 46 | BOOST_CHECK (prop->mCode == MTP_PROPERTY_STORAGE_ID); | ||
1303 | 47 | BOOST_CHECK (prop->mWriteable == true); | ||
1304 | 48 | |||
1305 | 49 | BOOST_CHECK (prop->mDefaultValue.u.u32 == 42); | ||
1306 | 50 | BOOST_CHECK (prop->mCurrentValue.u.u64 == 0); | ||
1307 | 51 | } | ||
1308 | 52 | |||
1309 | 53 | BOOST_AUTO_TEST_CASE(PropertySetFormRange) | ||
1310 | 54 | { | ||
1311 | 55 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, true, 42); | ||
1312 | 56 | |||
1313 | 57 | prop->setFormRange(0, 90, 2); | ||
1314 | 58 | |||
1315 | 59 | BOOST_CHECK(prop->mMinimumValue.u.u32 == 0); | ||
1316 | 60 | BOOST_CHECK(prop->mMaximumValue.u.u32 == 90); | ||
1317 | 61 | BOOST_CHECK(prop->mStepSize.u.u32 == 2); | ||
1318 | 62 | } | ||
1319 | 63 | |||
1320 | 64 | BOOST_AUTO_TEST_CASE(PropertySetFormEnum) | ||
1321 | 65 | { | ||
1322 | 66 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, true, 42); | ||
1323 | 67 | const int values[4] = { 1, 2, 3, 4, }; | ||
1324 | 68 | |||
1325 | 69 | prop->setFormEnum(values, 4); | ||
1326 | 70 | |||
1327 | 71 | BOOST_CHECK(prop->mEnumValues[0].u.u32 == 1); | ||
1328 | 72 | BOOST_CHECK(prop->mEnumValues[1].u.u32 == 2); | ||
1329 | 73 | BOOST_CHECK(prop->mEnumValues[2].u.u32 == 3); | ||
1330 | 74 | BOOST_CHECK(prop->mEnumValues[3].u.u32 == 4); | ||
1331 | 75 | } | ||
1332 | 76 | |||
1333 | 77 | BOOST_AUTO_TEST_CASE(PropertySetFormDateTime) | ||
1334 | 78 | { | ||
1335 | 79 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, true, 42); | ||
1336 | 80 | |||
1337 | 81 | prop->setFormDateTime(); | ||
1338 | 82 | |||
1339 | 83 | BOOST_CHECK(prop->mFormFlag == MtpProperty::kFormDateTime); | ||
1340 | 84 | } | ||
1341 | 85 | |||
1342 | 86 | BOOST_AUTO_TEST_CASE(PropertyPrintToBuffer) | ||
1343 | 87 | { | ||
1344 | 88 | MtpProperty *prop = new MtpProperty(MTP_PROPERTY_STORAGE_ID, MTP_TYPE_UINT32, true, 42); | ||
1345 | 89 | std::string expected ("42"); | ||
1346 | 90 | std::string result; | ||
1347 | 91 | |||
1348 | 92 | prop->print(prop->mDefaultValue, result); | ||
1349 | 93 | |||
1350 | 94 | BOOST_CHECK (result == expected); | ||
1351 | 95 | } | ||
1352 | 0 | 96 | ||
1353 | === added file 'tests/TestMtpServer.cpp' | |||
1354 | --- tests/TestMtpServer.cpp 1970-01-01 00:00:00 +0000 | |||
1355 | +++ tests/TestMtpServer.cpp 2013-09-11 16:32:38 +0000 | |||
1356 | @@ -0,0 +1,72 @@ | |||
1357 | 1 | /* | ||
1358 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1359 | 3 | * | ||
1360 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1361 | 5 | * you may not use this file except in compliance with the License. | ||
1362 | 6 | * You may obtain a copy of the License at | ||
1363 | 7 | * | ||
1364 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1365 | 9 | * | ||
1366 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1367 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1368 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1369 | 13 | * See the License for the specific language governing permissions and | ||
1370 | 14 | * limitations under the License. | ||
1371 | 15 | */ | ||
1372 | 16 | |||
1373 | 17 | #define BOOST_TEST_DYN_LINK | ||
1374 | 18 | #define BOOST_TEST_MAIN | ||
1375 | 19 | #include <boost/test/unit_test.hpp> | ||
1376 | 20 | |||
1377 | 21 | #include "mtp.h" | ||
1378 | 22 | #include "MockMtpDatabase.h" | ||
1379 | 23 | #include "MtpServer.h" | ||
1380 | 24 | #include "MtpStorage.h" | ||
1381 | 25 | |||
1382 | 26 | using namespace android; | ||
1383 | 27 | |||
1384 | 28 | BOOST_AUTO_TEST_CASE(ServerConstructor) | ||
1385 | 29 | { | ||
1386 | 30 | MtpDatabase *db = new MockMtpDatabase (); | ||
1387 | 31 | MtpServer *server = new MtpServer (0, db, false, 0, 0, 0); | ||
1388 | 32 | |||
1389 | 33 | BOOST_CHECK(server); | ||
1390 | 34 | } | ||
1391 | 35 | |||
1392 | 36 | BOOST_AUTO_TEST_CASE(ServerAddGetStorage) | ||
1393 | 37 | { | ||
1394 | 38 | MtpDatabase *db = new MockMtpDatabase (); | ||
1395 | 39 | MtpServer *server = new MtpServer (0, db, false, 0, 0, 0); | ||
1396 | 40 | MtpStorage *storage = new MtpStorage (666, "/tmp", "Test storage", 0, false, 64); | ||
1397 | 41 | |||
1398 | 42 | server->addStorage(storage); | ||
1399 | 43 | |||
1400 | 44 | BOOST_CHECK(server->getStorage(666) != NULL); | ||
1401 | 45 | } | ||
1402 | 46 | |||
1403 | 47 | BOOST_AUTO_TEST_CASE(ServerGetStorageNull) | ||
1404 | 48 | { | ||
1405 | 49 | MtpDatabase *db = new MockMtpDatabase (); | ||
1406 | 50 | MtpServer *server = new MtpServer (0, db, false, 0, 0, 0); | ||
1407 | 51 | |||
1408 | 52 | BOOST_CHECK(server->getStorage(666) == NULL); | ||
1409 | 53 | } | ||
1410 | 54 | |||
1411 | 55 | BOOST_AUTO_TEST_CASE(ServerHasStorageTrue) | ||
1412 | 56 | { | ||
1413 | 57 | MtpDatabase *db = new MockMtpDatabase (); | ||
1414 | 58 | MtpServer *server = new MtpServer (0, db, false, 0, 0, 0); | ||
1415 | 59 | MtpStorage *storage = new MtpStorage (666, "/tmp", "Test storage", 0, false, 64); | ||
1416 | 60 | |||
1417 | 61 | server->addStorage(storage); | ||
1418 | 62 | |||
1419 | 63 | BOOST_CHECK(server->hasStorage(666)); | ||
1420 | 64 | } | ||
1421 | 65 | |||
1422 | 66 | BOOST_AUTO_TEST_CASE(ServerHasStorageFalse) | ||
1423 | 67 | { | ||
1424 | 68 | MtpDatabase *db = new MockMtpDatabase (); | ||
1425 | 69 | MtpServer *server = new MtpServer (0, db, false, 0, 0, 0); | ||
1426 | 70 | |||
1427 | 71 | BOOST_CHECK(server->hasStorage(667) == false); | ||
1428 | 72 | } | ||
1429 | 0 | 73 | ||
1430 | === added file 'tests/TestMtpStorage.cpp' | |||
1431 | --- tests/TestMtpStorage.cpp 1970-01-01 00:00:00 +0000 | |||
1432 | +++ tests/TestMtpStorage.cpp 2013-09-11 16:32:38 +0000 | |||
1433 | @@ -0,0 +1,87 @@ | |||
1434 | 1 | /* | ||
1435 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1436 | 3 | * | ||
1437 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1438 | 5 | * you may not use this file except in compliance with the License. | ||
1439 | 6 | * You may obtain a copy of the License at | ||
1440 | 7 | * | ||
1441 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1442 | 9 | * | ||
1443 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1444 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1445 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1446 | 13 | * See the License for the specific language governing permissions and | ||
1447 | 14 | * limitations under the License. | ||
1448 | 15 | */ | ||
1449 | 16 | |||
1450 | 17 | #define BOOST_TEST_DYN_LINK | ||
1451 | 18 | #define BOOST_TEST_MAIN | ||
1452 | 19 | #include <boost/test/unit_test.hpp> | ||
1453 | 20 | |||
1454 | 21 | #include "mtp.h" | ||
1455 | 22 | #include "MtpStorage.h" | ||
1456 | 23 | |||
1457 | 24 | using namespace android; | ||
1458 | 25 | |||
1459 | 26 | BOOST_AUTO_TEST_CASE(StorageConstructor) | ||
1460 | 27 | { | ||
1461 | 28 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, false, 64); | ||
1462 | 29 | |||
1463 | 30 | BOOST_CHECK(s); | ||
1464 | 31 | } | ||
1465 | 32 | |||
1466 | 33 | BOOST_AUTO_TEST_CASE(StorageGetTypeFixed) | ||
1467 | 34 | { | ||
1468 | 35 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, false, 64); | ||
1469 | 36 | |||
1470 | 37 | BOOST_CHECK (s->getType() == MTP_STORAGE_FIXED_RAM); | ||
1471 | 38 | } | ||
1472 | 39 | |||
1473 | 40 | BOOST_AUTO_TEST_CASE(StorageGetTypeRemovable) | ||
1474 | 41 | { | ||
1475 | 42 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, true, 64); | ||
1476 | 43 | |||
1477 | 44 | BOOST_CHECK (s->getType() == MTP_STORAGE_REMOVABLE_RAM); | ||
1478 | 45 | } | ||
1479 | 46 | |||
1480 | 47 | BOOST_AUTO_TEST_CASE(StorageGetFileSystemType) | ||
1481 | 48 | { | ||
1482 | 49 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, true, 64); | ||
1483 | 50 | |||
1484 | 51 | BOOST_CHECK (s->getFileSystemType() == MTP_STORAGE_FILESYSTEM_HIERARCHICAL); | ||
1485 | 52 | } | ||
1486 | 53 | |||
1487 | 54 | BOOST_AUTO_TEST_CASE(StorageGetAccessCapa) | ||
1488 | 55 | { | ||
1489 | 56 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, true, 64); | ||
1490 | 57 | |||
1491 | 58 | BOOST_CHECK (s->getAccessCapability() == MTP_STORAGE_READ_WRITE); | ||
1492 | 59 | } | ||
1493 | 60 | |||
1494 | 61 | BOOST_AUTO_TEST_CASE(StorageGetMaxCapacity) | ||
1495 | 62 | { | ||
1496 | 63 | MtpStorage *s = new MtpStorage (666, "/tmp", "Test storage", 0, true, 64); | ||
1497 | 64 | |||
1498 | 65 | BOOST_CHECK (s->getMaxCapacity() > 0); | ||
1499 | 66 | } | ||
1500 | 67 | |||
1501 | 68 | BOOST_AUTO_TEST_CASE(StorageGetMaxCapacityInvalidPath) | ||
1502 | 69 | { | ||
1503 | 70 | MtpStorage *s = new MtpStorage (666, "", "Test storage", 0, true, 64); | ||
1504 | 71 | |||
1505 | 72 | BOOST_CHECK (s->getMaxCapacity() == -1); | ||
1506 | 73 | } | ||
1507 | 74 | |||
1508 | 75 | BOOST_AUTO_TEST_CASE(StoageGetFreeSpace) | ||
1509 | 76 | { | ||
1510 | 77 | MtpStorage *s = new MtpStorage (666, "/", "Test storage", 0, true, 64); | ||
1511 | 78 | |||
1512 | 79 | BOOST_CHECK (s->getFreeSpace() != -1); | ||
1513 | 80 | } | ||
1514 | 81 | |||
1515 | 82 | BOOST_AUTO_TEST_CASE(StorageGetDescription) | ||
1516 | 83 | { | ||
1517 | 84 | MtpStorage *s = new MtpStorage (666, "/", "Test storage", 0, true, 64); | ||
1518 | 85 | |||
1519 | 86 | BOOST_CHECK_EQUAL( strcmp( s->getDescription(), "Test storage" ), 0); | ||
1520 | 87 | } | ||
1521 | 0 | 88 | ||
1522 | === added file 'tests/TestMtpUtils.cpp' | |||
1523 | --- tests/TestMtpUtils.cpp 1970-01-01 00:00:00 +0000 | |||
1524 | +++ tests/TestMtpUtils.cpp 2013-09-11 16:32:38 +0000 | |||
1525 | @@ -0,0 +1,48 @@ | |||
1526 | 1 | /* | ||
1527 | 2 | * Copyright (C) 2013 Canonical Ltd. | ||
1528 | 3 | * | ||
1529 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
1530 | 5 | * you may not use this file except in compliance with the License. | ||
1531 | 6 | * You may obtain a copy of the License at | ||
1532 | 7 | * | ||
1533 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
1534 | 9 | * | ||
1535 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
1536 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
1537 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
1538 | 13 | * See the License for the specific language governing permissions and | ||
1539 | 14 | * limitations under the License. | ||
1540 | 15 | */ | ||
1541 | 16 | |||
1542 | 17 | #define BOOST_TEST_DYN_LINK | ||
1543 | 18 | #define BOOST_TEST_MAIN | ||
1544 | 19 | #include <boost/test/unit_test.hpp> | ||
1545 | 20 | |||
1546 | 21 | #include <cstdlib> | ||
1547 | 22 | |||
1548 | 23 | // #include <cutils/tztime.h> | ||
1549 | 24 | #include "MtpUtils.h" | ||
1550 | 25 | |||
1551 | 26 | using namespace android; | ||
1552 | 27 | |||
1553 | 28 | BOOST_AUTO_TEST_CASE(UtilsParseDateTime) | ||
1554 | 29 | { | ||
1555 | 30 | time_t seconds; | ||
1556 | 31 | |||
1557 | 32 | setenv("TZ", "UTC", 1); | ||
1558 | 33 | |||
1559 | 34 | parseDateTime("20130909T114143", seconds); | ||
1560 | 35 | BOOST_CHECK_EQUAL(seconds, 1378726903l); | ||
1561 | 36 | } | ||
1562 | 37 | |||
1563 | 38 | BOOST_AUTO_TEST_CASE(UtilsFormatDateTime) | ||
1564 | 39 | { | ||
1565 | 40 | time_t seconds = 1378726903; | ||
1566 | 41 | char buffer[25]; | ||
1567 | 42 | char *expected = "20130909T114143"; | ||
1568 | 43 | |||
1569 | 44 | setenv("TZ", "UTC", 1); | ||
1570 | 45 | |||
1571 | 46 | formatDateTime(seconds, buffer, 25); | ||
1572 | 47 | BOOST_CHECK_EQUAL(strcmp(expected, buffer), 0); | ||
1573 | 48 | } |
105 + timeout=10 property_ service ]; do
106 + # loop 10 times and then exit, if the property service
107 + # isnt up after 80 sec # it is likely not starting at all
108 + while [ ! -e /dev/socket/
109 + sleep 8
110 + if [ "$timeout" -le 0 ]; then
111 + stop
112 + exit 0
113 + fi
114 + timeout=$(($timeout - 1))
115 + done
116 +
117 + if [ -x /usr/bin/setprop ]; then
118 + /usr/bin/setprop sys.usb.config mtp,adb
119 + fi
You don't need to go over the timeout logic if setprop is not available.
121 + start mtp-server
Why do we need to manually start the mtp-server if the other upstart job is already watching for android_ usb-device- changed udev events?
337 + readFiles( "/home/ phablet" );
How hard would it be to not make it hardcoded to phablet? Guess the server would be per user anyway, right?
Rest looks fine, need testing.