Loading android/app/src/com/android/bluetooth/opp/BluetoothOppService.java 100755 → 100644 +23 −13 Original line number Original line Diff line number Diff line Loading @@ -168,8 +168,6 @@ public class BluetoothOppService extends ProfileService { synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mAdapter == null) { if (mAdapter == null) { Log.w(TAG, "Local BT device is not enabled"); Log.w(TAG, "Local BT device is not enabled"); } else { startListener(); } } } } if (V) BluetoothOppPreference.getInstance(this).dump(); if (V) BluetoothOppPreference.getInstance(this).dump(); Loading @@ -179,7 +177,6 @@ public class BluetoothOppService extends ProfileService { @Override @Override public boolean start() { public boolean start() { if (V) Log.v(TAG, "start()"); if (V) Log.v(TAG, "start()"); startListener(); updateFromProvider(); updateFromProvider(); return true; return true; } } Loading Loading @@ -230,8 +227,14 @@ public class BluetoothOppService extends ProfileService { mTransfer =null; mTransfer =null; } } synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mUpdateThread == null) { if (mUpdateThread != null) { stopSelf(); try { mUpdateThread.interrupt(); mUpdateThread.join(); } catch (InterruptedException e) { Log.e(TAG, "Interrupted", e); } mUpdateThread = null; } } } } break; break; Loading Loading @@ -369,7 +372,7 @@ public class BluetoothOppService extends ProfileService { switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) { switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) { case BluetoothAdapter.STATE_ON: case BluetoothAdapter.STATE_ON: if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON"); if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON"); startSocketListener(); startListener(); // If this is within a sending process, continue the handle // If this is within a sending process, continue the handle // logic to display device picker dialog. // logic to display device picker dialog. synchronized (this) { synchronized (this) { Loading Loading @@ -412,29 +415,36 @@ public class BluetoothOppService extends ProfileService { } } private class UpdateThread extends Thread { private class UpdateThread extends Thread { private boolean isInterrupted ; public UpdateThread() { public UpdateThread() { super("Bluetooth Share Service"); super("Bluetooth Share Service"); isInterrupted = false; } } @Override public void interrupt() { isInterrupted = true; if (D) Log.d(TAG, "Interrupted :" + isInterrupted); super.interrupt(); } @Override @Override public void run() { public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); boolean keepService = false; boolean keepService = false; for (;;) { while (!isInterrupted) { synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mUpdateThread != this) { if (mUpdateThread != this) { throw new IllegalStateException( throw new IllegalStateException( "multiple UpdateThreads in BluetoothOppService"); "multiple UpdateThreads in BluetoothOppService"); } } if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); + keepService + " sListenStarted is " + mListenStarted + " isInterrupted :" + isInterrupted ); if (!mPendingUpdate) { if (!mPendingUpdate) { mUpdateThread = null; mUpdateThread = null; if (!keepService && !mListenStarted) { stopSelf(); break; } return; return; } } mPendingUpdate = false; mPendingUpdate = false; Loading Loading @@ -469,7 +479,7 @@ public class BluetoothOppService extends ProfileService { * contains an entry that's not in the array, insert a new entry * 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. * 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) { if (isAfterLast) { // We're beyond the end of the cursor but there's still // We're beyond the end of the cursor but there's still // some // some Loading Loading
android/app/src/com/android/bluetooth/opp/BluetoothOppService.java 100755 → 100644 +23 −13 Original line number Original line Diff line number Diff line Loading @@ -168,8 +168,6 @@ public class BluetoothOppService extends ProfileService { synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mAdapter == null) { if (mAdapter == null) { Log.w(TAG, "Local BT device is not enabled"); Log.w(TAG, "Local BT device is not enabled"); } else { startListener(); } } } } if (V) BluetoothOppPreference.getInstance(this).dump(); if (V) BluetoothOppPreference.getInstance(this).dump(); Loading @@ -179,7 +177,6 @@ public class BluetoothOppService extends ProfileService { @Override @Override public boolean start() { public boolean start() { if (V) Log.v(TAG, "start()"); if (V) Log.v(TAG, "start()"); startListener(); updateFromProvider(); updateFromProvider(); return true; return true; } } Loading Loading @@ -230,8 +227,14 @@ public class BluetoothOppService extends ProfileService { mTransfer =null; mTransfer =null; } } synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mUpdateThread == null) { if (mUpdateThread != null) { stopSelf(); try { mUpdateThread.interrupt(); mUpdateThread.join(); } catch (InterruptedException e) { Log.e(TAG, "Interrupted", e); } mUpdateThread = null; } } } } break; break; Loading Loading @@ -369,7 +372,7 @@ public class BluetoothOppService extends ProfileService { switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) { switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) { case BluetoothAdapter.STATE_ON: case BluetoothAdapter.STATE_ON: if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON"); if (V) Log.v(TAG, "Bluetooth state changed: STATE_ON"); startSocketListener(); startListener(); // If this is within a sending process, continue the handle // If this is within a sending process, continue the handle // logic to display device picker dialog. // logic to display device picker dialog. synchronized (this) { synchronized (this) { Loading Loading @@ -412,29 +415,36 @@ public class BluetoothOppService extends ProfileService { } } private class UpdateThread extends Thread { private class UpdateThread extends Thread { private boolean isInterrupted ; public UpdateThread() { public UpdateThread() { super("Bluetooth Share Service"); super("Bluetooth Share Service"); isInterrupted = false; } } @Override public void interrupt() { isInterrupted = true; if (D) Log.d(TAG, "Interrupted :" + isInterrupted); super.interrupt(); } @Override @Override public void run() { public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); boolean keepService = false; boolean keepService = false; for (;;) { while (!isInterrupted) { synchronized (BluetoothOppService.this) { synchronized (BluetoothOppService.this) { if (mUpdateThread != this) { if (mUpdateThread != this) { throw new IllegalStateException( throw new IllegalStateException( "multiple UpdateThreads in BluetoothOppService"); "multiple UpdateThreads in BluetoothOppService"); } } if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " if (V) Log.v(TAG, "pendingUpdate is " + mPendingUpdate + " keepUpdateThread is " + keepService + " sListenStarted is " + mListenStarted); + keepService + " sListenStarted is " + mListenStarted + " isInterrupted :" + isInterrupted ); if (!mPendingUpdate) { if (!mPendingUpdate) { mUpdateThread = null; mUpdateThread = null; if (!keepService && !mListenStarted) { stopSelf(); break; } return; return; } } mPendingUpdate = false; mPendingUpdate = false; Loading Loading @@ -469,7 +479,7 @@ public class BluetoothOppService extends ProfileService { * contains an entry that's not in the array, insert a new entry * 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. * 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) { if (isAfterLast) { // We're beyond the end of the cursor but there's still // We're beyond the end of the cursor but there's still // some // some Loading