Android 一连接USB就弹窗显示USB选项,与默认MTP文件传输设置

/frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java

复制代码
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_UPDATE_STATE:
                    mConnected = (msg.arg1 == 1);
                    mConfigured = (msg.arg2 == 1);

                    updateUsbNotification(false);
                    updateAdbNotification(false);
                    if (mBootCompleted) {
                        updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                    }
                    if ((mCurrentFunctions & UsbManager.FUNCTION_ACCESSORY) != 0) {
                        updateCurrentAccessory();
                    }
                    if (mBootCompleted) {
                        if (!mConnected && !hasMessages(MSG_ACCESSORY_MODE_ENTER_TIMEOUT)
                                && !hasMessages(MSG_FUNCTION_SWITCH_TIMEOUT)) {
                            // restore defaults when USB is disconnected
                            if (!mScreenLocked
                                    && mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
                                setScreenUnlockedFunctions();
                            } else {
                                //*/add def mtp
                                setEnabledFunctions(UsbManager.FUNCTION_MTP, true);
                                /*/
                                setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
                                //*/
                            }
                        } 
                      //*/add,connect usb jump dialog activity
                          else {
                                Intent intent2 = new Intent();
                                intent2.setClassName("com.android.settings", "com.android.settings.Settings$UsbDetailsActivity");
                                intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                mContext.startActivity(intent2);
                                //*/
                        }
                        updateUsbFunctions();
                    } else {
                        mPendingBootBroadcast = true;
                    }
                    break;

  protected void finishBoot() {
            if (mBootCompleted && mCurrentUsbFunctionsReceived && mSystemReady) {

                if (mPendingBootBroadcast) {
                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                    mPendingBootBroadcast = false;
                }
                if (!mScreenLocked
                        && mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
                    setScreenUnlockedFunctions();
                } else {
                     /*/ add Default mtp.2th
                    setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
                    //*/
                    setEnabledFunctions(UsbManager.FUNCTION_MTP, true);
                    //*/
                }
                if (mCurrentAccessory != null) {
                    mUsbDeviceManager.getCurrentSettings().accessoryAttached(mCurrentAccessory);
                }

                updateUsbNotification(false);
                updateAdbNotification(false);
                updateUsbFunctions();
            }
        }
相关推荐
Wgllss1 小时前
雷电雨效果:Kotlin+Compose+协程+Flow 实现天气UI
android·架构·android jetpack
用户207038619493 小时前
Compose 可点击文本:ClickableText Compose 中的 ClickableSpan
android
常利兵3 小时前
Kotlin作用域函数全解:run/with/apply/let/also与this/it的魔法对决
android·开发语言·kotlin
幼稚园的山代王3 小时前
Kotlin-基础语法练习一
android·开发语言·kotlin
闻不多3 小时前
用llamaindex搭建GAR遇到400
android·运维·服务器
阿华的代码王国3 小时前
【Android】适配器与外部事件的交互
android·xml·java·前端·后端·交互
跨界混迹车辆网的Android工程师4 小时前
实现Android图片手势缩放功能的完整自定义View方案,结合了多种手势交互功能
android·交互
wyjcxyyy4 小时前
打靶日记-PHPSerialize
android
安卓开发者15 小时前
Android RxJava 组合操作符实战:优雅处理多数据源
android·rxjava
阿华的代码王国15 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端