Loading core/java/android/server/BluetoothA2dpService.java +5 −20 Original line number Diff line number Diff line Loading @@ -187,25 +187,11 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { return false; } private synchronized boolean addAudioSink(BluetoothDevice device) { String path = mBluetoothService.getObjectPathFromAddress(device.getAddress()); String propValues[] = (String []) getSinkPropertiesNative(path); if (propValues == null) { Log.e(TAG, "Error while getting AudioSink properties for device: " + device); return false; } Integer state = null; // Properties are name-value pairs for (int i = 0; i < propValues.length; i+=2) { if (propValues[i].equals(PROPERTY_STATE)) { state = new Integer(convertBluezSinkStringToState(propValues[i+1])); break; private synchronized void addAudioSink(BluetoothDevice device) { if (mAudioDevices.get(device) == null) { mAudioDevices.put(device, BluetoothA2dp.STATE_DISCONNECTED); } } mAudioDevices.put(device, state); handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state); return true; } private synchronized void onBluetoothEnable() { String devices = mBluetoothService.getProperty("Devices"); Loading Loading @@ -259,9 +245,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { return false; } if (mAudioDevices.get(device) == null && !addAudioSink(device)) { return false; } addAudioSink(device); String path = mBluetoothService.getObjectPathFromAddress(device.getAddress()); if (path == null) { Loading Loading @@ -495,6 +479,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { // This is for an incoming connection for a device not known to us. // We have authorized it and bluez state has changed. addAudioSink(device); handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state); } else { if (state == BluetoothA2dp.STATE_PLAYING && mPlayingA2dpDevice == null) { mPlayingA2dpDevice = device; Loading core/java/android/server/BluetoothAdapterStateMachine.java +13 −19 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { private class PowerOff extends State { @Override public void enter() { if (DBG) log("Enter PowerOff: "); if (DBG) log("Enter PowerOff: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading Loading @@ -280,7 +280,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { if (DBG) log("Enter WarmUp"); if (DBG) log("Enter WarmUp: " + getCurrentMessage().what); } @Override Loading Loading @@ -319,7 +319,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { private class HotOff extends State { @Override public void enter() { if (DBG) log("Enter HotOff:"); if (DBG) log("Enter HotOff: " + getCurrentMessage().what); } @Override Loading Loading @@ -380,8 +380,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { int what = getCurrentMessage().what; if (DBG) log("Enter Switching: " + what); if (DBG) log("Enter Switching: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading @@ -390,13 +389,12 @@ final class BluetoothAdapterStateMachine extends StateMachine { boolean retValue = HANDLED; switch(message.what) { case BECAME_PAIRABLE: String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")}; mEventLoop.onPropertyChanged(propVal); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); mBluetoothService.initBluetoothAfterTurningOn(); transitionTo(mBluetoothOn); broadcastState(BluetoothAdapter.STATE_ON); // run bluetooth now that it's turned on // Note runBluetooth should be called only in adapter STATE_ON mBluetoothService.runBluetooth(); break; case BECAME_NON_PAIRABLE: if (mBluetoothService.getAdapterConnectionState() == Loading Loading @@ -438,11 +436,10 @@ final class BluetoothAdapterStateMachine extends StateMachine { } private class BluetoothOn extends State { private boolean mPersistBluetoothOff = false; @Override public void enter() { if (DBG) log("Enter BluetoothOn: " + mPersistBluetoothOff); if (DBG) log("Enter BluetoothOn: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading Loading @@ -500,7 +497,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { if (DBG) log("Enter PerProcessState"); if (DBG) log("Enter PerProcessState: " + getCurrentMessage().what); } @Override Loading @@ -523,14 +520,11 @@ final class BluetoothAdapterStateMachine extends StateMachine { case USER_TURN_ON: broadcastState(BluetoothAdapter.STATE_TURNING_ON); persistSwitchSetting(true); String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")}; mEventLoop.onPropertyChanged(propVal); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); mBluetoothService.initBluetoothAfterTurningOn(); transitionTo(mBluetoothOn); broadcastState(BluetoothAdapter.STATE_ON); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); break; case USER_TURN_OFF: broadcastState(BluetoothAdapter.STATE_TURNING_OFF); Loading core/java/android/server/BluetoothBondState.java +1 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ class BluetoothBondState { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST); mContext.registerReceiver(mReceiver, filter); readAutoPairingData(); } synchronized void setPendingOutgoingBonding(String address) { Loading core/java/android/server/BluetoothEventLoop.java +0 −2 Original line number Diff line number Diff line Loading @@ -354,12 +354,10 @@ class BluetoothEventLoop { Intent intent; adapterProperties.setProperty(name, propValues[1]); if (propValues[1].equals("true")) { mBluetoothService.setIsDiscovering(true); intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED); } else { // Stop the discovery. mBluetoothService.cancelDiscovery(); mBluetoothService.setIsDiscovering(false); intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); } mContext.sendBroadcast(intent, BLUETOOTH_PERM); Loading core/java/android/server/BluetoothService.java +20 −17 Original line number Diff line number Diff line Loading @@ -96,7 +96,6 @@ public class BluetoothService extends IBluetooth.Stub { private boolean mIsAirplaneToggleable; private BluetoothAdapterStateMachine mBluetoothState; private boolean mRestart = false; // need to call enable() after disable() private boolean mIsDiscovering; private int[] mAdapterSdpHandles; private ParcelUuid[] mAdapterUuids; Loading Loading @@ -213,8 +212,6 @@ public class BluetoothService extends IBluetooth.Stub { disableNative(); } mIsDiscovering = false; mBondState = new BluetoothBondState(context, this); mAdapterProperties = new BluetoothAdapterProperties(context, this); mDeviceProperties = new BluetoothDeviceProperties(this); Loading Loading @@ -411,7 +408,6 @@ public class BluetoothService extends IBluetooth.Stub { intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE); mContext.sendBroadcast(intent, BLUETOOTH_PERM); mIsDiscovering = false; mAdapterProperties.clear(); mServiceRecordToPid.clear(); Loading Loading @@ -482,8 +478,6 @@ public class BluetoothService extends IBluetooth.Stub { if (!setupNativeDataNative()) { return false; } mIsDiscovering = false; switchConnectable(false); updateSdpRecords(); return true; Loading Loading @@ -586,17 +580,22 @@ public class BluetoothService extends IBluetooth.Stub { } } /** * This method is called immediately before Bluetooth module is turned on after * the adapter became pariable. * It inits bond state and profile state before STATE_ON intent is broadcasted. */ /*package*/ void initBluetoothAfterTurningOn() { mBondState.initBondState(); initProfileState(); } /** * This method is called immediately after Bluetooth module is turned on. * It starts auto-connection and places bluetooth on sign onto the battery * stats */ /*package*/ void runBluetooth() { mIsDiscovering = false; mBondState.readAutoPairingData(); mBondState.initBondState(); initProfileState(); autoConnect(); // Log bluetooth on to battery stats. Loading Loading @@ -787,12 +786,14 @@ public class BluetoothService extends IBluetooth.Stub { } if (allowOnlyInOnState) { setPropertyBoolean("Pairable", pairable); setPropertyBoolean("Discoverable", discoverable); setPropertyBoolean("Pairable", pairable); } else { // allowed to set the property through native layer directly setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0); setAdapterPropertyBooleanNative("Discoverable", discoverable ? 1 : 0); // do setting pairable after setting discoverable since the adapter // state machine uses pairable event for state change setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0); } return true; } Loading Loading @@ -949,11 +950,13 @@ public class BluetoothService extends IBluetooth.Stub { public synchronized boolean isDiscovering() { mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); return mIsDiscovering; String discoveringProperty = mAdapterProperties.getProperty("Discovering"); if (discoveringProperty == null) { return false; } /* package */ void setIsDiscovering(boolean isDiscovering) { mIsDiscovering = isDiscovering; return discoveringProperty.equals("true"); } private boolean isBondingFeasible(String address) { Loading Loading
core/java/android/server/BluetoothA2dpService.java +5 −20 Original line number Diff line number Diff line Loading @@ -187,25 +187,11 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { return false; } private synchronized boolean addAudioSink(BluetoothDevice device) { String path = mBluetoothService.getObjectPathFromAddress(device.getAddress()); String propValues[] = (String []) getSinkPropertiesNative(path); if (propValues == null) { Log.e(TAG, "Error while getting AudioSink properties for device: " + device); return false; } Integer state = null; // Properties are name-value pairs for (int i = 0; i < propValues.length; i+=2) { if (propValues[i].equals(PROPERTY_STATE)) { state = new Integer(convertBluezSinkStringToState(propValues[i+1])); break; private synchronized void addAudioSink(BluetoothDevice device) { if (mAudioDevices.get(device) == null) { mAudioDevices.put(device, BluetoothA2dp.STATE_DISCONNECTED); } } mAudioDevices.put(device, state); handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state); return true; } private synchronized void onBluetoothEnable() { String devices = mBluetoothService.getProperty("Devices"); Loading Loading @@ -259,9 +245,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { return false; } if (mAudioDevices.get(device) == null && !addAudioSink(device)) { return false; } addAudioSink(device); String path = mBluetoothService.getObjectPathFromAddress(device.getAddress()); if (path == null) { Loading Loading @@ -495,6 +479,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { // This is for an incoming connection for a device not known to us. // We have authorized it and bluez state has changed. addAudioSink(device); handleSinkStateChange(device, BluetoothA2dp.STATE_DISCONNECTED, state); } else { if (state == BluetoothA2dp.STATE_PLAYING && mPlayingA2dpDevice == null) { mPlayingA2dpDevice = device; Loading
core/java/android/server/BluetoothAdapterStateMachine.java +13 −19 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { private class PowerOff extends State { @Override public void enter() { if (DBG) log("Enter PowerOff: "); if (DBG) log("Enter PowerOff: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading Loading @@ -280,7 +280,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { if (DBG) log("Enter WarmUp"); if (DBG) log("Enter WarmUp: " + getCurrentMessage().what); } @Override Loading Loading @@ -319,7 +319,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { private class HotOff extends State { @Override public void enter() { if (DBG) log("Enter HotOff:"); if (DBG) log("Enter HotOff: " + getCurrentMessage().what); } @Override Loading Loading @@ -380,8 +380,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { int what = getCurrentMessage().what; if (DBG) log("Enter Switching: " + what); if (DBG) log("Enter Switching: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading @@ -390,13 +389,12 @@ final class BluetoothAdapterStateMachine extends StateMachine { boolean retValue = HANDLED; switch(message.what) { case BECAME_PAIRABLE: String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")}; mEventLoop.onPropertyChanged(propVal); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); mBluetoothService.initBluetoothAfterTurningOn(); transitionTo(mBluetoothOn); broadcastState(BluetoothAdapter.STATE_ON); // run bluetooth now that it's turned on // Note runBluetooth should be called only in adapter STATE_ON mBluetoothService.runBluetooth(); break; case BECAME_NON_PAIRABLE: if (mBluetoothService.getAdapterConnectionState() == Loading Loading @@ -438,11 +436,10 @@ final class BluetoothAdapterStateMachine extends StateMachine { } private class BluetoothOn extends State { private boolean mPersistBluetoothOff = false; @Override public void enter() { if (DBG) log("Enter BluetoothOn: " + mPersistBluetoothOff); if (DBG) log("Enter BluetoothOn: " + getCurrentMessage().what); } @Override public boolean processMessage(Message message) { Loading Loading @@ -500,7 +497,7 @@ final class BluetoothAdapterStateMachine extends StateMachine { @Override public void enter() { if (DBG) log("Enter PerProcessState"); if (DBG) log("Enter PerProcessState: " + getCurrentMessage().what); } @Override Loading @@ -523,14 +520,11 @@ final class BluetoothAdapterStateMachine extends StateMachine { case USER_TURN_ON: broadcastState(BluetoothAdapter.STATE_TURNING_ON); persistSwitchSetting(true); String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")}; mEventLoop.onPropertyChanged(propVal); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); mBluetoothService.initBluetoothAfterTurningOn(); transitionTo(mBluetoothOn); broadcastState(BluetoothAdapter.STATE_ON); // run bluetooth now that it's turned on mBluetoothService.runBluetooth(); break; case USER_TURN_OFF: broadcastState(BluetoothAdapter.STATE_TURNING_OFF); Loading
core/java/android/server/BluetoothBondState.java +1 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ class BluetoothBondState { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST); mContext.registerReceiver(mReceiver, filter); readAutoPairingData(); } synchronized void setPendingOutgoingBonding(String address) { Loading
core/java/android/server/BluetoothEventLoop.java +0 −2 Original line number Diff line number Diff line Loading @@ -354,12 +354,10 @@ class BluetoothEventLoop { Intent intent; adapterProperties.setProperty(name, propValues[1]); if (propValues[1].equals("true")) { mBluetoothService.setIsDiscovering(true); intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_STARTED); } else { // Stop the discovery. mBluetoothService.cancelDiscovery(); mBluetoothService.setIsDiscovering(false); intent = new Intent(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); } mContext.sendBroadcast(intent, BLUETOOTH_PERM); Loading
core/java/android/server/BluetoothService.java +20 −17 Original line number Diff line number Diff line Loading @@ -96,7 +96,6 @@ public class BluetoothService extends IBluetooth.Stub { private boolean mIsAirplaneToggleable; private BluetoothAdapterStateMachine mBluetoothState; private boolean mRestart = false; // need to call enable() after disable() private boolean mIsDiscovering; private int[] mAdapterSdpHandles; private ParcelUuid[] mAdapterUuids; Loading Loading @@ -213,8 +212,6 @@ public class BluetoothService extends IBluetooth.Stub { disableNative(); } mIsDiscovering = false; mBondState = new BluetoothBondState(context, this); mAdapterProperties = new BluetoothAdapterProperties(context, this); mDeviceProperties = new BluetoothDeviceProperties(this); Loading Loading @@ -411,7 +408,6 @@ public class BluetoothService extends IBluetooth.Stub { intent.putExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE); mContext.sendBroadcast(intent, BLUETOOTH_PERM); mIsDiscovering = false; mAdapterProperties.clear(); mServiceRecordToPid.clear(); Loading Loading @@ -482,8 +478,6 @@ public class BluetoothService extends IBluetooth.Stub { if (!setupNativeDataNative()) { return false; } mIsDiscovering = false; switchConnectable(false); updateSdpRecords(); return true; Loading Loading @@ -586,17 +580,22 @@ public class BluetoothService extends IBluetooth.Stub { } } /** * This method is called immediately before Bluetooth module is turned on after * the adapter became pariable. * It inits bond state and profile state before STATE_ON intent is broadcasted. */ /*package*/ void initBluetoothAfterTurningOn() { mBondState.initBondState(); initProfileState(); } /** * This method is called immediately after Bluetooth module is turned on. * It starts auto-connection and places bluetooth on sign onto the battery * stats */ /*package*/ void runBluetooth() { mIsDiscovering = false; mBondState.readAutoPairingData(); mBondState.initBondState(); initProfileState(); autoConnect(); // Log bluetooth on to battery stats. Loading Loading @@ -787,12 +786,14 @@ public class BluetoothService extends IBluetooth.Stub { } if (allowOnlyInOnState) { setPropertyBoolean("Pairable", pairable); setPropertyBoolean("Discoverable", discoverable); setPropertyBoolean("Pairable", pairable); } else { // allowed to set the property through native layer directly setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0); setAdapterPropertyBooleanNative("Discoverable", discoverable ? 1 : 0); // do setting pairable after setting discoverable since the adapter // state machine uses pairable event for state change setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0); } return true; } Loading Loading @@ -949,11 +950,13 @@ public class BluetoothService extends IBluetooth.Stub { public synchronized boolean isDiscovering() { mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); return mIsDiscovering; String discoveringProperty = mAdapterProperties.getProperty("Discovering"); if (discoveringProperty == null) { return false; } /* package */ void setIsDiscovering(boolean isDiscovering) { mIsDiscovering = isDiscovering; return discoveringProperty.equals("true"); } private boolean isBondingFeasible(String address) { Loading