Android 11 Framework修改默认usb连接模式为MTP模式

将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 {
                             // 20211024 FelixMa modify usb default value
                             //setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
			                 setEnabledFunctions(UsbManager.FUNCTION_MTP, false);
                        }
                    }
                    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 {
                 // 20211024 FelixMa modify usb default value
                 //setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
      	         setEnabledFunctions(UsbManager.FUNCTION_MTP, false);
            }
            if (mCurrentAccessory != null) {
                mUsbDeviceManager.getCurrentSettings().accessoryAttached(mCurrentAccessory);
            }
            updateUsbNotification(false);
            updateAdbNotification(false);
            updateUsbFunctions();
        }
    }
	
	 ...

你可能感兴趣的:(1024程序员节,mtp,android)