Android 8.1 USB连接模式默认为MTP

Android 8.1 USB连接模式默认为MTP

最近收到项目需求,要求设备默认的USB连接模式为MTP,具体修改参照如下:

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

        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 {
-                                setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
+                                setEnabledFunctions(UsbManager.FUNCTION_MTP, true);
                            }
                        }
        protected void finishBoot() {
            if (mBootCompleted && mCurrentUsbFunctionsReceived && mSystemReady) {
                if (mPendingBootBroadcast) {
                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                    mPendingBootBroadcast = false;
                }
                if (!mScreenLocked
                        && mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
                    setScreenUnlockedFunctions();
                } else {
-                    setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
+                    setEnabledFunctions(UsbManager.FUNCTION_MTP, true);
                }

重新编译验证,修改生效,设备默认的USB连接模式已设为MTP

相关推荐

  1. android 13.0 USB连接模式默认MTP

    2024-03-27 12:48:03       55 阅读
  2. Android 8.1 USB连接模式默认MTP

    2024-03-27 12:48:03       46 阅读
  3. Android 连接USB弹窗出来USB相关选项

    2024-03-27 12:48:03       37 阅读
  4. Android 10-13,默认屏幕亮度80%或100%

    2024-03-27 12:48:03       50 阅读
  5. Android8.1 MTK平台 修改蓝牙默认名称

    2024-03-27 12:48:03       38 阅读
  6. Android】设置三方应用默认Launcher

    2024-03-27 12:48:03       59 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 12:48:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 12:48:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 12:48:03       87 阅读
  4. Python语言-面向对象

    2024-03-27 12:48:03       96 阅读

热门阅读

  1. pytest和unittest 如何选择?

    2024-03-27 12:48:03       38 阅读
  2. Neuro-Linguistic Programming (NLP)

    2024-03-27 12:48:03       40 阅读
  3. Docker一键部署MySQL 8

    2024-03-27 12:48:03       42 阅读
  4. 单点服务向分布式微服务眼睛的过程

    2024-03-27 12:48:03       47 阅读
  5. 设计模式(3):工厂模式

    2024-03-27 12:48:03       37 阅读
  6. C++(7): std::list的使用

    2024-03-27 12:48:03       45 阅读
  7. MFC:组合框ComboBox的使用

    2024-03-27 12:48:03       38 阅读