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();
            }
        }
相关推荐
2401_897916064 小时前
Android 自定义 View _ 扭曲动效
android
天花板之恋5 小时前
Android AutoMotive --CarService
android·aaos·automotive
susu10830189118 小时前
Android Studio打包APK
android·ide·android studio
2401_897907869 小时前
Android 存储进化:分区存储
android
Dwyane0316 小时前
Android实战经验篇-AndroidScrcpyClient投屏一
android
FlyingWDX16 小时前
Android 拖转改变视图高度
android
_可乐无糖16 小时前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
一名技术极客18 小时前
Python 进阶 - Excel 基本操作
android·python·excel
我是大佬的大佬19 小时前
在Android Studio中如何实现综合实验MP3播放器(保姆级教程)
android·ide·android studio
lichong95119 小时前
【Flutter&Dart】MVVM(Model-View-ViewModel)架构模式例子-http版本(30 /100)
android·flutter·http·架构·postman·win·smartapi