Merge "MidiDeviceServer: Fix race condition in setting device server's mDeviceInfo" into mnc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d5ca05c3dd
@@ -31,4 +31,5 @@ interface IMidiDeviceServer
|
||||
void connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber);
|
||||
|
||||
MidiDeviceInfo getDeviceInfo();
|
||||
void setDeviceInfo(in MidiDeviceInfo deviceInfo);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -741,6 +741,15 @@ public class MidiService extends IMidiManager.Stub {
|
||||
MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts,
|
||||
inputPortNames, outputPortNames, properties, isPrivate);
|
||||
|
||||
if (server != null) {
|
||||
try {
|
||||
server.setDeviceInfo(deviceInfo);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in setDeviceInfo()");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Device device = null;
|
||||
BluetoothDevice bluetoothDevice = null;
|
||||
if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
|
||||
|
||||
Reference in New Issue
Block a user