summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBadhri Jagan Sridharan2017-12-02 15:15:01 -0600
committerBadhri Jagan Sridharan2018-01-16 20:03:58 -0600
commit5e1a0ca634382752d5f755ab7e0e301aff187df1 (patch)
tree82ad69ac64994863ae62670ab3ab0178e4593bd4
parentda007e0deb1f7149565766ae72499e48fb821bf0 (diff)
downloadplatform-system-core-5e1a0ca634382752d5f755ab7e0e301aff187df1.tar.gz
platform-system-core-5e1a0ca634382752d5f755ab7e0e301aff187df1.tar.xz
platform-system-core-5e1a0ca634382752d5f755ab7e0e301aff187df1.zip
Initial commit for usb daemon
usbd checks whether adb is enabled by default, if yes, would start adbd and would call into usb hal to configure usb gadget stack. Bug: 63669128 Test: Verify that adb gets configured when enabled Change-Id: If6d06cdadd6d93f181d56619142cbbb04d39a5cd
-rw-r--r--usbd/Android.bp16
-rw-r--r--usbd/usbd.cpp56
-rw-r--r--usbd/usbd.rc5
3 files changed, 77 insertions, 0 deletions
diff --git a/usbd/Android.bp b/usbd/Android.bp
new file mode 100644
index 000000000..4f9338fef
--- /dev/null
+++ b/usbd/Android.bp
@@ -0,0 +1,16 @@
1cc_binary {
2 name: "usbd",
3 init_rc: ["usbd.rc"],
4 srcs: ["usbd.cpp"],
5 shared_libs: [
6 "libbase",
7 "libhidlbase",
8 "libhidltransport",
9 "liblog",
10 "libutils",
11 "libhardware",
12 "android.hardware.usb.gadget@1.0",
13 "libcutils",
14 ],
15}
16
diff --git a/usbd/usbd.cpp b/usbd/usbd.cpp
new file mode 100644
index 000000000..41cd8dd9b
--- /dev/null
+++ b/usbd/usbd.cpp
@@ -0,0 +1,56 @@
1/*
2 * Copyright (C) 2018 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
17#define LOG_TAG "usbd"
18
19#include <string>
20
21#include <android-base/logging.h>
22#include <android-base/properties.h>
23#include <android/hardware/usb/gadget/1.0/IUsbGadget.h>
24
25#define PERSISTENT_USB_CONFIG "persist.sys.usb.config"
26
27using android::base::GetProperty;
28using android::base::SetProperty;
29using android::hardware::usb::gadget::V1_0::GadgetFunction;
30using android::hardware::usb::gadget::V1_0::IUsbGadget;
31using android::hardware::Return;
32
33int main(int /*argc*/, char** /*argv*/) {
34 android::sp<IUsbGadget> gadget = IUsbGadget::getService();
35 Return<void> ret;
36
37 if (gadget != nullptr) {
38 LOG(INFO) << "Usb HAL found.";
39 std::string function = GetProperty(PERSISTENT_USB_CONFIG, "");
40 if (function == "adb") {
41 LOG(INFO) << "peristent prop is adb";
42 SetProperty("ctl.start", "adbd");
43 ret = gadget->setCurrentUsbFunctions(static_cast<uint64_t>(GadgetFunction::ADB),
44 nullptr, 0);
45 } else {
46 LOG(INFO) << "Signal MTP to enable default functions";
47 ret = gadget->setCurrentUsbFunctions(static_cast<uint64_t>(GadgetFunction::MTP),
48 nullptr, 0);
49 }
50
51 if (!ret.isOk()) LOG(ERROR) << "Error while invoking usb hal";
52 } else {
53 LOG(INFO) << "Usb HAL not found";
54 }
55 exit(0);
56}
diff --git a/usbd/usbd.rc b/usbd/usbd.rc
new file mode 100644
index 000000000..c7838e831
--- /dev/null
+++ b/usbd/usbd.rc
@@ -0,0 +1,5 @@
1service usbd /system/bin/usbd
2 class late_start
3 oneshot
4 user root
5 group root usb