Fix race condition in MTP/PTP checkbox updating
UsbManager.getDefaultFunction() might not return the updated state immediately after changing the USB configuration, so do not rely on it for updating after a checkbox has been clicked. Change-Id: I5ae8d46854f24403cda2c62e006c742dcd257d1d Bug: 5334777 Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -51,7 +51,7 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
|
|
||||||
private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
|
||||||
public void onReceive(Context content, Intent intent) {
|
public void onReceive(Context content, Intent intent) {
|
||||||
updateToggles();
|
updateToggles(mUsbManager.getDefaultFunction());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,8 +94,7 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
new IntentFilter(UsbManager.ACTION_USB_STATE));
|
new IntentFilter(UsbManager.ACTION_USB_STATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateToggles() {
|
private void updateToggles(String function) {
|
||||||
String function = mUsbManager.getDefaultFunction();
|
|
||||||
if (UsbManager.USB_FUNCTION_MTP.equals(function)) {
|
if (UsbManager.USB_FUNCTION_MTP.equals(function)) {
|
||||||
mMtp.setChecked(true);
|
mMtp.setChecked(true);
|
||||||
mPtp.setChecked(false);
|
mPtp.setChecked(false);
|
||||||
@@ -122,10 +121,11 @@ public class UsbSettings extends SettingsPreferenceFragment {
|
|||||||
}
|
}
|
||||||
if (preference == mMtp) {
|
if (preference == mMtp) {
|
||||||
mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);
|
mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_MTP, true);
|
||||||
|
updateToggles(UsbManager.USB_FUNCTION_MTP);
|
||||||
} else if (preference == mPtp) {
|
} else if (preference == mPtp) {
|
||||||
mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true);
|
mUsbManager.setCurrentFunction(UsbManager.USB_FUNCTION_PTP, true);
|
||||||
|
updateToggles(UsbManager.USB_FUNCTION_PTP);
|
||||||
}
|
}
|
||||||
updateToggles();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user