Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e8e4ea0 authored by Mike Lockwood's avatar Mike Lockwood Committed by Android (Google) Code Review
Browse files

Merge changes Ib517e5e4,I93be7695,I49bf22a4 into honeycomb-mr1

* changes:
  Close USB dialogs if their corresponding accessory or device has disconnected
  USB: Add API and dialog for apps to request permissions for USB devices and accessories
  UsbService: Automatically use system apps by default if it is the only choice
parents 36b077d5 d5913575
Loading
Loading
Loading
Loading
+68 −1
Original line number Diff line number Diff line
@@ -95457,6 +95457,32 @@
 visibility="public"
>
</method>
<method name="hasPermission"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="device" type="android.hardware.usb.UsbDevice">
</parameter>
</method>
<method name="hasPermission"
 return="boolean"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="accessory" type="android.hardware.usb.UsbAccessory">
</parameter>
</method>
<method name="isFunctionEnabled"
 return="boolean"
 abstract="false"
@@ -95509,6 +95535,36 @@
<parameter name="device" type="android.hardware.usb.UsbDevice">
</parameter>
</method>
<method name="requestPermission"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="device" type="android.hardware.usb.UsbDevice">
</parameter>
<parameter name="pi" type="android.app.PendingIntent">
</parameter>
</method>
<method name="requestPermission"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="accessory" type="android.hardware.usb.UsbAccessory">
</parameter>
<parameter name="pi" type="android.app.PendingIntent">
</parameter>
</method>
<field name="ACTION_USB_ACCESSORY_ATTACHED"
 type="java.lang.String"
 transient="false"
@@ -95586,6 +95642,17 @@
 visibility="public"
>
</field>
<field name="EXTRA_PERMISSION_GRANTED"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;permission&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="USB_CONFIGURATION"
 type="java.lang.String"
 transient="false"
@@ -267304,7 +267371,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="arg0" type="T">
<parameter name="t" type="T">
</parameter>
</method>
</interface>
+3 −3
Original line number Diff line number Diff line
@@ -401,10 +401,10 @@ class ContextImpl extends Context {
                    return new UiModeManager();
                }});

        registerService(USB_SERVICE, new StaticServiceFetcher() {
                public Object createStaticService() {
        registerService(USB_SERVICE, new ServiceFetcher() {
                public Object createService(ContextImpl ctx) {
                    IBinder b = ServiceManager.getService(USB_SERVICE);
                    return new UsbManager(IUsbManager.Stub.asInterface(b));
                    return new UsbManager(ctx, IUsbManager.Stub.asInterface(b));
                }});

        registerService(VIBRATOR_SERVICE, new ServiceFetcher() {
+20 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.hardware.usb;

import android.app.PendingIntent;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbDevice;
import android.os.Bundle;
@@ -50,6 +51,25 @@ interface IUsbManager
     */
    void setAccessoryPackage(in UsbAccessory accessory, String packageName);

    /* Returns true if the caller has permission to access the device. */
    boolean hasDevicePermission(in UsbDevice device);

    /* 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 device.
     * Will display a system dialog to query the user if permission
     * had not already been given.
     */
    void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi);

    /* 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 device */
    void grantDevicePermission(in UsbDevice device, int uid);

+94 −4
Original line number Diff line number Diff line
@@ -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;
@@ -176,12 +178,24 @@ 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
     * {#requestPermission(android.content.Context, android.hardware.usb.UsbDevice, android.app.PendingIntent)}
     * or
     * {#requestPermission(android.content.Context, android.hardware.usb.UsbAccessory, android.app.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;
    }

@@ -265,6 +279,82 @@ public class UsbManager {
        }
    }

    /**
     * Returns true if the caller has permission to access the device.
     *
     * @param device to check permissions for
     * @return true if caller has permission
     */
    public boolean hasPermission(UsbDevice device) {
        try {
            return mService.hasDevicePermission(device);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in hasPermission", e);
            return false;
        }
    }

    /**
     * Returns true if the caller has permission to access 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 permission for the given package to access the device.
     * 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.
     * The following extras will be added to pi:
     * <ul>
     * <li> {@link #EXTRA_DEVICE} containing the device passed into this call
     * <li> {@link #EXTRA_PERMISSION_GRANTED} containing boolean indicating whether
     * permission was granted by the user
     * </ul>
     *
     * @param device to request permissions for
     * @param pi PendingIntent for returning result
     */
    public void requestPermission(UsbDevice device, PendingIntent pi) {
        try {
            mService.requestDevicePermission(device, mContext.getPackageName(), pi);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in requestPermission", e);
        }
    }

    /**
     * Requests 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.
     * 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");
    }
+0 −6
Original line number Diff line number Diff line
@@ -1379,12 +1379,6 @@
                android:excludeFromRecents="true">
        </activity>

        <activity android:name="com.android.server.usb.UsbResolverActivity"
            android:theme="@style/Theme.Holo.Dialog.Alert"
            android:finishOnCloseSystemDialogs="true"
            android:excludeFromRecents="true">
        </activity>

        <service android:name="com.android.server.LoadAverageService"
                android:exported="true" />

Loading