Usb: Add status check to prevent NPE
This patch prevents a Null Pointer Exception in queryMoistureDetectionStatus() when getPortStatusHelper() fails to open the /sys/class/typec file. The failure results in an empty currentPortStatus vector, causing the NPE when accessing its first element. Bug: 361097811 Flag: EXEMPT bugfix Test: NPE does not occur when getPortStatusHelper() fails Change-Id: Id6886283d6f2f9179b3a9c5d535646874e9f277b Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
This commit is contained in:
parent
e471d73857
commit
7ed8a55835
1 changed files with 14 additions and 10 deletions
|
@ -943,6 +943,7 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
|
|||
Status status;
|
||||
pthread_mutex_lock(&usb->mLock);
|
||||
status = getPortStatusHelper(usb, currentPortStatus);
|
||||
if (status == Status::SUCCESS && currentPortStatus->size() > 0) {
|
||||
queryMoistureDetectionStatus(usb, currentPortStatus);
|
||||
queryPowerTransferStatus(usb, currentPortStatus);
|
||||
queryNonCompliantChargerStatus(currentPortStatus);
|
||||
|
@ -955,6 +956,9 @@ void queryVersionHelper(android::hardware::usb::Usb *usb,
|
|||
} else {
|
||||
ALOGI("Notifying userspace skipped. Callback is NULL");
|
||||
}
|
||||
} else {
|
||||
ALOGI("%s skipped. currentPortStatus is empty", __func__);
|
||||
}
|
||||
pthread_mutex_unlock(&usb->mLock);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue