关于在android系统移植中usb的连接问题

来源:互联网 发布:优化win8 编辑:程序博客网 时间:2024/05/16 06:35

        近来在研究系统移植,出现了这样一个情况:连接usb线,usb Debugging connect(usb调试)显示正确,但是通知栏却没有出现usb连接的图标,statusBar也没有弹出连接usb的提示,故对此情况做出分析,找出原因所在。接下来的内容是记录自己寻找解决问题的整个过程。

这是log打印信息所示


显示ums连接失败


    首先从usb连接模式讲起,usb连接时,有两种模式,一种是AC模式(充电),另一种是usb模式(usb_storage connect和usb Debugging connect),具体的判断在之前的一篇日志里有说明,在这里不提,因为在sys文件系统里我找到了我的对应的两个文件

/sys/class/power_supply/ac/online   显示值为0;

/sys/class/power_supply/usb/online  显示值为1;

由此可以判断,内核判断正确,此错误不是出在内核上,问题应该在frame框架层接受参数出错


    接下来就重点于frame框架层的问题寻找。

                                                                                                                                            记于2012/11/16日

----------------------------------------------------------------------------------------------------------------------------------------


    查阅相关资料,和源代码,找到usb连接的相关类:

在系统级APK-SystemUI.apk 下的usb文件夹内找到以下类:

StorageNotification.java

UsbStorageActivity.java

这是另个正常的log信息:省略号为其他log信息,

--------- beginning of /dev/log/system
I/Vold    ( 1245): Vold 2.1 (the revenge) firing up
D/Vold    ( 1245): Volume sdcard state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 1245): Volume sdcard state changing 0 (No-Media) -> 2 (Pending)
D/Vold    ( 1245): Volume sdcard state changing 2 (Pending) -> 1 (Idle-Unmounted)
W/Vold    ( 1245): Ignoring unknown switch 'msm_hsusb_peripheral'
W/Vold    ( 1245): Ignoring unknown switch 'msm_hsusb_peripheral'
.............
I/SystemServer( 1327): USB Service
I/UsbService( 1327): This kernel does not have USB configuration switch support
I/UsbService( 1327): Trying legacy USB configuration switch support
W/UsbService( 1327): This kernel does not have USB composite class support
D/UsbService( 1327): diag contains non-numeric data
............
D/VoldCmdListener( 1245): share status ums
D/StorageNotification( 1453): Startup with UMS connection false (media state unmounted)
I/StorageNotification( 1453): UMS connection changed to true (media state unmounted)


现在遇到的问题就是最后一句,错误的log信息为UMS connection changed to false(media state unmounted)
这句话的log信息出自StorageNotification.java中的onUsbMassStorageConnectionChangedAsync方法中

private void onUsbMassStorageConnectionChangedAsync(boolean connected) {

       mUmsAvailable = connected;

      

       String st = Environment.getExternalStorageState();

       Slog.i(TAG, String.format("UMS connection changed to %s (media state %s)", connected, st));

       Slog.v(TAG, String.format("UMS connection changed to %s (media state %s)", connected, st));

       source code

      

       updateUsbMassStorageNotification(connected);

    }

最后调用了一个updateUsbMassStorageNotification()方法来传递参数connected(available或者unavailable)

void updateUsbMassStorageNotification(boolean available) {

        if (available) {

            Intent intent = new Intent();

            intent.setClass(mContext,com.android.systemui.usb.UsbStorageActivity.class);

           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            PendingIntent pi =PendingIntent.getActivity(mContext, 0, intent, 0);

            setUsbStorageNotification(

                   com.android.internal.R.string.usb_storage_notification_title,

                   com.android.internal.R.string.usb_storage_notification_message,

                   com.android.internal.R.drawable.stat_sys_data_usb,

                    false, true, pi);

        } else {

            setUsbStorageNotification(0, 0, 0,false, false, null);

        }

    }

从上边的update方法我们可以看出只要传递的connected参数为available时,将更新状态栏的信息,出现usb连接的title,

而connected的参数是从哪传来的呢?接下来我们再看一段log信息:

usb未连接

10-1116:51:19.714: DEBUG/Vold(70): USB disconnected

10-1116:51:19.714: DEBUG/Vold(70): Share method ums now unavailable

10-1116:51:19.734: INFO/StorageNotification(177): UMS connection changed to false(media state removed)

10-1116:51:19.734: VERBOSE/StorageNotification(177): UMS connection changed to false(media state removed)

10-1116:51:19.734: VERBOSE/StorageNotification(177): --------- beginning of/dev/log/main

10-1116:51:20.820: DEBUG/Tethering(112): InitialState.processMessage what=4

10-1116:51:20.820: DEBUG/Tethering(112): sendTetherStateChangedBroadcast 0, 0, 0

usb已连接

10-1116:51:30.101: DEBUG/Vold(70): USB connected

10-1116:51:30.101: DEBUG/Vold(70): Share method ums now available

10-1116:51:30.132: VERBOSE/Environment(177): getExternalStorageState()

10-1116:51:30.140: INFO/StorageNotification(177): UMS connection changed to true(media state removed)

10-1116:51:30.140: VERBOSE/StorageNotification(177): UMS connection changed to true(media state removed)

10-1116:51:30.156: DEBUG/Tethering(112): sendTetherStateChangedBroadcast 1, 0, 0

10-1116:51:30.156: DEBUG/Tethering(112): interfaceAdded :usb0

 从这段log里我们可以看到available这个参数是从vold底层传上来的

未完待续。。。

                                                                                                                                       记于2012/11/19日

----------------------------------------------------------------------------------------------------------------------------------