summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/AudioDeviceInfo.java3
-rw-r--r--media/java/android/media/AudioDevicePort.java4
-rw-r--r--media/java/android/media/AudioManager.java82
-rw-r--r--media/java/android/media/AudioMixPort.java5
-rw-r--r--media/java/android/media/AudioPort.java13
-rw-r--r--media/java/android/media/AudioRecord.java15
-rw-r--r--media/java/android/media/AudioTrack.java13
-rw-r--r--media/java/android/media/midi/IMidiDeviceServer.aidl1
-rw-r--r--media/java/android/media/midi/MidiDeviceServer.java26
-rw-r--r--media/java/android/media/midi/MidiDeviceService.java4
-rw-r--r--media/java/android/media/midi/MidiManager.java1
-rw-r--r--media/java/android/media/tv/TvInputService.java17
-rw-r--r--media/java/android/mtp/MtpDevice.java3
13 files changed, 121 insertions, 66 deletions
diff --git a/media/java/android/media/AudioDeviceInfo.java b/media/java/android/media/AudioDeviceInfo.java
index 431d37e..173d349 100644
--- a/media/java/android/media/AudioDeviceInfo.java
+++ b/media/java/android/media/AudioDeviceInfo.java
@@ -173,8 +173,7 @@ public final class AudioDeviceInfo {
* @see AudioFormat
*/
public @NonNull int[] getChannelIndexMasks() {
- // TODO: implement
- return new int[0];
+ return mPort.channelIndexMasks();
}
/**
diff --git a/media/java/android/media/AudioDevicePort.java b/media/java/android/media/AudioDevicePort.java
index c078260..aea39a3 100644
--- a/media/java/android/media/AudioDevicePort.java
+++ b/media/java/android/media/AudioDevicePort.java
@@ -37,12 +37,12 @@ public class AudioDevicePort extends AudioPort {
private final String mAddress;
AudioDevicePort(AudioHandle handle, String deviceName,
- int[] samplingRates, int[] channelMasks,
+ int[] samplingRates, int[] channelMasks, int[] channelIndexMasks,
int[] formats, AudioGain[] gains, int type, String address) {
super(handle,
(AudioManager.isInputDevice(type) == true) ?
AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK,
- deviceName, samplingRates, channelMasks, formats, gains);
+ deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains);
mType = type;
mAddress = address;
}
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 33db9cf..a806440 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -3701,8 +3701,9 @@ public class AudioManager {
* The message sent to apps when the contents of the device list changes if they provide
* a {#link Handler} object to addOnAudioDeviceConnectionListener().
*/
- private final static int MSG_DEVICES_DEVICES_ADDED = 0;
- private final static int MSG_DEVICES_DEVICES_REMOVED = 1;
+ private final static int MSG_DEVICES_CALLBACK_REGISTERED = 0;
+ private final static int MSG_DEVICES_DEVICES_ADDED = 1;
+ private final static int MSG_DEVICES_DEVICES_REMOVED = 2;
/**
* The list of {@link AudioDeviceCallback} objects to receive add/remove notifications.
@@ -3848,8 +3849,10 @@ public class AudioManager {
android.os.Handler handler) {
if (callback != null && !mDeviceCallbacks.containsKey(callback)) {
synchronized (mDeviceCallbacks) {
- mDeviceCallbacks.put(
- callback, new NativeEventHandlerDelegate(callback, handler));
+ NativeEventHandlerDelegate delegate =
+ new NativeEventHandlerDelegate(callback, handler);
+ mDeviceCallbacks.put(callback, delegate);
+ broadcastDeviceListChange(delegate.getHandler());
}
}
}
@@ -3868,49 +3871,60 @@ public class AudioManager {
}
}
+ // Since we need to calculate the changes since THE LAST NOTIFICATION, and not since the
+ // (unpredictable) last time updateAudioPortCache() was called by someone, keep a list
+ // of the ports that exist at the time of the last notification.
+ private ArrayList<AudioDevicePort> mPreviousPorts = new ArrayList<AudioDevicePort>();
+
/**
* Internal method to compute and generate add/remove messages and then send to any
* registered callbacks.
*/
- private void broadcastDeviceListChange() {
+ private void broadcastDeviceListChange(Handler handler) {
int status;
- ArrayList<AudioDevicePort> previous_ports = new ArrayList<AudioDevicePort>();
- status = AudioManager.listPreviousAudioDevicePorts(previous_ports);
- if (status != AudioManager.SUCCESS) {
- return;
- }
-
+ // Get the new current set of ports
ArrayList<AudioDevicePort> current_ports = new ArrayList<AudioDevicePort>();
status = AudioManager.listAudioDevicePorts(current_ports);
if (status != AudioManager.SUCCESS) {
return;
}
- AudioDeviceInfo[] added_devices =
- calcListDeltas(previous_ports, current_ports, GET_DEVICES_ALL);
- AudioDeviceInfo[] removed_devices =
- calcListDeltas(current_ports, previous_ports, GET_DEVICES_ALL);
-
- if (added_devices.length != 0 || removed_devices.length != 0) {
- Collection<NativeEventHandlerDelegate> values;
- synchronized (mDeviceCallbacks) {
- values = mDeviceCallbacks.values();
- }
- for (NativeEventHandlerDelegate delegate : values) {
- Handler handler = delegate.getHandler();
- if (handler != null) {
- if (added_devices.length != 0) {
- handler.sendMessage(
- Message.obtain(handler,MSG_DEVICES_DEVICES_ADDED, added_devices));
- }
- if (removed_devices.length != 0) {
- handler.sendMessage(
- Message.obtain(handler,MSG_DEVICES_DEVICES_REMOVED, removed_devices));
+ if (handler != null) {
+ // This is the callback for the registration, so send the current list
+ AudioDeviceInfo[] deviceList =
+ infoListFromPortList(current_ports, GET_DEVICES_ALL);
+ handler.sendMessage(
+ Message.obtain(handler, MSG_DEVICES_CALLBACK_REGISTERED, deviceList));
+ } else {
+ AudioDeviceInfo[] added_devices =
+ calcListDeltas(mPreviousPorts, current_ports, GET_DEVICES_ALL);
+ AudioDeviceInfo[] removed_devices =
+ calcListDeltas(current_ports, mPreviousPorts, GET_DEVICES_ALL);
+
+ if (added_devices.length != 0 || removed_devices.length != 0) {
+ Collection<NativeEventHandlerDelegate> values;
+ synchronized (mDeviceCallbacks) {
+ values = mDeviceCallbacks.values();
+ }
+ for (NativeEventHandlerDelegate delegate : values) {
+ handler = delegate.getHandler();
+ if (handler != null) {
+ if (added_devices.length != 0) {
+ handler.sendMessage(
+ Message.obtain(handler,MSG_DEVICES_DEVICES_ADDED, added_devices));
+ }
+ if (removed_devices.length != 0) {
+ handler.sendMessage(
+ Message.obtain(handler,MSG_DEVICES_DEVICES_REMOVED,
+ removed_devices));
+ }
}
}
}
}
+
+ mPreviousPorts = current_ports;
}
/**
@@ -3919,7 +3933,7 @@ public class AudioManager {
private class OnAmPortUpdateListener implements AudioManager.OnAudioPortUpdateListener {
static final String TAG = "OnAmPortUpdateListener";
public void onAudioPortListUpdate(AudioPort[] portList) {
- broadcastDeviceListChange();
+ broadcastDeviceListChange(null);
}
/**
@@ -3933,7 +3947,7 @@ public class AudioManager {
* Callback method called when the mediaserver dies
*/
public void onServiceDied() {
- broadcastDeviceListChange();
+ broadcastDeviceListChange(null);
}
}
@@ -3965,8 +3979,8 @@ public class AudioManager {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
+ case MSG_DEVICES_CALLBACK_REGISTERED:
case MSG_DEVICES_DEVICES_ADDED:
- // call the OnAudioDeviceConnectionListener
if (callback != null) {
callback.onAudioDevicesAdded((AudioDeviceInfo[])msg.obj);
}
diff --git a/media/java/android/media/AudioMixPort.java b/media/java/android/media/AudioMixPort.java
index ab55c8d..ba144bf 100644
--- a/media/java/android/media/AudioMixPort.java
+++ b/media/java/android/media/AudioMixPort.java
@@ -31,9 +31,10 @@ public class AudioMixPort extends AudioPort {
private final int mIoHandle;
AudioMixPort(AudioHandle handle, int ioHandle, int role, String deviceName,
- int[] samplingRates, int[] channelMasks,
+ int[] samplingRates, int[] channelMasks, int[] channelIndexMasks,
int[] formats, AudioGain[] gains) {
- super(handle, role, deviceName, samplingRates, channelMasks, formats, gains);
+ super(handle, role, deviceName, samplingRates, channelMasks, channelIndexMasks,
+ formats, gains);
mIoHandle = ioHandle;
}
diff --git a/media/java/android/media/AudioPort.java b/media/java/android/media/AudioPort.java
index 7328d7a..19bf51d 100644
--- a/media/java/android/media/AudioPort.java
+++ b/media/java/android/media/AudioPort.java
@@ -71,12 +71,13 @@ public class AudioPort {
private final String mName;
private final int[] mSamplingRates;
private final int[] mChannelMasks;
+ private final int[] mChannelIndexMasks;
private final int[] mFormats;
private final AudioGain[] mGains;
private AudioPortConfig mActiveConfig;
AudioPort(AudioHandle handle, int role, String name,
- int[] samplingRates, int[] channelMasks,
+ int[] samplingRates, int[] channelMasks, int[] channelIndexMasks,
int[] formats, AudioGain[] gains) {
mHandle = handle;
@@ -84,6 +85,7 @@ public class AudioPort {
mName = name;
mSamplingRates = samplingRates;
mChannelMasks = channelMasks;
+ mChannelIndexMasks = channelIndexMasks;
mFormats = formats;
mGains = gains;
}
@@ -133,6 +135,15 @@ public class AudioPort {
}
/**
+ * Get the list of supported channel index mask configurations
+ * (e.g 0x0003 means 2 channel, 0x000F means 4 channel....)
+ * Empty array if channel index mask is not relevant for this audio port
+ */
+ public int[] channelIndexMasks() {
+ return mChannelIndexMasks;
+ }
+
+ /**
* Get the list of supported audio format configurations
* (e.g AudioFormat.ENCODING_PCM_16BIT)
* Empty array if format is not relevant for this audio port
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index 3cbc405..974b62e 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -527,10 +527,11 @@ public class AudioRecord
}
/**
- * @return a new {@link AudioRecord} instance initialized with all the parameters set
- * on this <code>Builder</code>
+ * @return a new {@link AudioRecord} instance successfully initialized with all
+ * the parameters set on this <code>Builder</code>.
* @throws UnsupportedOperationException if the parameters set on the <code>Builder</code>
- * were incompatible, or if they are not supported by the device.
+ * were incompatible, or if they are not supported by the device,
+ * or if the device was not available.
*/
public AudioRecord build() throws UnsupportedOperationException {
if (mFormat == null) {
@@ -564,7 +565,13 @@ public class AudioRecord
mBufferSizeInBytes = mFormat.getChannelCount()
* mFormat.getBytesPerSample(mFormat.getEncoding());
}
- return new AudioRecord(mAttributes, mFormat, mBufferSizeInBytes, mSessionId);
+ final AudioRecord record = new AudioRecord(
+ mAttributes, mFormat, mBufferSizeInBytes, mSessionId);
+ if (record.getState() == STATE_UNINITIALIZED) {
+ // release is not necessary
+ throw new UnsupportedOperationException("Cannot create AudioRecord");
+ }
+ return record;
} catch (IllegalArgumentException e) {
throw new UnsupportedOperationException(e.getMessage());
}
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index f395cb3..62810c6 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -661,9 +661,10 @@ public class AudioTrack
/**
* Builds an {@link AudioTrack} instance initialized with all the parameters set
* on this <code>Builder</code>.
- * @return a new {@link AudioTrack} instance.
+ * @return a new successfully initialized {@link AudioTrack} instance.
* @throws UnsupportedOperationException if the parameters set on the <code>Builder</code>
- * were incompatible, or if they are not supported by the device.
+ * were incompatible, or if they are not supported by the device,
+ * or if the device was not available.
*/
public @NonNull AudioTrack build() throws UnsupportedOperationException {
if (mAttributes == null) {
@@ -686,7 +687,13 @@ public class AudioTrack
mBufferSizeInBytes = mFormat.getChannelCount()
* mFormat.getBytesPerSample(mFormat.getEncoding());
}
- return new AudioTrack(mAttributes, mFormat, mBufferSizeInBytes, mMode, mSessionId);
+ final AudioTrack track = new AudioTrack(
+ mAttributes, mFormat, mBufferSizeInBytes, mMode, mSessionId);
+ if (track.getState() == STATE_UNINITIALIZED) {
+ // release is not necessary
+ throw new UnsupportedOperationException("Cannot create AudioTrack");
+ }
+ return track;
} catch (IllegalArgumentException e) {
throw new UnsupportedOperationException(e.getMessage());
}
diff --git a/media/java/android/media/midi/IMidiDeviceServer.aidl b/media/java/android/media/midi/IMidiDeviceServer.aidl
index e30796d..c2cc2b9 100644
--- a/media/java/android/media/midi/IMidiDeviceServer.aidl
+++ b/media/java/android/media/midi/IMidiDeviceServer.aidl
@@ -31,4 +31,5 @@ interface IMidiDeviceServer
void connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber);
MidiDeviceInfo getDeviceInfo();
+ void setDeviceInfo(in MidiDeviceInfo deviceInfo);
}
diff --git a/media/java/android/media/midi/MidiDeviceServer.java b/media/java/android/media/midi/MidiDeviceServer.java
index 1b56e1c..1212b64 100644
--- a/media/java/android/media/midi/MidiDeviceServer.java
+++ b/media/java/android/media/midi/MidiDeviceServer.java
@@ -269,8 +269,20 @@ public final class MidiDeviceServer implements Closeable {
public MidiDeviceInfo getDeviceInfo() {
return mDeviceInfo;
}
+
+ @Override
+ public void setDeviceInfo(MidiDeviceInfo deviceInfo) {
+ if (Binder.getCallingUid() != Process.SYSTEM_UID) {
+ throw new SecurityException("setDeviceInfo should only be called by MidiService");
+ }
+ if (mDeviceInfo != null) {
+ throw new IllegalStateException("setDeviceInfo should only be called once");
+ }
+ mDeviceInfo = deviceInfo;
+ }
};
+ // Constructor for MidiManager.createDeviceServer()
/* package */ MidiDeviceServer(IMidiManager midiManager, MidiReceiver[] inputPortReceivers,
int numOutputPorts, Callback callback) {
mMidiManager = midiManager;
@@ -292,6 +304,13 @@ public final class MidiDeviceServer implements Closeable {
mGuard.open("close");
}
+ // Constructor for MidiDeviceService.onCreate()
+ /* package */ MidiDeviceServer(IMidiManager midiManager, MidiReceiver[] inputPortReceivers,
+ MidiDeviceInfo deviceInfo, Callback callback) {
+ this(midiManager, inputPortReceivers, deviceInfo.getOutputPortCount(), callback);
+ mDeviceInfo = deviceInfo;
+ }
+
/* package */ IMidiDeviceServer getBinderInterface() {
return mServer;
}
@@ -300,13 +319,6 @@ public final class MidiDeviceServer implements Closeable {
return mServer.asBinder();
}
- /* package */ void setDeviceInfo(MidiDeviceInfo deviceInfo) {
- if (mDeviceInfo != null) {
- throw new IllegalStateException("setDeviceInfo should only be called once");
- }
- mDeviceInfo = deviceInfo;
- }
-
private void updateDeviceStatus() {
// clear calling identity, since we may be in a Binder call from one of our clients
long identityToken = Binder.clearCallingIdentity();
diff --git a/media/java/android/media/midi/MidiDeviceService.java b/media/java/android/media/midi/MidiDeviceService.java
index d897ad2..388d95b 100644
--- a/media/java/android/media/midi/MidiDeviceService.java
+++ b/media/java/android/media/midi/MidiDeviceService.java
@@ -83,9 +83,7 @@ abstract public class MidiDeviceService extends Service {
if (inputPortReceivers == null) {
inputPortReceivers = new MidiReceiver[0];
}
- server = new MidiDeviceServer(mMidiManager, inputPortReceivers,
- deviceInfo.getOutputPortCount(), mCallback);
- server.setDeviceInfo(deviceInfo);
+ server = new MidiDeviceServer(mMidiManager, inputPortReceivers, deviceInfo, mCallback);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in IMidiManager.getServiceDeviceInfo");
server = null;
diff --git a/media/java/android/media/midi/MidiManager.java b/media/java/android/media/midi/MidiManager.java
index 0beb9a4..89230fe 100644
--- a/media/java/android/media/midi/MidiManager.java
+++ b/media/java/android/media/midi/MidiManager.java
@@ -318,7 +318,6 @@ public final class MidiManager {
Log.e(TAG, "registerVirtualDevice failed");
return null;
}
- server.setDeviceInfo(deviceInfo);
return server;
} catch (RemoteException e) {
Log.e(TAG, "RemoteException in createVirtualDevice");
diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java
index 50a215c..f52ccc9 100644
--- a/media/java/android/media/tv/TvInputService.java
+++ b/media/java/android/media/tv/TvInputService.java
@@ -434,9 +434,12 @@ public abstract class TvInputService extends Service {
}
/**
- * Informs the application that the video is now available for watching. This is primarily
- * used to signal the application to unblock the screen. The TV input service must call this
- * method as soon as the content rendered onto its surface gets ready for viewing.
+ * Informs the application that the video is now available for watching. Video is blocked
+ * until this method is called.
+ *
+ * <p>The TV input service must call this method as soon as the content rendered onto its
+ * surface is ready for viewing. This method must be called each time {@link #onTune(Uri)}
+ * is called.
*
* @see #notifyVideoUnavailable
*/
@@ -761,9 +764,11 @@ public abstract class TvInputService extends Service {
public abstract void onSetStreamVolume(float volume);
/**
- * Tunes to a given channel. When the video is available, {@link #notifyVideoAvailable()}
- * should be called. Also, {@link #notifyVideoUnavailable(int)} should be called when the TV
- * input cannot continue playing the given channel.
+ * Tunes to a given channel.
+ *
+ * <p>No video will be displayed until {@link #notifyVideoAvailable()} is called.
+ * Also, {@link #notifyVideoUnavailable(int)} should be called when the TV input cannot
+ * continue playing the given channel.
*
* @param channelUri The URI of the channel.
* @return {@code true} if the tuning was successful, {@code false} otherwise.
diff --git a/media/java/android/mtp/MtpDevice.java b/media/java/android/mtp/MtpDevice.java
index 72dcaa8..a68361b 100644
--- a/media/java/android/mtp/MtpDevice.java
+++ b/media/java/android/mtp/MtpDevice.java
@@ -132,7 +132,8 @@ public final class MtpDevice {
*
* @param storageId the storage unit to query
* @param format the format of the object to return, or zero for all formats
- * @param objectHandle the parent object to query, or zero for the storage root
+ * @param objectHandle the parent object to query, -1 for the storage root,
+ * or zero for all objects
* @return the object handles
*/
public int[] getObjectHandles(int storageId, int format, int objectHandle) {