hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
From 2bf12a6c7c52f88fd9ef4cd5652d1391a7b3f25c Mon Sep 17 00:00:00 2001
From: "zain.wang" <wzz@rock-chips.com>
Date: Thu, 9 Aug 2018 10:22:20 +0800
Subject: [PATCH 1/3] Fix compile error
 
Remove some code about dbus and properties.
 
Signed-off-by: zain.wang <wzz@rock-chips.com>
---
 CMakeLists.txt        |   3 +-
 server/CMakeLists.txt |   1 -
 server/server.cpp     | 120 +-----------------------------------------
 src/MtpServer.cpp     |  10 ++--
 4 files changed, 7 insertions(+), 127 deletions(-)
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46bff47..707b7f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,7 +14,7 @@ set(MTP_VERSION_MINOR 0)
 set(MTP_VERSION_PATCH 0)
 
 find_package(Boost REQUIRED COMPONENTS thread system filesystem unit_test_framework)
-pkg_check_modules(DBUSCPP REQUIRED dbus-cpp)
+pkg_check_modules(DBUSCPP REQUIRED dbus-c++-1)
 pkg_check_modules(GLOG REQUIRED libglog)
 
 set(
@@ -71,7 +71,6 @@ add_library(
 
 target_link_libraries(
   mtpserver
-  android-properties
   ${GLOG_LIBRARIES}
   ${DBUSCPP_LIBRARIES}
 )
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index 411ff46..9acb974 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -11,7 +11,6 @@ target_link_libraries(
     mtp-server
     mtpserver
     usbhost
-    android-properties
     ${Boost_LIBRARIES}
     ${Boost_thread_LIBRARIES}
     ${Boost_system_LIBRARIES}
diff --git a/server/server.cpp b/server/server.cpp
index 0a9a846..d08c13c 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -32,73 +32,10 @@
 #include <libintl.h>
 #include <locale.h>
 
-#include <hybris/properties/properties.h>
 #include <glog/logging.h>
 
-#include <core/dbus/bus.h>
-#include <core/dbus/object.h>
-#include <core/dbus/property.h>
-#include <core/dbus/service.h>
-#include <core/dbus/signal.h>
-
-#include <core/dbus/asio/executor.h>
-#include <core/dbus/types/stl/tuple.h>
-#include <core/dbus/types/stl/vector.h>
-#include <core/dbus/types/struct.h>
-
-
-namespace dbus = core::dbus;
 using namespace android;
 
-namespace core
-{
-dbus::Bus::Ptr the_session_bus()
-{
-    static dbus::Bus::Ptr session_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::session);
-    return session_bus;
-}
-
-struct UnityGreeter
-{
-    struct Properties
-    {
-        struct IsActive
-        {
-            inline static std::string name()
-            {
-                return "IsActive";
-            };
-            typedef UnityGreeter Interface;
-            typedef bool ValueType;
-            static const bool readable = true;
-            static const bool writable = false;
-        };
-    };
-};
-}
-
-namespace core
-{
-namespace dbus
-{
-namespace traits
-{
-template<>
-struct Service<core::UnityGreeter>
-{
-    inline static const std::string& interface_name()
-    {
-        static const std::string s
-        {
-            "com.canonical.UnityGreeter"
-        };
-        return s;
-    }
-};
-}
-}
-}
-
 namespace
 {
 struct FileSystemConfig
@@ -114,7 +51,6 @@ class MtpDaemon
 
 private:
     struct passwd *userdata;
-    dbus::Bus::Ptr bus;
     boost::thread dbus_thread;
 
     // Mtp stuff
@@ -124,8 +60,7 @@ private:
     MtpDatabase* mtp_database;
 
     // Security
-    std::shared_ptr<core::dbus::Property<core::UnityGreeter::Properties::IsActive> > is_active;
-    bool screen_locked = true;
+    bool screen_locked = false;
 
     // inotify stuff
     boost::thread notifier_thread;
@@ -242,17 +177,6 @@ private:
         read_more_notify();
     }
 
-    void drive_bus()
-    {
-        try {
-            bus->run();
-        }
-        catch (...) {
-            PLOG(ERROR) << "There was an unexpected error in DBus; terminating.";
-            server->stop();
-        }
-    }
-
 public:
 
     MtpDaemon(int fd):
@@ -285,28 +209,14 @@ public:
                 userdata->pw_gid,
                 FileSystemConfig::file_perm,
                 FileSystemConfig::directory_perm);
-
-        // security / screen locking
-        bus = core::the_session_bus();
-        bus->install_executor(core::dbus::asio::make_executor(bus));
-        dbus_thread = boost::thread(&MtpDaemon::drive_bus, this);
-        auto greeter_service = dbus::Service::use_service(bus, "com.canonical.UnityGreeter");
-        dbus::Object::Ptr greeter = greeter_service->object_for_path(dbus::types::ObjectPath("/"));
-
-        is_active = greeter->get_property<core::UnityGreeter::Properties::IsActive>();
     }
 
     void initStorage()
     {
-        char product_name[PROP_VALUE_MAX];
-
-        // Local storage
-        property_get ("ro.product.model", product_name, "Ubuntu Touch device");
-
         home_storage = new MtpStorage(
             MTP_STORAGE_FIXED_RAM,
             userdata->pw_dir,
-        product_name,
+            "MTP",
             1024 * 1024 * 100,  /* 100 MB reserved space, to avoid filling the disk */
             false,
             0  /* Do not check sizes for internal storage */);
@@ -360,31 +270,6 @@ public:
 
     void run()
     {
-        if (is_active->get()) {
-            is_active->changed().connect([this](bool active)
-            {
-                if (!active) {
-                    screen_locked = active;
-                    VLOG(2) << "device was unlocked, adding storage";
-                    if (home_storage && !home_storage_added) {
-                        server->addStorage(home_storage);
-                        home_storage_added = true;
-                    }
-                    BOOST_FOREACH(std::string name, removables | boost::adaptors::map_keys) {
-                        auto t = removables.at(name);
-                        MtpStorage *storage = std::get<0>(t);
-                        bool added = std::get<1>(t);
-                        if (!added) {
-                            mtp_database->addStoragePath(storage->getPath(),
-                                                         std::string(),
-                                                         storage->getStorageID(),
-                                                         true);
-                            server->addStorage(storage);
-                        }
-                    }
-                }
-            });
-        } else {
             screen_locked = false;
             VLOG(2) << "device is not locked, adding storage";
             if (home_storage) {
@@ -403,7 +288,6 @@ public:
                     server->addStorage(storage);
                 }
             }
-        }
 
         // start the MtpServer main loop
         server->run();
diff --git a/src/MtpServer.cpp b/src/MtpServer.cpp
index b2d9e9c..ba95c5a 100644
--- a/src/MtpServer.cpp
+++ b/src/MtpServer.cpp
@@ -41,8 +41,6 @@
 
 #include <linux/usb/f_mtp.h>
 
-#include <hybris/properties/properties.h>
-
 #include <glog/logging.h>
 
 namespace android {
@@ -468,7 +466,7 @@ bool MtpServer::handleRequest() {
 MtpResponseCode MtpServer::doGetDeviceInfo() {
     VLOG(1) <<  __PRETTY_FUNCTION__;
     MtpStringBuffer   string;
-    char prop_value[PROP_VALUE_MAX];
+    char prop_value[64];
 
     MtpObjectFormatList* playbackFormats = mDatabase->getSupportedPlaybackFormats();
     MtpObjectFormatList* captureFormats = mDatabase->getSupportedCaptureFormats();
@@ -500,17 +498,17 @@ MtpResponseCode MtpServer::doGetDeviceInfo() {
     mData.putAUInt16(captureFormats); // Capture Formats
     mData.putAUInt16(playbackFormats);  // Playback Formats
 
-    property_get("ro.product.manufacturer", prop_value, "unknown manufacturer");
+    strcpy(prop_value, "---MANUFACTURER---");
     string.set(prop_value);
     mData.putString(string);   // Manufacturer
 
-    property_get("ro.product.model", prop_value, "MTP Device");
+    strcpy(prop_value, "---MODEL---");
     string.set(prop_value);
     mData.putString(string);   // Model
     string.set("1.0");
     mData.putString(string);   // Device Version
 
-    property_get("ro.serialno", prop_value, "????????");
+    strcpy(prop_value, "---SERIAL---");
     string.set(prop_value);
     mData.putString(string);   // Serial Number
 
-- 
2.17.1