Loading core/java/android/app/ContextImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -1158,7 +1158,7 @@ class ContextImpl extends Context { if (mUsbManager == null) { IBinder b = ServiceManager.getService(USB_SERVICE); IUsbManager service = IUsbManager.Stub.asInterface(b); mUsbManager = new UsbManager(service); mUsbManager = new UsbManager(this, service); } } return mUsbManager; Loading core/java/android/hardware/usb/IUsbManager.aidl +13 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.hardware.usb; import android.app.PendingIntent; import android.hardware.usb.UsbAccessory; import android.os.Bundle; import android.os.ParcelFileDescriptor; Loading @@ -36,12 +37,22 @@ interface IUsbManager */ void setAccessoryPackage(in UsbAccessory accessory, String packageName); /* Returns true if the caller has permission to access the accessory. */ boolean hasAccessoryPermission(in UsbAccessory accessory); /* Requests permission for the given package to access the accessory. * Will display a system dialog to query the user if permission * had not already been given. Result is returned via pi. */ void requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi); /* Grants permission for the given UID to access the accessory */ void grantAccessoryPermission(in UsbAccessory accessory, int uid); /* Returns true if the USB manager has default preferences or permissions for the package */ boolean hasDefaults(String packageName, int uid); boolean hasDefaults(String packageName); /* Clears default preferences and permissions for the package */ oneway void clearDefaults(String packageName, int uid); void clearDefaults(String packageName); } core/java/android/hardware/usb/UsbAccessory.java +43 −15 Original line number Diff line number Diff line Loading @@ -31,18 +31,21 @@ public class UsbAccessory implements Parcelable { private final String mManufacturer; private final String mModel; private final String mType; private final String mDescription; private final String mVersion; private final String mUri; /** * UsbAccessory should only be instantiated by UsbService implementation * @hide */ public UsbAccessory(String manufacturer, String model, String type, String version) { public UsbAccessory(String manufacturer, String model, String description, String version, String uri) { mManufacturer = manufacturer; mModel = model; mType = type; mDescription = description; mVersion = version; mUri = uri; } /** Loading @@ -52,8 +55,9 @@ public class UsbAccessory implements Parcelable { public UsbAccessory(String[] strings) { mManufacturer = strings[0]; mModel = strings[1]; mType = strings[2]; mDescription = strings[2]; mVersion = strings[3]; mUri = strings[4]; } /** Loading @@ -75,12 +79,12 @@ public class UsbAccessory implements Parcelable { } /** * Returns the type of the accessory. * Returns a user visible description of the accessory. * * @return the accessory type * @return the accessory description */ public String getType() { return mType; public String getDescription() { return mDescription; } /** Loading @@ -92,6 +96,17 @@ public class UsbAccessory implements Parcelable { return mVersion; } /** * Returns the URI for the accessory. * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI */ public String getUri() { return mUri; } private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); Loading @@ -103,18 +118,29 @@ public class UsbAccessory implements Parcelable { UsbAccessory accessory = (UsbAccessory)obj; return (compare(mManufacturer, accessory.getManufacturer()) && compare(mModel, accessory.getModel()) && compare(mType, accessory.getType()) && compare(mVersion, accessory.getVersion())); compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && compare(mUri, accessory.getUri())); } return false; } @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode())); } @Override public String toString() { return "UsbAccessory[mManufacturer=" + mManufacturer + ", mModel=" + mModel + ", mType=" + mType + ", mVersion=" + mVersion + "]"; ", mDescription=" + mDescription + ", mVersion=" + mVersion + ", mUri=" + mUri + "]"; } public static final Parcelable.Creator<UsbAccessory> CREATOR = Loading @@ -122,9 +148,10 @@ public class UsbAccessory implements Parcelable { public UsbAccessory createFromParcel(Parcel in) { String manufacturer = in.readString(); String model = in.readString(); String type = in.readString(); String description = in.readString(); String version = in.readString(); return new UsbAccessory(manufacturer, model, type, version); String uri = in.readString(); return new UsbAccessory(manufacturer, model, description, version, uri); } public UsbAccessory[] newArray(int size) { Loading @@ -139,7 +166,8 @@ public class UsbAccessory implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeString(mManufacturer); parcel.writeString(mModel); parcel.writeString(mType); parcel.writeString(mDescription); parcel.writeString(mVersion); parcel.writeString(mUri); } } core/java/android/hardware/usb/UsbManager.java +61 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.hardware.usb; import android.app.PendingIntent; import android.content.Context; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; Loading Loading @@ -75,7 +77,7 @@ public class UsbManager { * * This intent is sent when a USB accessory is detached. * <ul> * <li> {@link #EXTRA_ACCESSORY} containing the {@link android.hardware.usb.UsbAccessory} * <li> {@link #EXTRA_ACCESSORY} containing the {@link UsbAccessory} * for the attached accessory that was detached * </ul> */ Loading Loading @@ -145,12 +147,22 @@ public class UsbManager { */ public static final String EXTRA_ACCESSORY = "accessory"; private IUsbManager mService; /** * Name of extra added to the {@link android.app.PendingIntent} * passed into {@link #requestPermission(UsbDevice, PendingIntent)} * or {@link #requestPermission(UsbAccessory, PendingIntent)} * containing a boolean value indicating whether the user granted permission or not. */ public static final String EXTRA_PERMISSION_GRANTED = "permission"; private final Context mContext; private final IUsbManager mService; /** * {@hide} */ public UsbManager(IUsbManager service) { public UsbManager(Context context, IUsbManager service) { mContext = context; mService = service; } Loading Loading @@ -189,6 +201,50 @@ public class UsbManager { } } /** * Returns true if the caller has permission to access the accessory. * Permission might have been granted temporarily via * {@link #requestPermission(UsbAccessory, PendingIntent)} or * by the user choosing the caller as the default application for the accessory. * * @param accessory to check permissions for * @return true if caller has permission */ public boolean hasPermission(UsbAccessory accessory) { try { return mService.hasAccessoryPermission(accessory); } catch (RemoteException e) { Log.e(TAG, "RemoteException in hasPermission", e); return false; } } /** * Requests temporary permission for the given package to access the accessory. * This may result in a system dialog being displayed to the user * if permission had not already been granted. * Success or failure is returned via the {@link android.app.PendingIntent} pi. * If successful, this grants the caller permission to access the accessory only * until the device is disconnected. * * The following extras will be added to pi: * <ul> * <li> {@link #EXTRA_ACCESSORY} containing the accessory passed into this call * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether * permission was granted by the user * </ul> * * @param accessory to request permissions for * @param pi PendingIntent for returning result */ public void requestPermission(UsbAccessory accessory, PendingIntent pi) { try { mService.requestAccessoryPermission(accessory, mContext.getPackageName(), pi); } catch (RemoteException e) { Log.e(TAG, "RemoteException in requestPermission", e); } } private static File getFunctionEnableFile(String function) { return new File("/sys/class/usb_composite/" + function + "/enable"); } Loading libs/usb/src/com/android/future/usb/UsbAccessory.java +34 −10 Original line number Diff line number Diff line Loading @@ -23,14 +23,16 @@ public final class UsbAccessory { private final String mManufacturer; private final String mModel; private final String mType; private final String mDescription; private final String mVersion; private final String mUri; /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) { mManufacturer = accessory.getManufacturer(); mModel = accessory.getModel(); mType = accessory.getType(); mDescription = accessory.getDescription(); mVersion = accessory.getVersion(); mUri = accessory.getUri(); } /** Loading @@ -52,12 +54,12 @@ public final class UsbAccessory { } /** * Returns the type of the accessory. * Returns a user visible description of the accessory. * * @return the accessory type * @return the accessory description */ public String getType() { return mType; public String getDescription() { return mDescription; } /** Loading @@ -69,6 +71,17 @@ public final class UsbAccessory { return mVersion; } /** * Returns the URI for the accessory. * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI */ public String getUri() { return mUri; } private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); Loading @@ -80,17 +93,28 @@ public final class UsbAccessory { UsbAccessory accessory = (UsbAccessory)obj; return (compare(mManufacturer, accessory.getManufacturer()) && compare(mModel, accessory.getModel()) && compare(mType, accessory.getType()) && compare(mVersion, accessory.getVersion())); compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && compare(mUri, accessory.getUri())); } return false; } @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode())); } @Override public String toString() { return "UsbAccessory[mManufacturer=" + mManufacturer + ", mModel=" + mModel + ", mType=" + mType + ", mVersion=" + mVersion + "]"; ", mDescription=" + mDescription + ", mVersion=" + mVersion + ", mUri=" + mUri + "]"; } } Loading
core/java/android/app/ContextImpl.java +1 −1 Original line number Diff line number Diff line Loading @@ -1158,7 +1158,7 @@ class ContextImpl extends Context { if (mUsbManager == null) { IBinder b = ServiceManager.getService(USB_SERVICE); IUsbManager service = IUsbManager.Stub.asInterface(b); mUsbManager = new UsbManager(service); mUsbManager = new UsbManager(this, service); } } return mUsbManager; Loading
core/java/android/hardware/usb/IUsbManager.aidl +13 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.hardware.usb; import android.app.PendingIntent; import android.hardware.usb.UsbAccessory; import android.os.Bundle; import android.os.ParcelFileDescriptor; Loading @@ -36,12 +37,22 @@ interface IUsbManager */ void setAccessoryPackage(in UsbAccessory accessory, String packageName); /* Returns true if the caller has permission to access the accessory. */ boolean hasAccessoryPermission(in UsbAccessory accessory); /* Requests permission for the given package to access the accessory. * Will display a system dialog to query the user if permission * had not already been given. Result is returned via pi. */ void requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi); /* Grants permission for the given UID to access the accessory */ void grantAccessoryPermission(in UsbAccessory accessory, int uid); /* Returns true if the USB manager has default preferences or permissions for the package */ boolean hasDefaults(String packageName, int uid); boolean hasDefaults(String packageName); /* Clears default preferences and permissions for the package */ oneway void clearDefaults(String packageName, int uid); void clearDefaults(String packageName); }
core/java/android/hardware/usb/UsbAccessory.java +43 −15 Original line number Diff line number Diff line Loading @@ -31,18 +31,21 @@ public class UsbAccessory implements Parcelable { private final String mManufacturer; private final String mModel; private final String mType; private final String mDescription; private final String mVersion; private final String mUri; /** * UsbAccessory should only be instantiated by UsbService implementation * @hide */ public UsbAccessory(String manufacturer, String model, String type, String version) { public UsbAccessory(String manufacturer, String model, String description, String version, String uri) { mManufacturer = manufacturer; mModel = model; mType = type; mDescription = description; mVersion = version; mUri = uri; } /** Loading @@ -52,8 +55,9 @@ public class UsbAccessory implements Parcelable { public UsbAccessory(String[] strings) { mManufacturer = strings[0]; mModel = strings[1]; mType = strings[2]; mDescription = strings[2]; mVersion = strings[3]; mUri = strings[4]; } /** Loading @@ -75,12 +79,12 @@ public class UsbAccessory implements Parcelable { } /** * Returns the type of the accessory. * Returns a user visible description of the accessory. * * @return the accessory type * @return the accessory description */ public String getType() { return mType; public String getDescription() { return mDescription; } /** Loading @@ -92,6 +96,17 @@ public class UsbAccessory implements Parcelable { return mVersion; } /** * Returns the URI for the accessory. * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI */ public String getUri() { return mUri; } private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); Loading @@ -103,18 +118,29 @@ public class UsbAccessory implements Parcelable { UsbAccessory accessory = (UsbAccessory)obj; return (compare(mManufacturer, accessory.getManufacturer()) && compare(mModel, accessory.getModel()) && compare(mType, accessory.getType()) && compare(mVersion, accessory.getVersion())); compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && compare(mUri, accessory.getUri())); } return false; } @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode())); } @Override public String toString() { return "UsbAccessory[mManufacturer=" + mManufacturer + ", mModel=" + mModel + ", mType=" + mType + ", mVersion=" + mVersion + "]"; ", mDescription=" + mDescription + ", mVersion=" + mVersion + ", mUri=" + mUri + "]"; } public static final Parcelable.Creator<UsbAccessory> CREATOR = Loading @@ -122,9 +148,10 @@ public class UsbAccessory implements Parcelable { public UsbAccessory createFromParcel(Parcel in) { String manufacturer = in.readString(); String model = in.readString(); String type = in.readString(); String description = in.readString(); String version = in.readString(); return new UsbAccessory(manufacturer, model, type, version); String uri = in.readString(); return new UsbAccessory(manufacturer, model, description, version, uri); } public UsbAccessory[] newArray(int size) { Loading @@ -139,7 +166,8 @@ public class UsbAccessory implements Parcelable { public void writeToParcel(Parcel parcel, int flags) { parcel.writeString(mManufacturer); parcel.writeString(mModel); parcel.writeString(mType); parcel.writeString(mDescription); parcel.writeString(mVersion); parcel.writeString(mUri); } }
core/java/android/hardware/usb/UsbManager.java +61 −5 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ package android.hardware.usb; import android.app.PendingIntent; import android.content.Context; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.RemoteException; Loading Loading @@ -75,7 +77,7 @@ public class UsbManager { * * This intent is sent when a USB accessory is detached. * <ul> * <li> {@link #EXTRA_ACCESSORY} containing the {@link android.hardware.usb.UsbAccessory} * <li> {@link #EXTRA_ACCESSORY} containing the {@link UsbAccessory} * for the attached accessory that was detached * </ul> */ Loading Loading @@ -145,12 +147,22 @@ public class UsbManager { */ public static final String EXTRA_ACCESSORY = "accessory"; private IUsbManager mService; /** * Name of extra added to the {@link android.app.PendingIntent} * passed into {@link #requestPermission(UsbDevice, PendingIntent)} * or {@link #requestPermission(UsbAccessory, PendingIntent)} * containing a boolean value indicating whether the user granted permission or not. */ public static final String EXTRA_PERMISSION_GRANTED = "permission"; private final Context mContext; private final IUsbManager mService; /** * {@hide} */ public UsbManager(IUsbManager service) { public UsbManager(Context context, IUsbManager service) { mContext = context; mService = service; } Loading Loading @@ -189,6 +201,50 @@ public class UsbManager { } } /** * Returns true if the caller has permission to access the accessory. * Permission might have been granted temporarily via * {@link #requestPermission(UsbAccessory, PendingIntent)} or * by the user choosing the caller as the default application for the accessory. * * @param accessory to check permissions for * @return true if caller has permission */ public boolean hasPermission(UsbAccessory accessory) { try { return mService.hasAccessoryPermission(accessory); } catch (RemoteException e) { Log.e(TAG, "RemoteException in hasPermission", e); return false; } } /** * Requests temporary permission for the given package to access the accessory. * This may result in a system dialog being displayed to the user * if permission had not already been granted. * Success or failure is returned via the {@link android.app.PendingIntent} pi. * If successful, this grants the caller permission to access the accessory only * until the device is disconnected. * * The following extras will be added to pi: * <ul> * <li> {@link #EXTRA_ACCESSORY} containing the accessory passed into this call * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether * permission was granted by the user * </ul> * * @param accessory to request permissions for * @param pi PendingIntent for returning result */ public void requestPermission(UsbAccessory accessory, PendingIntent pi) { try { mService.requestAccessoryPermission(accessory, mContext.getPackageName(), pi); } catch (RemoteException e) { Log.e(TAG, "RemoteException in requestPermission", e); } } private static File getFunctionEnableFile(String function) { return new File("/sys/class/usb_composite/" + function + "/enable"); } Loading
libs/usb/src/com/android/future/usb/UsbAccessory.java +34 −10 Original line number Diff line number Diff line Loading @@ -23,14 +23,16 @@ public final class UsbAccessory { private final String mManufacturer; private final String mModel; private final String mType; private final String mDescription; private final String mVersion; private final String mUri; /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) { mManufacturer = accessory.getManufacturer(); mModel = accessory.getModel(); mType = accessory.getType(); mDescription = accessory.getDescription(); mVersion = accessory.getVersion(); mUri = accessory.getUri(); } /** Loading @@ -52,12 +54,12 @@ public final class UsbAccessory { } /** * Returns the type of the accessory. * Returns a user visible description of the accessory. * * @return the accessory type * @return the accessory description */ public String getType() { return mType; public String getDescription() { return mDescription; } /** Loading @@ -69,6 +71,17 @@ public final class UsbAccessory { return mVersion; } /** * Returns the URI for the accessory. * This is an optional URI that might show information about the accessory * or provide the option to download an application for the accessory * * @return the accessory URI */ public String getUri() { return mUri; } private static boolean compare(String s1, String s2) { if (s1 == null) return (s2 == null); return s1.equals(s2); Loading @@ -80,17 +93,28 @@ public final class UsbAccessory { UsbAccessory accessory = (UsbAccessory)obj; return (compare(mManufacturer, accessory.getManufacturer()) && compare(mModel, accessory.getModel()) && compare(mType, accessory.getType()) && compare(mVersion, accessory.getVersion())); compare(mDescription, accessory.getDescription()) && compare(mVersion, accessory.getVersion()) && compare(mUri, accessory.getUri())); } return false; } @Override public int hashCode() { return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ (mModel == null ? 0 : mModel.hashCode()) ^ (mDescription == null ? 0 : mDescription.hashCode()) ^ (mVersion == null ? 0 : mVersion.hashCode()) ^ (mUri == null ? 0 : mUri.hashCode())); } @Override public String toString() { return "UsbAccessory[mManufacturer=" + mManufacturer + ", mModel=" + mModel + ", mType=" + mType + ", mVersion=" + mVersion + "]"; ", mDescription=" + mDescription + ", mVersion=" + mVersion + ", mUri=" + mUri + "]"; } }