diff options
Diffstat (limited to 'service/java/com')
-rw-r--r-- | service/java/com/android/server/bluetooth/BluetoothManagerService.java | 45 | ||||
-rw-r--r-- | service/java/com/android/server/bluetooth/BluetoothService.java | 8 |
2 files changed, 34 insertions, 19 deletions
diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java index fb19c6f848..e7fcf56692 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -115,6 +115,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { private static final int ACTIVE_LOG_MAX_SIZE = 20; private static final int CRASH_LOG_MAX_SIZE = 100; + private static final int DEFAULT_REBIND_COUNT = 3; private static final int TIMEOUT_BIND_MS = 3000; //Maximum msec to wait for a bind /** @@ -1538,23 +1539,23 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { } synchronized (mProfileServices) { ProfileServiceConnections psc = mProfileServices.get(new Integer(bluetoothProfile)); + Intent intent; + if (bluetoothProfile == BluetoothProfile.HEADSET + && BluetoothProperties.isProfileHfpAgEnabled().orElse(false)) { + intent = new Intent(IBluetoothHeadset.class.getName()); + } else if (bluetoothProfile == BluetoothProfile.LE_CALL_CONTROL + && BluetoothProperties.isProfileCcpServerEnabled().orElse(false)) { + intent = new Intent(IBluetoothLeCallControl.class.getName()); + } else { + return false; + } if (psc == null) { if (DBG) { Log.d(TAG, "Creating new ProfileServiceConnections object for" + " profile: " + bluetoothProfile); } - - Intent intent; - if (bluetoothProfile == BluetoothProfile.HEADSET) { - intent = new Intent(IBluetoothHeadset.class.getName()); - } else if (bluetoothProfile== BluetoothProfile.LE_CALL_CONTROL) { - intent = new Intent(IBluetoothLeCallControl.class.getName()); - } else { - return false; - } - psc = new ProfileServiceConnections(intent); - if (!psc.bindService()) { + if (!psc.bindService(DEFAULT_REBIND_COUNT)) { return false; } @@ -1689,7 +1690,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { mIntent = intent; } - private boolean bindService() { + private boolean bindService(int rebindCount) { int state = BluetoothAdapter.STATE_OFF; try { mBluetoothLock.readLock().lock(); @@ -1712,6 +1713,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { && doBind(mIntent, this, 0, USER_HANDLE_CURRENT_OR_SELF)) { Message msg = mHandler.obtainMessage(MESSAGE_BIND_PROFILE_SERVICE); msg.obj = this; + msg.arg1 = rebindCount; mHandler.sendMessageDelayed(msg, TIMEOUT_BIND_MS); return true; } @@ -1738,6 +1740,7 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { if (!mHandler.hasMessages(MESSAGE_BIND_PROFILE_SERVICE, this)) { Message msg = mHandler.obtainMessage(MESSAGE_BIND_PROFILE_SERVICE); msg.obj = this; + msg.arg1 = DEFAULT_REBIND_COUNT; mHandler.sendMessage(msg); } } @@ -2506,8 +2509,11 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { Log.w(TAG, "psc is null, breaking"); break; } - Log.w(TAG, "Calling psc.bindService from MESSAGE_BIND_PROFILE_SERVICE"); - psc.bindService(); + if (msg.arg1 > 0) { + mContext.unbindService(psc); + Log.w(TAG, "Calling psc.bindService from MESSAGE_BIND_PROFILE_SERVICE"); + psc.bindService(msg.arg1 - 1); + } break; } case MESSAGE_BLUETOOTH_SERVICE_CONNECTED: { @@ -3336,9 +3342,14 @@ public class BluetoothManagerService extends IBluetoothManager.Stub { final ComponentName oppLauncherComponent = new ComponentName( mContext.getPackageManager().getPackagesForUid(Process.BLUETOOTH_UID)[0], "com.android.bluetooth.opp.BluetoothOppLauncherActivity"); - final int newState = - bluetoothSharingDisallowed ? PackageManager.COMPONENT_ENABLED_STATE_DISABLED - : PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; + int newState; + if (bluetoothSharingDisallowed) { + newState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED; + } else if (BluetoothProperties.isProfileOppEnabled().orElse(false)) { + newState = PackageManager.COMPONENT_ENABLED_STATE_ENABLED; + } else { + newState = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; + } try { mContext.createContextAsUser(userHandle, 0) .getPackageManager() diff --git a/service/java/com/android/server/bluetooth/BluetoothService.java b/service/java/com/android/server/bluetooth/BluetoothService.java index ff6938e5f6..a729f8213a 100644 --- a/service/java/com/android/server/bluetooth/BluetoothService.java +++ b/service/java/com/android/server/bluetooth/BluetoothService.java @@ -50,8 +50,12 @@ public class BluetoothService extends SystemService { if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, mBluetoothManagerService); - } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY && - !UserManager.isHeadlessSystemUserMode()) { + } + } + + @Override + public void onUserStarting(@NonNull TargetUser user) { + if (!UserManager.isHeadlessSystemUserMode()) { initialize(); } } |