diff options
author | Josh Gao | 2018-01-02 14:01:43 -0600 |
---|---|---|
committer | Josh Gao | 2018-02-28 17:29:50 -0600 |
commit | 2776845aa534da492e90c9b3c7de094d6212c0f1 (patch) | |
tree | f733098713248168e0c26c3e984c266a6a7aa3e5 /diagnose_usb | |
parent | e2176118f4e7a9e2470310f978a40dbdcc904fb3 (diff) | |
download | platform-system-core-2776845aa534da492e90c9b3c7de094d6212c0f1.tar.gz platform-system-core-2776845aa534da492e90c9b3c7de094d6212c0f1.tar.xz platform-system-core-2776845aa534da492e90c9b3c7de094d6212c0f1.zip |
adb: switch over to Android.bp.
Rearrange some files while we're doing this.
Bug: http://b/71721338
Test: manually ran adb on windows
Change-Id: Ie47bda82279e4b9521505ad0353bf9ef649fc7d7
Diffstat (limited to 'diagnose_usb')
-rw-r--r-- | diagnose_usb/Android.bp | 13 | ||||
-rw-r--r-- | diagnose_usb/diagnose_usb.cpp | 86 | ||||
-rw-r--r-- | diagnose_usb/include/diagnose_usb.h | 27 |
3 files changed, 126 insertions, 0 deletions
diff --git a/diagnose_usb/Android.bp b/diagnose_usb/Android.bp new file mode 100644 index 000000000..a7ecf3737 --- /dev/null +++ b/diagnose_usb/Android.bp | |||
@@ -0,0 +1,13 @@ | |||
1 | cc_library_static { | ||
2 | name: "libdiagnose_usb", | ||
3 | cflags: ["-Wall", "-Wextra", "-Werror"], | ||
4 | host_supported: true, | ||
5 | target: { | ||
6 | windows: { | ||
7 | enabled: true, | ||
8 | }, | ||
9 | }, | ||
10 | srcs: ["diagnose_usb.cpp"], | ||
11 | export_include_dirs: ["include"], | ||
12 | static_libs: ["libbase"], | ||
13 | } | ||
diff --git a/diagnose_usb/diagnose_usb.cpp b/diagnose_usb/diagnose_usb.cpp new file mode 100644 index 000000000..5695ecec5 --- /dev/null +++ b/diagnose_usb/diagnose_usb.cpp | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #include "diagnose_usb.h" | ||
18 | |||
19 | #include <errno.h> | ||
20 | #include <unistd.h> | ||
21 | |||
22 | #include <string> | ||
23 | |||
24 | #include <android-base/stringprintf.h> | ||
25 | |||
26 | #if defined(__linux__) | ||
27 | #include <grp.h> | ||
28 | #include <pwd.h> | ||
29 | #endif | ||
30 | |||
31 | static const char kPermissionsHelpUrl[] = "http://developer.android.com/tools/device.html"; | ||
32 | |||
33 | // Returns a message describing any potential problems we find with udev, or an empty string if we | ||
34 | // can't find plugdev information (i.e. udev is not installed). | ||
35 | static std::string GetUdevProblem() { | ||
36 | #if defined(__linux__) && !defined(__BIONIC__) | ||
37 | errno = 0; | ||
38 | group* plugdev_group = getgrnam("plugdev"); | ||
39 | |||
40 | if (plugdev_group == nullptr) { | ||
41 | if (errno != 0) { | ||
42 | perror("failed to read plugdev group info"); | ||
43 | } | ||
44 | // We can't give any generally useful advice here, just let the caller print the help URL. | ||
45 | return ""; | ||
46 | } | ||
47 | |||
48 | // getgroups(2) indicates that the GNU group_member(3) may not check the egid so we check it | ||
49 | // additionally just to be sure. | ||
50 | if (group_member(plugdev_group->gr_gid) || getegid() == plugdev_group->gr_gid) { | ||
51 | // The user is in plugdev so the problem is likely with the udev rules. | ||
52 | return "user in plugdev group; are your udev rules wrong?"; | ||
53 | } | ||
54 | passwd* pwd = getpwuid(getuid()); | ||
55 | return android::base::StringPrintf("user %s is not in the plugdev group", | ||
56 | pwd ? pwd->pw_name : "?"); | ||
57 | #else | ||
58 | return ""; | ||
59 | #endif | ||
60 | } | ||
61 | |||
62 | // Short help text must be a single line, and will look something like: | ||
63 | // | ||
64 | // no permissions (reason); see [URL] | ||
65 | std::string UsbNoPermissionsShortHelpText() { | ||
66 | std::string help_text = "no permissions"; | ||
67 | |||
68 | std::string problem(GetUdevProblem()); | ||
69 | if (!problem.empty()) help_text += " (" + problem + ")"; | ||
70 | |||
71 | return android::base::StringPrintf("%s; see [%s]", help_text.c_str(), kPermissionsHelpUrl); | ||
72 | } | ||
73 | |||
74 | // Long help text can span multiple lines but doesn't currently provide more detailed information: | ||
75 | // | ||
76 | // insufficient permissions for device: reason | ||
77 | // See [URL] for more information | ||
78 | std::string UsbNoPermissionsLongHelpText() { | ||
79 | std::string header = "insufficient permissions for device"; | ||
80 | |||
81 | std::string problem(GetUdevProblem()); | ||
82 | if (!problem.empty()) header += ": " + problem; | ||
83 | |||
84 | return android::base::StringPrintf("%s\nSee [%s] for more information", header.c_str(), | ||
85 | kPermissionsHelpUrl); | ||
86 | } | ||
diff --git a/diagnose_usb/include/diagnose_usb.h b/diagnose_usb/include/diagnose_usb.h new file mode 100644 index 000000000..325b2e3b6 --- /dev/null +++ b/diagnose_usb/include/diagnose_usb.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 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 | #ifndef __DIAGNOSE_LINUX_USB_H | ||
18 | #define __DIAGNOSE_LINUX_USB_H | ||
19 | |||
20 | #include <string> | ||
21 | |||
22 | // USB permission error help text. The short version will be one line, long may be multi-line. | ||
23 | // Returns a string message to print, or an empty string if no problems could be found. | ||
24 | std::string UsbNoPermissionsShortHelpText(); | ||
25 | std::string UsbNoPermissionsLongHelpText(); | ||
26 | |||
27 | #endif | ||