Skip to content

Commit d4fa741

Browse files
Jimmy HuReallySnow
Jimmy Hu
authored andcommitted
b1c1: Write the pullup value only if new value applied
Also, remove the non-existing paths and set the initial value of mUsbDataEnabled. Bug: 221009551 Test: build, boot Signed-off-by: Jimmy Hu <[email protected]> Change-Id: I30033a9dc5e2ccfd1fe1dcc5fe8a7796c56fce75
1 parent 5210fb3 commit d4fa741

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

Diff for: usb/usb/Usb.cpp

+21-19
Original file line numberDiff line numberDiff line change
@@ -57,40 +57,41 @@ ScopedAStatus Usb::enableUsbData(const string& in_portName, bool in_enable,
5757
int64_t in_transactionId) {
5858
bool result = true;
5959
std::vector<PortStatus> currentPortStatus;
60+
string pullup;
6061

6162
ALOGI("Userspace turn %s USB data signaling. opID:%ld", in_enable ? "on" : "off",
6263
in_transactionId);
6364

6465
if (in_enable) {
65-
if (!WriteStringToFile("1", USB_DATA_PATH)) {
66-
ALOGE("Not able to turn on usb connection notification");
67-
result = false;
66+
if (ReadFileToString(PULLUP_PATH, &pullup)) {
67+
pullup = Trim(pullup);
68+
if (pullup != kGadgetName) {
69+
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
70+
ALOGE("Gadget cannot be pulled up");
71+
result = false;
72+
}
73+
}
6874
}
6975

70-
if (!WriteStringToFile(kGadgetName, PULLUP_PATH)) {
71-
ALOGE("Gadget cannot be pulled up");
76+
if (!WriteStringToFile("1", USB_DATA_PATH)) {
77+
ALOGE("Not able to turn on usb connection notification");
7278
result = false;
7379
}
7480
} else {
75-
if (!WriteStringToFile("1", ID_PATH)) {
76-
ALOGE("Not able to turn off host mode");
77-
result = false;
78-
}
79-
80-
if (!WriteStringToFile("0", VBUS_PATH)) {
81-
ALOGE("Not able to set Vbus state");
82-
result = false;
81+
if (ReadFileToString(PULLUP_PATH, &pullup)) {
82+
pullup = Trim(pullup);
83+
if (pullup == kGadgetName) {
84+
if (!WriteStringToFile("none", PULLUP_PATH)) {
85+
ALOGE("Gadget cannot be pulled down");
86+
result = false;
87+
}
88+
}
8389
}
8490

8591
if (!WriteStringToFile("0", USB_DATA_PATH)) {
8692
ALOGE("Not able to turn on usb connection notification");
8793
result = false;
8894
}
89-
90-
if (!WriteStringToFile("none", PULLUP_PATH)) {
91-
ALOGE("Gadget cannot be pulled down");
92-
result = false;
93-
}
9495
}
9596

9697
if (result) {
@@ -322,7 +323,8 @@ Usb::Usb()
322323
: mLock(PTHREAD_MUTEX_INITIALIZER),
323324
mRoleSwitchLock(PTHREAD_MUTEX_INITIALIZER),
324325
mPartnerLock(PTHREAD_MUTEX_INITIALIZER),
325-
mPartnerUp(false) {
326+
mPartnerUp(false),
327+
mUsbDataEnabled(true) {
326328
pthread_condattr_t attr;
327329
if (pthread_condattr_init(&attr)) {
328330
ALOGE("pthread_condattr_init failed: %s", strerror(errno));

Diff for: usb/usb/Usb.h

-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ using ::std::shared_ptr;
4343
using ::std::string;
4444

4545
constexpr char kGadgetName[] = "a600000.dwc3";
46-
#define ID_PATH SOC_PATH "id"
4746
#define PULLUP_PATH "/config/usb_gadget/g1/UDC"
4847
#define SOC_PATH "/sys/devices/platform/soc/a600000.ssusb/"
4948
#define USB_DATA_PATH SOC_PATH "usb_data_enabled"
50-
#define VBUS_PATH SOC_PATH "b_sess"
5149

5250
struct Usb : public BnUsb {
5351
Usb();

0 commit comments

Comments
 (0)