概述
01)设置包中对mUsbManager的调用
mUsbManager.setCurrentFunction(function, false);
---> frameworks/base/core/java/android/hardware/usb/UsbManager.java
/**
* Sets the current USB function.
* If function is null, then the current function is set to the default function.
*
* @param function name of the USB function, or null to restore the default function
* @param makeDefault true if the function should be set as the new default function
*
* {@hide}
*/
public void setCurrentFunction(String function, boolean makeDefault) {
try {
mService.setCurrentFunction(function, makeDefault);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in setCurrentFunction", e);
}
}
/*mService 的赋值之处如下*/
/**
* {@hide}
*/
public UsbManager(Context context, IUsbManager service) {
mContext = context;
mService = service;
}
----->frameworks/base/core/java/android/hardware/usb/IUsbManager.aidl
/* Sets the current USB function. */
void setCurrentFunction(String function, boolean makeDefault);
该文件具体实现在如下文件
------->frameworks/base/services/usb/java/com/android/server/usb/UsbService.java
@Override
public void setCurrentFunction(String function, boolean makeDefault) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
// If attempt to change USB function while file transfer is restricted, ensure that
// the current function is set to "none", and return.
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
if (userManager.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
if (mDeviceManager != null) mDeviceManager.setCurrentFunctions("none", false);
return;
}
if (mDeviceManager != null) {
mDeviceManager.setCurrentFunctions(function, makeDefault);
} else {
throw new IllegalStateException("USB device mode not supported");
}
}
如此,便调到了最常用的类frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
public void setCurrentFunctions(String functions, boolean makeDefault) {
if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ") default: " + makeDefault);
mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, makeDefault);
}
.........
<pre name="code" class="java"> case MSG_SET_CURRENT_FUNCTIONS:
String functions = (String)msg.obj;
boolean makeDefault = (msg.arg1 == 1);
mSettingUsbCharging = false;
mSettingUsbBicr = false;
/* In BICR evo, it's hard to confirm that the current disconnect is caused by switching usb function or unplugging usb cable*/
/* So add a flag to know it*/
mIsUserSwitch = true;
if (functions != null && functions.equals(UsbManager.USB_FUNCTION_CHARGING_ONLY)) {
mSettingUsbCharging = true;
mCurrentFunctions = removeFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_MTP);
mCurrentFunctions = removeFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_PTP);
updateUsbState();
if (DEBUG) Slog.d(TAG, "handleMessage - MSG_SET_CURRENT_FUNCTION - CHARGING_ONLY - makeDefault: " + makeDefault);
} else if (functions != null && functions.equals(UsbManager.USB_FUNCTION_BICR)) {
mSettingUsbBicr = true;
if (DEBUG) Slog.d(TAG, "handleMessage - MSG_SET_CURRENT_FUNCTION - BICR - makeDefault: " + makeDefault);
} else if (functions == null && mDefaultFunctions.equals(UsbManager.USB_FUNCTION_CHARGING_ONLY)) {
functions = mDefaultFunctions;
mSettingUsbCharging = true;
makeDefault = true;
updateUsbState();
if (DEBUG) Slog.d(TAG, "handleMessage - MSG_SET_CURRENT_FUNCTION - [Tethering Off] USB_FUNCTION_CHARGING_ONLY - makeDefault: " + makeDefault);
}
setEnabledFunctions(functions, makeDefault);
mIsUserSwitch = false;
//ALPS00428998
if(mMtpAskDisconnect) mMtpAskDisconnect = false;
//ALPS00428998
if (DEBUG) Slog.d(TAG, "handleMessage - MSG_SET_CURRENT_FUNCTION - functions: " + functions);
break;
最后有一点说明:
与usb相关的两个系统属性值:'persist.sys.usb.config'和'sys.usb.config'
reboot之后是不是默认的charging模式,主要是看'persist.sys.usb.config'属性值是不是'charging'(或者'charging,adb'),插拔usb线会不会到默认的功能是看'sys.usb.config'属性值是不是'charging'(或者'charging,adb').
也可参详http://blog.csdn.net/lylianlll/article/details/8446675
http://blog.csdn.net/chief1985/article/details/4551242
最后
以上就是欣慰茉莉为你收集整理的USB----调用过程和简单解释的全部内容,希望文章能够帮你解决USB----调用过程和简单解释所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复