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

來源:互聯網
上載者:User

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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.