Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29b0d287 authored by Patty Huang's avatar Patty Huang
Browse files

Checks the service is supported before binding the service

Bug: 241827236
Tag: #refactor
Test: atest CtsBluetoothTestCases
Change-Id: I27970e71ad440fd8829d387b296b12ef1236b542
parent 792bc3a9
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -129,13 +129,27 @@ public abstract class BluetoothProfileConnector<T> {
            if (mService == null) {
                logDebug("Binding service...");
                mCloseGuard.open("doUnbind");

                List<Integer> mSupportedProfileList =
                        BluetoothAdapter.getDefaultAdapter().getSupportedProfiles();

                if (!mSupportedProfileList.contains(mProfileId)) {
                    logDebug("Skip binding " + mProfileName + " service due to not supported");
                    return false;
                }

                try {
                    Intent intent = new Intent(mServiceName);
                    ComponentName comp = resolveSystemService(intent, mContext.getPackageManager());
                    intent.setComponent(comp);
                    if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
                    if (comp == null) {
                        logError("Component is null");
                        return false;
                    }
                    if (!mContext.bindServiceAsUser(intent, mConnection, 0,
                            USER_HANDLE_CURRENT_OR_SELF)) {
                        logError("Could not bind to Bluetooth Service with " + intent);
                        mContext.unbindService(mConnection);
                        return false;
                    }
                } catch (SecurityException se) {