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

Commit db93bf5e authored by Hemant Gupta's avatar Hemant Gupta Committed by android-build-merger
Browse files

Merge "OPP: Fix Functionality failure for OPP Rx" am: ddff8059

am: df0e7672

Change-Id: I9091842fa616b598209ce444874c07dbca3d7c6c
parents 6d925dd2 df0e7672
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -168,8 +168,6 @@ public class BluetoothOppService extends ProfileService {
        synchronized (BluetoothOppService.this) {
            if (mAdapter == null) {
                Log.w(TAG, "Local BT device is not enabled");
            } else {
                startListener();
            }
        }
        if (V) BluetoothOppPreference.getInstance(this).dump();
@@ -179,7 +177,6 @@ public class BluetoothOppService extends ProfileService {
    @Override
    public boolean start() {
        if (V) Log.v(TAG, "start()");
        startListener();
        updateFromProvider();
        return true;
    }
@@ -230,8 +227,14 @@ public class BluetoothOppService extends ProfileService {
                       mTransfer =null;
                    }
                    synchronized (BluetoothOppService.this) {
                        if (mUpdateThread == null) {
                            stopSelf();
                        if (mUpdateThread != null) {
                            try {
                                mUpdateThread.interrupt();
                                mUpdateThread.join();
                            } catch (InterruptedException e) {
                                Log.e(TAG, "Interrupted", e);
                            }
                            mUpdateThread = null;
                        }
                    }
                    break;
@@ -369,7 +372,7 @@ public class BluetoothOppService extends ProfileService {
                switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
                    case BluetoothAdapter.STATE_ON:
                        if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON");
                        startSocketListener();
                        startListener();
                        // If this is within a sending process, continue the handle
                        // logic to display device picker dialog.
                        synchronized (this) {
@@ -412,29 +415,36 @@ public class BluetoothOppService extends ProfileService {
    }

    private class UpdateThread extends Thread {
        private boolean isInterrupted ;
        public UpdateThread() {
            super("Bluetooth Share Service");
            isInterrupted = false;
        }

        @Override
        public void interrupt() {
            isInterrupted = true;
            if (D) Log.d(TAG, "Interrupted :" + isInterrupted);
            super.interrupt();
        }


        @Override
        public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            boolean keepService = false;
            for (;;) {
            while (!isInterrupted) {
                synchronized (BluetoothOppService.this) {
                    if (mUpdateThread != this) {
                        throw new IllegalStateException(
                                "multiple UpdateThreads in BluetoothOppService");
                    }
                    if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is "
                                + keepService + " sListenStarted is " + mListenStarted);
                                + keepService + " sListenStarted is " + mListenStarted +
                                " isInterrupted :" + isInterrupted );
                    if (!mPendingUpdate) {
                        mUpdateThread = null;
                        if (!keepService && !mListenStarted) {
                            stopSelf();
                            break;
                        }
                        return;
                    }
                    mPendingUpdate = false;
@@ -469,7 +479,7 @@ public class BluetoothOppService extends ProfileService {
                 * contains an entry that's not in the array, insert a new entry
                 * in the array, move to next cursor row and next array entry.
                 */
                while (!isAfterLast || arrayPos < mShares.size()) {
                while (!isAfterLast || arrayPos < mShares.size() && mListenStarted) {
                    if (isAfterLast) {
                        // We're beyond the end of the cursor but there's still
                        // some