Skip to content

Commit 40bbf92

Browse files
committed
DO NOT MERGE: Backport USB accessory support to gingerbread
Signed-off-by: Mike Lockwood <lockwood@android.com>
1 parent db52ab6 commit 40bbf92

File tree

25 files changed

+1956
-376
lines changed

25 files changed

+1956
-376
lines changed

Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ LOCAL_SRC_FILES += \
113113
core/java/android/content/pm/IPackageMoveObserver.aidl \
114114
core/java/android/content/pm/IPackageStatsObserver.aidl \
115115
core/java/android/database/IContentObserver.aidl \
116+
core/java/android/hardware/usb/IUsbManager.aidl \
116117
core/java/android/net/IConnectivityManager.aidl \
117118
core/java/android/net/INetworkManagementEventObserver.aidl \
118119
core/java/android/net/IThrottleManager.aidl \

core/java/android/app/ContextImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
import android.graphics.Bitmap;
6363
import android.graphics.drawable.Drawable;
6464
import android.hardware.SensorManager;
65+
import android.hardware.usb.IUsbManager;
66+
import android.hardware.usb.UsbManager;
6567
import android.location.ILocationManager;
6668
import android.location.LocationManager;
6769
import android.media.AudioManager;
@@ -191,6 +193,7 @@ class ContextImpl extends Context {
191193
private SearchManager mSearchManager = null;
192194
private SensorManager mSensorManager = null;
193195
private StorageManager mStorageManager = null;
196+
private UsbManager mUsbManager = null;
194197
private Vibrator mVibrator = null;
195198
private LayoutInflater mLayoutInflater = null;
196199
private StatusBarManager mStatusBarManager = null;
@@ -954,6 +957,8 @@ public Object getSystemService(String name) {
954957
return getSensorManager();
955958
} else if (STORAGE_SERVICE.equals(name)) {
956959
return getStorageManager();
960+
} else if (USB_SERVICE.equals(name)) {
961+
return getUsbManager();
957962
} else if (VIBRATOR_SERVICE.equals(name)) {
958963
return getVibrator();
959964
} else if (STATUS_BAR_SERVICE.equals(name)) {
@@ -1148,6 +1153,17 @@ private StorageManager getStorageManager() {
11481153
return mStorageManager;
11491154
}
11501155

1156+
private UsbManager getUsbManager() {
1157+
synchronized (mSync) {
1158+
if (mUsbManager == null) {
1159+
IBinder b = ServiceManager.getService(USB_SERVICE);
1160+
IUsbManager service = IUsbManager.Stub.asInterface(b);
1161+
mUsbManager = new UsbManager(service);
1162+
}
1163+
}
1164+
return mUsbManager;
1165+
}
1166+
11511167
private Vibrator getVibrator() {
11521168
synchronized (mSync) {
11531169
if (mVibrator == null) {

core/java/android/content/Context.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,17 @@ public abstract boolean startInstrumentation(ComponentName className,
15661566
/** @hide */
15671567
public static final String SIP_SERVICE = "sip";
15681568

1569+
/**
1570+
* Use with {@link #getSystemService} to retrieve a {@link
1571+
* android.hardware.usb.UsbManager} for access to USB devices (as a USB host)
1572+
* and for controlling this device's behavior as a USB device.
1573+
*
1574+
* @see #getSystemService
1575+
* @see android.harware.usb.UsbManager
1576+
* @hide
1577+
*/
1578+
public static final String USB_SERVICE = "usb";
1579+
15691580
/**
15701581
* Determine whether the given permission is allowed for a particular
15711582
* process and user ID running in the system.

core/java/android/content/pm/PackageManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,13 @@ public NameNotFoundException(String name) {
783783
@SdkConstant(SdkConstantType.FEATURE)
784784
public static final String FEATURE_TELEPHONY_GSM = "android.hardware.telephony.gsm";
785785

786+
/**
787+
* Feature for {@link #getSystemAvailableFeatures} and
788+
* {@link #hasSystemFeature}: The device supports connecting to USB accessories.
789+
* @hide
790+
*/
791+
public static final String FEATURE_USB_ACCESSORY = "android.hardware.usb.accessory";
792+
786793
/**
787794
* Feature for {@link #getSystemAvailableFeatures} and
788795
* {@link #hasSystemFeature}: The SIP API is enabled on the device.

core/java/android/hardware/UsbManager.java

Lines changed: 0 additions & 115 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.hardware.usb;
18+
19+
import android.hardware.usb.UsbAccessory;
20+
import android.os.Bundle;
21+
import android.os.ParcelFileDescriptor;
22+
23+
/** @hide */
24+
interface IUsbManager
25+
{
26+
/* Returns the currently attached USB accessory */
27+
UsbAccessory getCurrentAccessory();
28+
29+
/* Returns a file descriptor for communicating with the USB accessory.
30+
* This file descriptor can be used with standard Java file operations.
31+
*/
32+
ParcelFileDescriptor openAccessory(in UsbAccessory accessory);
33+
34+
/* Sets the default package for a USB accessory
35+
* (or clears it if the package name is null)
36+
*/
37+
void setAccessoryPackage(in UsbAccessory accessory, String packageName);
38+
39+
/* Grants permission for the given UID to access the accessory */
40+
void grantAccessoryPermission(in UsbAccessory accessory, int uid);
41+
42+
/* Returns true if the USB manager has default preferences or permissions for the package */
43+
boolean hasDefaults(String packageName, int uid);
44+
45+
/* Clears default preferences and permissions for the package */
46+
oneway void clearDefaults(String packageName, int uid);
47+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2011, The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package android.hardware.usb;
18+
19+
parcelable UsbAccessory;

0 commit comments

Comments
 (0)