Full access to external USB devices (such as external cameras):
override/frameworks/base/services/usb/java/com/android/server/usb/UsbUserSettingsManager.java
public boolean hasPermission(UsbDevicedevice, String packageName, int uid) {
/*/tyd.yantao 20230202 grant permission directly
if (isCameraDevicePresent(device)) {
if (!isCameraPermissionGranted(packageName, uid)) {
return false;
}
}
return mUsbPermissionManager.hasPermission(device, uid);
//*/
return true;
//*/
}
The specified button simulates the default function of other specified buttons, such as pressing a button twice to support hanging up the phone:
Under the corresponding key-value case
if (count == 2) {
TelephonyManager telephonyManager2 =(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if(telephonyManager2.getCallState() !=0){
sendFakeKey(KeyEvent.KEYCODE_ENDCALL);
}
Mainly these two methods, the parameters are different, anyway, the default is down, the second use generally involves the operation of up
private void sendFakeKey(int key) {
long now = SystemClock.uptimeMillis();
KeyEvent down = new KeyEvent(now, now, KeyEvent.ACTION_DOWN, key, 0);
InputManager.getInstance().injectInputEvent(down,InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
KeyEvent up = new KeyEvent(now, now, KeyEvent.ACTION_UP, key, 0);
InputManager.getInstance().injectInputEvent(up, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}
private void sendFakeKey(int key,String keyACTION) {
long now = SystemClock.uptimeMillis();
if(keyACTION=="down"){
KeyEvent down = newKeyEvent(now, now, KeyEvent.ACTION_DOWN, key, 0);
InputManager.getInstance().injectInputEvent(down,InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}else if(keyACTION=="up"){
KeyEvent up = new KeyEvent(now,now, KeyEvent.ACTION_UP, key, 0);
InputManager.getInstance().injectInputEvent(up,InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
}
}