现象:Android P 版本使用OTG时,直接入OTG线未接入设备,下拉栏会显示
“Android系统.正在通过USB为连接的设备充电”
原因:Android P 新增的USB特性导致,控制的宏开关为CONFIG_DUAL_ROLE_USB_INTF,用于控制两用OTG USB。
解决:若只做OTG功能,关闭该宏开关,但是会造成正常PC接入设备USB选择栏为灰色不可选,只能到开发者选项中修改USB默认模式。否则只能上层修改显示信息。
上层修改如下,规避不显示:
frameworks\base\services\usb\java\com\android\server\usb\UsbDeviceManager.java
protected void updateUsbNotification(boolean force) {
if (mNotificationManager == null || !mUseUsbNotification
|| ("0".equals(getSystemProperty("persist.charging.notify", "")))) {
return;
}
...
int id = 0;
int titleRes = 0;
Resources r = mContext.getResources();
CharSequence message = r.getText(
com.android.internal.R.string.usb_notification_message);
if (mAudioAccessoryConnected && !mAudioAccessorySupported) {
...
} else if (mConnected) {
...
// } else if (mSourcePower) {
//修改为如下
} else if (SourcePower && !"project_name".equals(SystemProperties.get("ro.product.device_group",""))) {
Slog.d(TAG, "[ malata debug : ] ************** NOTE_USB_SUPPLYING");
titleRes = com.android.internal.R.string.usb_supplying_notification_title;
id = SystemMessage.NOTE_USB_SUPPLYING;
} else if (mHostConnected && mSinkPower && mUsbCharging) {
...
}
project_name为该项目名称。ro.product.device_group的赋值在
\device\malata\{project_name}\system.prop文件中ro.product.device_group=project_name一致