關於在android系統移植中usb的連接問題

已開通新的博客,後續文字都會發到新博客

http://www.0xfree.top

---

        近來在研究系統移植,出現了這樣一個情況:連接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日

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章