M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.usb;
import android.app.PendingIntent;
import android.hardware.usb.UsbAccessory;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
/** @hide */
interface IUsbManager
{
/* Returns the currently attached USB accessory */
UsbAccessory getCurrentAccessory();
/* Returns a file descriptor for communicating with the USB accessory.
* This file descriptor can be used with standard Java file operations.
*/
ParcelFileDescriptor openAccessory(in UsbAccessory accessory);
/* Sets the default package for a USB accessory
* (or clears it if the package name is null)
*/
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);
/* Clears default preferences and permissions for the package */
void clearDefaults(String packageName);
}
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2011, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.usb;
parcelable UsbAccessory;
@@ -0,0 +1,192 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.usb;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
/**
* A class representing a USB accessory.
* @hide
*/
public class UsbAccessory implements Parcelable {
private static final String TAG = "UsbAccessory";
private final String mManufacturer;
private final String mModel;
private final String mDescription;
private final String mVersion;
private final String mUri;
private final String mSerial;
/**
* UsbAccessory should only be instantiated by UsbService implementation
* @hide
*/
public UsbAccessory(String manufacturer, String model, String description,
String version, String uri, String serial) {
mManufacturer = manufacturer;
mModel = model;
mDescription = description;
mVersion = version;
mUri = uri;
mSerial = serial;
}
/**
* UsbAccessory should only be instantiated by UsbService implementation
* @hide
*/
public UsbAccessory(String[] strings) {
mManufacturer = strings[0];
mModel = strings[1];
mDescription = strings[2];
mVersion = strings[3];
mUri = strings[4];
mSerial = strings[5];
}
/**
* Returns the manufacturer of the accessory.
*
* @return the accessory manufacturer
*/
public String getManufacturer() {
return mManufacturer;
}
/**
* Returns the model name of the accessory.
*
* @return the accessory model
*/
public String getModel() {
return mModel;
}
/**
* Returns a user visible description of the accessory.
*
* @return the accessory description
*/
public String getDescription() {
return mDescription;
}
/**
* Returns the version of the accessory.
*
* @return the accessory version
*/
public String getVersion() {
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;
}
/**
* Returns the unique serial number for the accessory.
* This is an optional serial number that can be used to differentiate
* between individual accessories of the same model and manufacturer
*
* @return the unique serial number
*/
public String getSerial() {
return mSerial;
}
private static boolean compare(String s1, String s2) {
if (s1 == null) return (s2 == null);
return s1.equals(s2);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof UsbAccessory) {
UsbAccessory accessory = (UsbAccessory)obj;
return (compare(mManufacturer, accessory.getManufacturer()) &&
compare(mModel, accessory.getModel()) &&
compare(mDescription, accessory.getDescription()) &&
compare(mVersion, accessory.getVersion()) &&
compare(mUri, accessory.getUri()) &&
compare(mSerial, accessory.getSerial()));
}
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()) ^
(mSerial == null ? 0 : mSerial.hashCode()));
}
@Override
public String toString() {
return "UsbAccessory[mManufacturer=" + mManufacturer +
", mModel=" + mModel +
", mDescription=" + mDescription +
", mVersion=" + mVersion +
", mUri=" + mUri +
", mSerial=" + mSerial + "]";
}
public static final Parcelable.Creator<UsbAccessory> CREATOR =
new Parcelable.Creator<UsbAccessory>() {
public UsbAccessory createFromParcel(Parcel in) {
String manufacturer = in.readString();
String model = in.readString();
String description = in.readString();
String version = in.readString();
String uri = in.readString();
String serial = in.readString();
return new UsbAccessory(manufacturer, model, description, version, uri, serial);
}
public UsbAccessory[] newArray(int size) {
return new UsbAccessory[size];
}
};
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeString(mManufacturer);
parcel.writeString(mModel);
parcel.writeString(mDescription);
parcel.writeString(mVersion);
parcel.writeString(mUri);
parcel.writeString(mSerial);
}
}
@@ -0,0 +1,295 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.usb;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
/**
* This class allows you to access the state of USB.
*
* <p>You can obtain an instance of this class by calling
* {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}.
*
* {@samplecode
* UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
* }
* @hide
*/
public class UsbManager {
private static final String TAG = "UsbManager";
/**
* Broadcast Action: A sticky broadcast for USB state change events when in device mode.
*
* This is a sticky broadcast for clients that includes USB connected/disconnected state,
* <ul>
* <li> {@link #USB_CONNECTED} boolean indicating whether USB is connected or disconnected.
* <li> {@link #USB_CONFIGURATION} a Bundle containing name/value pairs where the name
* is the name of a USB function and the value is either {@link #USB_FUNCTION_ENABLED}
* or {@link #USB_FUNCTION_DISABLED}. The possible function names include
* {@link #USB_FUNCTION_MASS_STORAGE}, {@link #USB_FUNCTION_ADB}, {@link #USB_FUNCTION_RNDIS},
* {@link #USB_FUNCTION_MTP} and {@link #USB_FUNCTION_ACCESSORY}.
* </ul>
*/
public static final String ACTION_USB_STATE =
"android.hardware.usb.action.USB_STATE";
/**
* Broadcast Action: A broadcast for USB accessory attached event.
*
* This intent is sent when a USB accessory is attached.
* <ul>
* <li> {@link #EXTRA_ACCESSORY} containing the {@link android.hardware.usb.UsbAccessory}
* for the attached accessory
* </ul>
*/
public static final String ACTION_USB_ACCESSORY_ATTACHED =
"android.hardware.usb.action.USB_ACCESSORY_ATTACHED";
/**
* Broadcast Action: A broadcast for USB accessory detached event.
*
* This intent is sent when a USB accessory is detached.
* <ul>
* <li> {@link #EXTRA_ACCESSORY} containing the {@link UsbAccessory}
* for the attached accessory that was detached
* </ul>
*/
public static final String ACTION_USB_ACCESSORY_DETACHED =
"android.hardware.usb.action.USB_ACCESSORY_DETACHED";
/**
* Boolean extra indicating whether USB is connected or disconnected.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast.
*/
public static final String USB_CONNECTED = "connected";
/**
* Integer extra containing currently set USB configuration.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast.
*/
public static final String USB_CONFIGURATION = "configuration";
/**
* Name of the USB mass storage USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_MASS_STORAGE = "mass_storage";
/**
* Name of the adb USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_ADB = "adb";
/**
* Name of the RNDIS ethernet USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_RNDIS = "rndis";
/**
* Name of the MTP USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_MTP = "mtp";
/**
* Name of the Accessory USB function.
* Used in extras for the {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_ACCESSORY = "accessory";
/**
* Value indicating that a USB function is enabled.
* Used in {@link #USB_CONFIGURATION} extras bundle for the
* {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_ENABLED = "enabled";
/**
* Value indicating that a USB function is disabled.
* Used in {@link #USB_CONFIGURATION} extras bundle for the
* {@link #ACTION_USB_STATE} broadcast
*/
public static final String USB_FUNCTION_DISABLED = "disabled";
/**
* Name of extra for {@link #ACTION_USB_ACCESSORY_ATTACHED} and
* {@link #ACTION_USB_ACCESSORY_DETACHED} broadcasts
* containing the UsbAccessory object for the accessory.
*/
public static final String EXTRA_ACCESSORY = "accessory";
/**
* 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(Context context, IUsbManager service) {
mContext = context;
mService = service;
}
/**
* Returns a list of currently attached USB accessories.
* (in the current implementation there can be at most one)
*
* @return list of USB accessories, or null if none are attached.
*/
public UsbAccessory[] getAccessoryList() {
try {
UsbAccessory accessory = mService.getCurrentAccessory();
if (accessory == null) {
return null;
} else {
return new UsbAccessory[] { accessory };
}
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in getAccessoryList", e);
return null;
}
}
/**
* Opens a file descriptor for reading and writing data to the USB accessory.
*
* @param accessory the USB accessory to open
* @return file descriptor, or null if the accessor could not be opened.
*/
public ParcelFileDescriptor openAccessory(UsbAccessory accessory) {
try {
return mService.openAccessory(accessory);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in openAccessory", e);
return null;
}
}
/**
* 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");
}
/**
* Returns true if the specified USB function is supported by the kernel.
* Note that a USB function maybe supported but disabled.
*
* @param function name of the USB function
* @return true if the USB function is supported.
*/
public static boolean isFunctionSupported(String function) {
return getFunctionEnableFile(function).exists();
}
/**
* Returns true if the specified USB function is currently enabled.
*
* @param function name of the USB function
* @return true if the USB function is enabled.
*/
public static boolean isFunctionEnabled(String function) {
try {
FileInputStream stream = new FileInputStream(getFunctionEnableFile(function));
boolean enabled = (stream.read() == '1');
stream.close();
return enabled;
} catch (IOException e) {
return false;
}
}
/**
* Enables or disables a USB function.
*
* @hide
*/
public static boolean setFunctionEnabled(String function, boolean enable) {
try {
FileOutputStream stream = new FileOutputStream(getFunctionEnableFile(function));
stream.write(enable ? '1' : '0');
stream.close();
return true;
} catch (IOException e) {
return false;
}
}
}