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

Commit 20b8be05 authored by Nitin Shivpure's avatar Nitin Shivpure Committed by Steve Kondik
Browse files

Bluetooth: Fix to avoid framework reboot during monkey.

A case where monkey is running & sometimes framework is
disconnected due to unhandled java Exception during the
binding of DUN, SAP, HID device & PAN service on unsuccessful
binding. So it never handled. Handing java exception while binding
DUN, SAP, HID device & PAN  services to solve this issue.

Change-Id: Idea710593a3f9496305f636042605303e73e7749
CRs-Fixed: 564709
parent eeef98b9
Loading
Loading
Loading
Loading
+23 −10
Original line number Diff line number Diff line
@@ -98,13 +98,21 @@ public final class BluetoothDun implements BluetoothProfile {
            Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
        }
        Log.d(TAG, "BluetoothDun() call bindService");
        if (!context.bindService(new Intent(IBluetoothDun.class.getName()),
                                 mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth DUN Service");
        doBind();
    }
        Log.d(TAG, "BluetoothDun(), bindService called");

    boolean doBind() {
        Intent intent = new Intent(IBluetoothDun.class.getName());
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindService(intent, mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth Dun Service with " + intent);
            return false;
        }
        return true;
    }


    /*package*/ void close() {
        if (VDBG) log("close()");
        mServiceListener = null;
@@ -137,15 +145,20 @@ public final class BluetoothDun implements BluetoothProfile {
                                    new IBluetoothStateChangeCallback.Stub() {

        @Override
        public void onBluetoothStateChange(boolean on) throws RemoteException {
        public void onBluetoothStateChange(boolean on) {
            //Handle enable request to bind again.
            Log.d(TAG, "onBluetoothStateChange on: " + on);
            if (on) {
                Log.d(TAG, "onBluetoothStateChange(on) call bindService");
                if (!mContext.bindService(new Intent(IBluetoothDun.class.getName()),
                                     mConnection, 0)) {
                    Log.e(TAG, "Could not bind to Bluetooth DUN Service");
                try {
                    if (mDunService == null) {
                        Log.d(TAG, "onBluetoothStateChange call bindService");
                        doBind();
                    }
                } catch (IllegalStateException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to DUN service: ", e);
                } catch (SecurityException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to DUN service: ", e);
                }
                Log.d(TAG, "BluetoothDun(), bindService called");
            } else {
                if (VDBG) Log.d(TAG,"Unbinding service...");
                synchronized (mConnection) {
+22 −10
Original line number Diff line number Diff line
@@ -136,18 +136,21 @@ public final class BluetoothHidDevice implements BluetoothProfile {

        public void onBluetoothStateChange(boolean up) {
            Log.d(TAG, "onBluetoothStateChange: up=" + up);

            synchronized (mConnection) {
                if (!up) {
                    Log.d(TAG,"Unbinding service...");
                    mService = null;
                    mContext.unbindService(mConnection);
                } else {
                    try {
                        if (mService == null) {
                        Log.v(TAG, "Binding service");
                        if (!mContext.bindService(new Intent(IBluetoothHidDevice.class.getName()),
                            mConnection, 0)) {
                            Log.e(TAG, "Could not bind service");
                            Log.d(TAG,"Binding HID Device service...");
                            doBind();
                        }
                    } catch (IllegalStateException e) {
                        Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
                    } catch (SecurityException e) {
                        Log.e(TAG,"onBluetoothStateChange: could not bind to HID Dev service: ", e);
                    }
                }
            }
@@ -179,7 +182,7 @@ public final class BluetoothHidDevice implements BluetoothProfile {
    };

    BluetoothHidDevice(Context context, ServiceListener listener) {
        Log.v(TAG, "BluetoothInputDevice()");
        Log.v(TAG, "BluetoothHidDevice");

        mContext = context;
        mServiceListener = listener;
@@ -194,10 +197,19 @@ public final class BluetoothHidDevice implements BluetoothProfile {
            }
        }

        if (!context.bindService(new Intent(IBluetoothHidDevice.class.getName()),
            mConnection, 0)) {
            Log.e(TAG, "Could not bind service");
        doBind();
    }

    boolean doBind() {
        Intent intent = new Intent(IBluetoothHidDevice.class.getName());
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindService(intent, mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth HID Device Service with " + intent);
            return false;
        }
        Log.d(TAG, "Bound to HID Device Service");
        return true;
    }

    void close() {
+12 −5
Original line number Diff line number Diff line
@@ -139,7 +139,6 @@ public final class BluetoothPan implements BluetoothProfile {
        }
        if (VDBG) Log.d(TAG, "BluetoothPan() call bindService");
        doBind();
        if (VDBG) Log.d(TAG, "BluetoothPan(), bindService called");
    }

    boolean doBind() {
@@ -185,12 +184,20 @@ public final class BluetoothPan implements BluetoothProfile {
    final private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() {

        @Override
        public void onBluetoothStateChange(boolean on) throws RemoteException {
        public void onBluetoothStateChange(boolean on) {
            //Handle enable request to bind again.
            Log.d(TAG, "onBluetoothStateChange on: " + on);
            if (on) {
                Log.d(TAG, "onBluetoothStateChange(on) call bindService");
                try {
                    if (mPanService == null) {
                        Log.d(TAG, "onBluetoothStateChange call bindService");
                        doBind();
                if (VDBG) Log.d(TAG, "BluetoothPan(), bindService called");
                    }
                } catch (IllegalStateException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e);
                } catch (SecurityException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to PAN service: ", e);
                }
            } else {
                if (VDBG) Log.d(TAG,"Unbinding service...");
                synchronized (mConnection) {
+22 −10
Original line number Diff line number Diff line
@@ -98,11 +98,18 @@ public final class BluetoothSap implements BluetoothProfile {
            Log.w(TAG,"Unable to register BluetoothStateChangeCallback",re);
        }
        Log.d(TAG, "BluetoothSap() call bindService");
        if (!context.bindService(new Intent(IBluetoothSap.class.getName()),
                                 mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth SAP Service");
        doBind();
    }
        Log.d(TAG, "BluetoothSap(), bindService called");

    boolean doBind() {
        Intent intent = new Intent(IBluetoothSap.class.getName());
        ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
        intent.setComponent(comp);
        if (comp == null || !mContext.bindService(intent, mConnection, 0)) {
            Log.e(TAG, "Could not bind to Bluetooth Sap Service with " + intent);
            return false;
        }
        return true;
    }

    /*package*/ void close() {
@@ -137,15 +144,20 @@ public final class BluetoothSap implements BluetoothProfile {
    private IBluetoothStateChangeCallback mStateChangeCallback = new IBluetoothStateChangeCallback.Stub() {

        @Override
        public void onBluetoothStateChange(boolean on) throws RemoteException {
        public void onBluetoothStateChange(boolean on) {
            //Handle enable request to bind again.
            Log.d(TAG, "onBluetoothStateChange on: " + on);
            if (on) {
                Log.d(TAG, "onBluetoothStateChange(on) call bindService");
                if (!mContext.bindService(new Intent(IBluetoothSap.class.getName()),
                                     mConnection, 0)) {
                    Log.e(TAG, "Could not bind to Bluetooth SAP Service");
                try {
                    if (mSapService == null) {
                        Log.d(TAG, "onBluetoothStateChange call bindService");
                        doBind();
                    }
                } catch (IllegalStateException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to SAP service: ", e);
                } catch (SecurityException e) {
                    Log.e(TAG,"onBluetoothStateChange: could not bind to SAP service: ", e);
                }
                Log.d(TAG, "BluetoothSap(), bindService called");
            } else {
                if (VDBG) Log.d(TAG,"Unbinding service...");
                synchronized (mConnection) {