use of android.hardware.usb.IUsbManager in project android_frameworks_base by ParanoidAndroid.
the class UsbDebuggingActivity method onClick.
@Override
public void onClick(DialogInterface dialog, int which) {
boolean allow = (which == AlertDialog.BUTTON_POSITIVE);
boolean alwaysAllow = allow && mAlwaysAllow.isChecked();
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
if (allow) {
service.allowUsbDebugging(alwaysAllow, mKey);
} else {
service.denyUsbDebugging();
}
} catch (Exception e) {
Log.e(TAG, "Unable to notify Usb service", e);
}
finish();
}
use of android.hardware.usb.IUsbManager in project android_frameworks_base by ParanoidAndroid.
the class UsbResolverActivity method onIntentSelected.
@Override
protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
final int uid = ri.activityInfo.applicationInfo.uid;
final int userId = UserHandle.myUserId();
if (mDevice != null) {
// grant permission for the device
service.grantDevicePermission(mDevice, uid);
// set or clear default setting
if (alwaysCheck) {
service.setDevicePackage(mDevice, ri.activityInfo.packageName, userId);
} else {
service.setDevicePackage(mDevice, null, userId);
}
} else if (mAccessory != null) {
// grant permission for the accessory
service.grantAccessoryPermission(mAccessory, uid);
// set or clear default setting
if (alwaysCheck) {
service.setAccessoryPackage(mAccessory, ri.activityInfo.packageName, userId);
} else {
service.setAccessoryPackage(mAccessory, null, userId);
}
}
try {
startActivityAsUser(intent, new UserHandle(userId));
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity failed", e);
}
} catch (RemoteException e) {
Log.e(TAG, "onIntentSelected failed", e);
}
}
use of android.hardware.usb.IUsbManager in project android_frameworks_base by ParanoidAndroid.
the class UsbCommand method run.
@Override
public void run(String[] args) {
boolean validCommand = false;
if (args.length >= 2) {
if ("setFunction".equals(args[1])) {
IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService(Context.USB_SERVICE));
try {
usbMgr.setCurrentFunction((args.length >= 3 ? args[2] : null), false);
} catch (RemoteException e) {
System.err.println("Error communicating with UsbManager: " + e);
}
return;
} else if ("getFunction".equals(args[1])) {
System.err.println(SystemProperties.get("sys.usb.config"));
return;
}
}
System.err.println(longHelp());
}
use of android.hardware.usb.IUsbManager in project android_frameworks_base by DirtyUnicorns.
the class UsbConfirmActivity method onClick.
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
final int uid = mResolveInfo.activityInfo.applicationInfo.uid;
final int userId = UserHandle.myUserId();
boolean alwaysUse = mAlwaysUse.isChecked();
Intent intent = null;
if (mDevice != null) {
intent = new Intent(UsbManager.ACTION_USB_DEVICE_ATTACHED);
intent.putExtra(UsbManager.EXTRA_DEVICE, mDevice);
// grant permission for the device
service.grantDevicePermission(mDevice, uid);
// set or clear default setting
if (alwaysUse) {
service.setDevicePackage(mDevice, mResolveInfo.activityInfo.packageName, userId);
} else {
service.setDevicePackage(mDevice, null, userId);
}
} else if (mAccessory != null) {
intent = new Intent(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
intent.putExtra(UsbManager.EXTRA_ACCESSORY, mAccessory);
// grant permission for the accessory
service.grantAccessoryPermission(mAccessory, uid);
// set or clear default setting
if (alwaysUse) {
service.setAccessoryPackage(mAccessory, mResolveInfo.activityInfo.packageName, userId);
} else {
service.setAccessoryPackage(mAccessory, null, userId);
}
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name));
startActivityAsUser(intent, new UserHandle(userId));
} catch (Exception e) {
Log.e(TAG, "Unable to start activity", e);
}
}
finish();
}
use of android.hardware.usb.IUsbManager in project android_frameworks_base by DirtyUnicorns.
the class UsbDebuggingActivity method onClick.
@Override
public void onClick(DialogInterface dialog, int which) {
boolean allow = (which == AlertDialog.BUTTON_POSITIVE);
boolean alwaysAllow = allow && mAlwaysAllow.isChecked();
try {
IBinder b = ServiceManager.getService(USB_SERVICE);
IUsbManager service = IUsbManager.Stub.asInterface(b);
if (allow) {
service.allowUsbDebugging(alwaysAllow, mKey);
} else {
service.denyUsbDebugging();
}
} catch (Exception e) {
Log.e(TAG, "Unable to notify Usb service", e);
}
finish();
}
Aggregations