USB----调用过程和简单解释
2016-02-02 15:35
363 查看
01)设置包中对mUsbManager的调用
mUsbManager.setCurrentFunction(function, false);
---> frameworks/base/core/java/android/hardware/usb/UsbManager.java
----->frameworks/base/core/java/android/hardware/usb/IUsbManager.aidl
该文件具体实现在如下文件
------->frameworks/base/services/usb/java/com/android/server/usb/UsbService.java
如此,便调到了最常用的类frameworks/base/services/usb/java/com/android/server/usb/UsbDeviceManager.java
最后有一点说明:
与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
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
相关文章推荐
- 基于webpack的模块化构建
- Selenium——selenium之利用excel实现参数化
- 字节、字、bit、byte的关系
- UESTC(LCA应用:求两点之间的距离)
- LightOJ--1149--Factors and Multiples(二分图好题)
- JavaWeb中读取文件资源的路径问题
- 使用process_monitor.sh监控hadoop进程的crontab配置
- Win8.1更新补丁提示8024402F错误的原因及解决方法
- 提升linux下tcp服务器并发连接数限制
- Android中的动画效果
- 【转】Android LockScreen admin API sample code
- LXC内启动NFS服务(NFS server on LXC)
- Inno Step 安装包程序 写INI配置文件脚本
- Linux命令行学习之路(五)
- Linux命令行学习之路(五)
- SQLite数据库创建、升级数据库、事务处理、添加、更新、删除、查询管理操作类完整代码
- 青瓷引擎使用心得——修改引擎的loading界面
- javascript实现键盘按下回车时触发
- oracle视图
- bzoj 2194快速傅立叶之二