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);
|
void connectPorts(IBinder token, in ParcelFileDescriptor pfd, int outputPortNumber);
|
||||||
|
|
||||||
MidiDeviceInfo getDeviceInfo();
|
MidiDeviceInfo getDeviceInfo();
|
||||||
|
void setDeviceInfo(in MidiDeviceInfo deviceInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,8 +269,20 @@ public final class MidiDeviceServer implements Closeable {
|
|||||||
public MidiDeviceInfo getDeviceInfo() {
|
public MidiDeviceInfo getDeviceInfo() {
|
||||||
return mDeviceInfo;
|
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,
|
/* package */ MidiDeviceServer(IMidiManager midiManager, MidiReceiver[] inputPortReceivers,
|
||||||
int numOutputPorts, Callback callback) {
|
int numOutputPorts, Callback callback) {
|
||||||
mMidiManager = midiManager;
|
mMidiManager = midiManager;
|
||||||
@@ -292,6 +304,13 @@ public final class MidiDeviceServer implements Closeable {
|
|||||||
mGuard.open("close");
|
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() {
|
/* package */ IMidiDeviceServer getBinderInterface() {
|
||||||
return mServer;
|
return mServer;
|
||||||
}
|
}
|
||||||
@@ -300,13 +319,6 @@ public final class MidiDeviceServer implements Closeable {
|
|||||||
return mServer.asBinder();
|
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() {
|
private void updateDeviceStatus() {
|
||||||
// clear calling identity, since we may be in a Binder call from one of our clients
|
// clear calling identity, since we may be in a Binder call from one of our clients
|
||||||
long identityToken = Binder.clearCallingIdentity();
|
long identityToken = Binder.clearCallingIdentity();
|
||||||
|
|||||||
@@ -83,9 +83,7 @@ abstract public class MidiDeviceService extends Service {
|
|||||||
if (inputPortReceivers == null) {
|
if (inputPortReceivers == null) {
|
||||||
inputPortReceivers = new MidiReceiver[0];
|
inputPortReceivers = new MidiReceiver[0];
|
||||||
}
|
}
|
||||||
server = new MidiDeviceServer(mMidiManager, inputPortReceivers,
|
server = new MidiDeviceServer(mMidiManager, inputPortReceivers, deviceInfo, mCallback);
|
||||||
deviceInfo.getOutputPortCount(), mCallback);
|
|
||||||
server.setDeviceInfo(deviceInfo);
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException in IMidiManager.getServiceDeviceInfo");
|
Log.e(TAG, "RemoteException in IMidiManager.getServiceDeviceInfo");
|
||||||
server = null;
|
server = null;
|
||||||
|
|||||||
@@ -318,7 +318,6 @@ public final class MidiManager {
|
|||||||
Log.e(TAG, "registerVirtualDevice failed");
|
Log.e(TAG, "registerVirtualDevice failed");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
server.setDeviceInfo(deviceInfo);
|
|
||||||
return server;
|
return server;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "RemoteException in createVirtualDevice");
|
Log.e(TAG, "RemoteException in createVirtualDevice");
|
||||||
|
|||||||
@@ -741,6 +741,15 @@ public class MidiService extends IMidiManager.Stub {
|
|||||||
MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts,
|
MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts,
|
||||||
inputPortNames, outputPortNames, properties, isPrivate);
|
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;
|
Device device = null;
|
||||||
BluetoothDevice bluetoothDevice = null;
|
BluetoothDevice bluetoothDevice = null;
|
||||||
if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
|
if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
|
||||||
|
|||||||
Reference in New Issue
Block a user