From 01e70d1c9f50b304639c8d8a0a26c86e6683f296 Mon Sep 17 00:00:00 2001 From: Sumit Bajpai Date: Tue, 3 Nov 2015 11:29:09 +0530 Subject: AVRCP1.5: Correct content resolver query for playlist items. When changepath is requested by remote to playlist items inside any playlist, we return only single media item count in response. This is because of incorrect query for content resolver. This change properly fetches the playlist media items from content resolver. Change-Id: I73e1c9ceec611ef806b6f1b4e2d3c5f20509490e --- src/com/android/bluetooth/avrcp/Avrcp.java | 37 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/com/android/bluetooth/avrcp/Avrcp.java b/src/com/android/bluetooth/avrcp/Avrcp.java index 14ebb71fa..cffb64876 100644 --- a/src/com/android/bluetooth/avrcp/Avrcp.java +++ b/src/com/android/bluetooth/avrcp/Avrcp.java @@ -2418,28 +2418,33 @@ public final class Avrcp { case FOLDER_DOWN: if (deviceFeatures[deviceIndex].mCurrentPathUid == null) { Cursor cursor = null; + String[] playlistMemberCols = new String[] { + MediaStore.Audio.Playlists.Members._ID, + MediaStore.Audio.Media.TITLE, + MediaStore.Audio.Media.DATA, + MediaStore.Audio.Media.ALBUM, + MediaStore.Audio.Media.ARTIST, + MediaStore.Audio.Media.DURATION, + MediaStore.Audio.Playlists.Members.PLAY_ORDER, + MediaStore.Audio.Playlists.Members.AUDIO_ID, + MediaStore.Audio.Media.IS_MUSIC + }; try { - String[] cols = new String[] { - MediaStore.Audio.Playlists._ID, - MediaStore.Audio.Playlists.NAME - }; - + Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", + folderUid); StringBuilder where = new StringBuilder(); - where.append(MediaStore.Audio.Playlists.NAME + " != ''"); - - cursor = mContext.getContentResolver().query( - MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, - cols, MediaStore.Audio.Playlists._ID + "=" + folderUid, - null, null); - - if ((cursor == null) || (cursor.getCount() == 0)) { - status = DOES_NOT_EXIST; - } else{ - numberOfItems = cursor.getCount(); + where.append(MediaStore.Audio.Media.TITLE + " != ''"); + cursor = mContext.getContentResolver().query(uri, playlistMemberCols, + where.toString(), null, + MediaStore.Audio.Playlists.Members.DEFAULT_SORT_ORDER); + if (cursor != null) { + numberOfItems = cursor.getCount(); deviceFeatures[deviceIndex].mCurrentPathUid = String.valueOf(folderUid); deviceFeatures[deviceIndex].mCurrentPath = PATH_PLAYLISTS; + } else { + status = DOES_NOT_EXIST; } } catch (Exception e) { Log.e(TAG, "Exception " + e); -- cgit v1.2.3 From 8c0e151c347df879de8184cce4cc8d0a59a7aa1e Mon Sep 17 00:00:00 2001 From: Gaurav Asati Date: Thu, 5 Nov 2015 15:08:12 +0530 Subject: Bluetooth: Set SCO volume to 0. - add property based SCO volume change to 0 notification - PTS certification requires SCO volume with value 0 which is not supported by android. - unify system property name for PTS certification - set property to true to check for PTS certification Change-Id: I3b05ed9289d126529e662773988eb28550f18659 --- .../android/bluetooth/hfp/HeadsetStateMachine.java | 21 ++++++++++++++++++--- src/com/android/bluetooth/sap/SapServer.java | 5 ++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java index 42e09e9de..9b533c5fc 100644 --- a/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +++ b/src/com/android/bluetooth/hfp/HeadsetStateMachine.java @@ -59,6 +59,7 @@ import android.os.Message; import android.os.ParcelUuid; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemProperties; import android.os.PowerManager; import android.os.UserHandle; import android.os.PowerManager.WakeLock; @@ -1753,8 +1754,15 @@ final class HeadsetStateMachine extends StateMachine { int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); if (mPhoneState.getSpeakerVolume() != volumeValue) { mPhoneState.setSpeakerVolume(volumeValue); - setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, + boolean scoVolume = + SystemProperties.getBoolean("bt.pts.certification", false); + if (!scoVolume) { + setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, volumeValue, getByteAddress(device)); + } else { + setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, + 0, getByteAddress(device)); + } } } @@ -2310,8 +2318,15 @@ final class HeadsetStateMachine extends StateMachine { int volumeValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); if (mPhoneState.getSpeakerVolume() != volumeValue) { mPhoneState.setSpeakerVolume(volumeValue); - setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, - volumeValue, getByteAddress(device)); + boolean scoVolume = + SystemProperties.getBoolean("bt.pts.certification", false); + if (!scoVolume) { + setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, + volumeValue, getByteAddress(device)); + } else { + setVolumeNative(HeadsetHalConstants.VOLUME_TYPE_SPK, + 0, getByteAddress(device)); + } } } } diff --git a/src/com/android/bluetooth/sap/SapServer.java b/src/com/android/bluetooth/sap/SapServer.java index a8f7dd0d2..a71db937e 100644 --- a/src/com/android/bluetooth/sap/SapServer.java +++ b/src/com/android/bluetooth/sap/SapServer.java @@ -217,9 +217,8 @@ public class SapServer extends Thread implements Callback { /* For PTS TC_SERVER_DCN_BV_03_I we need to expose the option to send immediate disconnect * without first sending a graceful disconnect. * To enable this option set - * bt.sap.pts="true" */ - String pts_enabled = SystemProperties.get("bt.sap.pts"); - Boolean pts_test = Boolean.parseBoolean(pts_enabled); + * bt.pts.certification="true" */ + Boolean pts_test = SystemProperties.getBoolean("bt.pts.certification", false); /* put notification up for the user to be able to disconnect from the client*/ Intent sapDisconnectIntent = new Intent(SapServer.SAP_DISCONNECT_ACTION); -- cgit v1.2.3 From 5756d9cfbbd03abbe19b0a085c2144534e06b767 Mon Sep 17 00:00:00 2001 From: Hemant Gupta Date: Tue, 19 May 2015 13:33:19 +0530 Subject: Multiuser: Check if valid user before starting service Check if valid user before starting profile service. Change-Id: Id23dafca80a36043d5fc1094f454c3483ebff507 CRs-Fixed: 933725 Bluetooth: Check Broadcast Action before starting service. Steps: 1. Install CTS verifier apk on both test unit. 2. Turn on NFC and Android beam. 3. Choose BYOD Managed Provisioning Test on both device. 4. Follow the onscreen instruction. 5. Go to Disable Nfc beam test and follow onscreen instruction. Failure: Beam did not complete on sender, test failed. Fix: Ignore if Broadcast action is not TRANSFER_COMPLETED_ACTION. Change-Id: I3af0716d8b55c4cd0b6b6839fa133e4299ab0999 CRs-Fixed: 939681 --- src/com/android/bluetooth/Utils.java | 4 ++++ src/com/android/bluetooth/map/BluetoothMapService.java | 6 ++++++ src/com/android/bluetooth/opp/BluetoothOppReceiver.java | 10 ++++++++++ src/com/android/bluetooth/pbap/BluetoothPbapService.java | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/src/com/android/bluetooth/Utils.java b/src/com/android/bluetooth/Utils.java index a16d3b9c4..73a5ad14a 100644 --- a/src/com/android/bluetooth/Utils.java +++ b/src/com/android/bluetooth/Utils.java @@ -204,15 +204,19 @@ final public class Utils { int callingUser = UserHandle.getCallingUserId(); int callingUid = Binder.getCallingUid(); long ident = Binder.clearCallingIdentity(); + Log.d(TAG,"callingUid =" + callingUid); try { // With calling identity cleared the current user is the foreground user. int foregroundUser = ActivityManager.getCurrentUser(); ok = (foregroundUser == callingUser); + Log.e(TAG, "foregroundUser =" + foregroundUser); + Log.e(TAG, "callingUser =" + callingUser); if (!ok) { // Always allow SystemUI/System access. int systemUiUid = ActivityThread.getPackageManager().getPackageUid( "com.android.systemui", UserHandle.USER_OWNER); + Log.d(TAG," systemUiUid :" + systemUiUid); ok = (systemUiUid == callingUid) || (Process.SYSTEM_UID == callingUid); } } catch (Exception ex) { diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java index e130599cc..8cf69f601 100644 --- a/src/com/android/bluetooth/map/BluetoothMapService.java +++ b/src/com/android/bluetooth/map/BluetoothMapService.java @@ -573,6 +573,12 @@ public class BluetoothMapService extends ProfileService { if (DEBUG) Log.d(TAG, "start()"); if(!VERBOSE) VERBOSE = Log.isLoggable(LOG_TAG, Log.VERBOSE); + + if (!Utils.checkCaller()) { + Log.w(TAG, "start received for non-active user, ignoring"); + return false; + } + if (VERBOSE) Log.v(TAG, "verbose logging is enabled"); IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY); diff --git a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java index 6efa65023..074fd2a82 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppReceiver.java +++ b/src/com/android/bluetooth/opp/BluetoothOppReceiver.java @@ -48,6 +48,7 @@ import android.database.Cursor; import android.net.Uri; import android.util.Log; import android.widget.Toast; +import com.android.bluetooth.Utils; /** * Receives and handles: system broadcasts; Intents from other applications; @@ -63,6 +64,15 @@ public class BluetoothOppReceiver extends BroadcastReceiver { String action = intent.getAction(); + + /* Ignore if Broadcast action is not transfer complete and Invalid user */ + + if (!Utils.checkCaller() && !action.equals(BluetoothShare.TRANSFER_COMPLETED_ACTION)) { + Log.w(TAG, action + " Intent received for non-active user, ignoring!!"); + return; + } + + if (V) Log.v(TAG, action + " Intent received for active user"); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { if (BluetoothAdapter.STATE_ON == intent.getIntExtra( BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) { diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java index cbe750b2b..00121bd78 100644 --- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java @@ -200,6 +200,11 @@ public class BluetoothPbapService extends Service { mInterrupted = false; mAdapter = BluetoothAdapter.getDefaultAdapter(); + if (!Utils.checkCaller()) { + Log.w(TAG, "onCreate received for non-active user, ignoring"); + return; + } + if (!mHasStarted) { mHasStarted = true; if (VERBOSE) Log.v(TAG, "Starting PBAP service"); -- cgit v1.2.3 From 09ef17455f810bd85c51e3c5afe3a1802000e834 Mon Sep 17 00:00:00 2001 From: Sravan Kumar V Date: Mon, 16 Nov 2015 18:24:52 +0530 Subject: Bluetooth-OPP: Optimatize file transfer progress Transfer progress thread will starts during send/receive data to or from stack to optimize the transfer progress between the sender and receiver. CRs-Fixed: 718755 Change-Id: I79f1ae7d357a5b56d407c65ab356df276f7ef42a --- .../opp/BluetoothOppObexClientSession.java | 29 +++++++++----------- .../opp/BluetoothOppObexServerSession.java | 32 +++++++++------------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 18a2d99cd..180ef70ee 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -77,6 +77,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { private final int MIN_FILE_LEN_FOR_TPUT_MEASUREMENT = 500000; + private ContentResolverUpdateThread uiUpdateThread = null; + public BluetoothOppObexClientSession(Context context, ObexTransport transport) { if (transport == null) { throw new NullPointerException("transport is null"); @@ -123,7 +125,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } private class ContentResolverUpdateThread extends Thread { - private static final int sSleepTime = 500; private Uri contentUri; private Context mContext1; private long position; @@ -135,28 +136,27 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { position = pos; } - public void updateProgress (long pos) { - position = pos; - } @Override public void run() { - ContentValues updateValues; Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); - while (true) { - updateValues = new ContentValues(); + synchronized (BluetoothOppObexClientSession.this) { + if (uiUpdateThread != this) { + throw new IllegalStateException( + "multiple UpdateThreads in BluetoothOppObexClientSession"); + } + } + + ContentValues updateValues = new ContentValues(); updateValues.put(BluetoothShare.CURRENT_BYTES, position); mContext1.getContentResolver().update(contentUri, updateValues, null, null); + synchronized (BluetoothOppObexClientSession.this) { + uiUpdateThread = null; + - try { - Thread.sleep(sSleepTime); - } catch (InterruptedException e1) { - if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting"); - return; - } } } } @@ -383,7 +383,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { int status = BluetoothShare.STATUS_SUCCESS; Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId); ContentValues updateValues; - ContentResolverUpdateThread uiUpdateThread = null; HeaderSet reply = new HeaderSet(); HeaderSet request; request = new HeaderSet(); @@ -524,8 +523,6 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { uiUpdateThread = new ContentResolverUpdateThread (mContext1, contentUri, position); uiUpdateThread.start ( ); - } else { - uiUpdateThread.updateProgress (position); } } } diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index ce6ed5734..0278d99b2 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -109,6 +109,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen boolean mTransferInProgress = false; + private ContentResolverUpdateThread uiUpdateThread = null; + public BluetoothOppObexServerSession(Context context, ObexTransport transport) { mContext = context; mTransport = transport; @@ -169,7 +171,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private class ContentResolverUpdateThread extends Thread { - private static final int sSleepTime = 500; private Uri contentUri; private Context mContext1; private long position; @@ -181,32 +182,28 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen position = pos; } - public void updateProgress (long pos) { - position = pos; - } - @Override public void run() { - ContentValues updateValues; Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + synchronized (BluetoothOppObexServerSession.this) { + if (uiUpdateThread != this) { + throw new IllegalStateException( + "multiple UpdateThreads in BluetoothOppObexServerSession"); + } + } if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted()); /* Check if the Operation is interrupted before entering into loop */ - while ( !isInterrupted() ) { - updateValues = new ContentValues(); + ContentValues updateValues = new ContentValues(); updateValues.put(BluetoothShare.CURRENT_BYTES, position); mContext1.getContentResolver().update(contentUri, updateValues, null, null); + synchronized (BluetoothOppObexServerSession.this) { + uiUpdateThread = null; + } - try { - Thread.sleep(sSleepTime); - } catch (InterruptedException e1) { - if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1), exiting"); - return; - } - } - } + } } /* * Called when a ABORT request is received. @@ -504,7 +501,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen long beginTime = 0; int status = -1; BufferedOutputStream bos = null; - ContentResolverUpdateThread uiUpdateThread = null; InputStream is = null; boolean error = false; @@ -559,8 +555,6 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri, position); if (V) Log.v(TAG, "Worker for Updation : Created"); uiUpdateThread.start(); - } else { - uiUpdateThread.updateProgress (position); } } -- cgit v1.2.3 From 097d4de2653652769c5a304188e05875316af28c Mon Sep 17 00:00:00 2001 From: Sravan Kumar V Date: Tue, 17 Nov 2015 10:21:41 +0530 Subject: Bluetooth: Single Contentresolver thread will be started during transfer Single Contentresolver thread will be started to update UI progress during transfer. Otherwise, multiple instances will cause fatal exceptions and lead to application crash. CRs-Fixed: 734425 Change-Id: I4a25a6949c6db4a16663d69567d5aa4effc5c8b4 --- .../opp/BluetoothOppObexClientSession.java | 38 ++++++++-------- .../opp/BluetoothOppObexServerSession.java | 53 ++++++++++++---------- 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java index 180ef70ee..37aeeb1f0 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexClientSession.java @@ -77,7 +77,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { private final int MIN_FILE_LEN_FOR_TPUT_MEASUREMENT = 500000; - private ContentResolverUpdateThread uiUpdateThread = null; + private long position; public BluetoothOppObexClientSession(Context context, ObexTransport transport) { if (transport == null) { @@ -125,38 +125,37 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { } private class ContentResolverUpdateThread extends Thread { + private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; - private long position; - public ContentResolverUpdateThread(Context context, Uri cntUri, long pos) { + public ContentResolverUpdateThread(Context context, Uri cntUri) { super("BtOpp ContentResolverUpdateThread"); mContext1 = context; contentUri = cntUri; - position = pos; } @Override public void run() { - Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); - - synchronized (BluetoothOppObexClientSession.this) { - if (uiUpdateThread != this) { - throw new IllegalStateException( - "multiple UpdateThreads in BluetoothOppObexClientSession"); - } - } + ContentValues updateValues; - ContentValues updateValues = new ContentValues(); + Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); + if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted()); + /* Check if the Operation is interrupted before entering into loop */ + while (!isInterrupted()) { + updateValues = new ContentValues(); updateValues.put(BluetoothShare.CURRENT_BYTES, position); mContext1.getContentResolver().update(contentUri, updateValues, null, null); - synchronized (BluetoothOppObexClientSession.this) { - uiUpdateThread = null; - + try { + Thread.sleep(sSleepTime); + } catch (InterruptedException e1) { + if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted (1), exiting"); + return; + } } } } @@ -379,10 +378,11 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { private int sendFile(BluetoothOppSendFileInfo fileInfo) { boolean error = false; int responseCode = -1; - long position = 0; + position = 0; int status = BluetoothShare.STATUS_SUCCESS; Uri contentUri = Uri.parse(BluetoothShare.CONTENT_URI + "/" + mInfo.mId); ContentValues updateValues; + ContentResolverUpdateThread uiUpdateThread = null; HeaderSet reply = new HeaderSet(); HeaderSet request; request = new HeaderSet(); @@ -521,7 +521,8 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { if (uiUpdateThread == null) { uiUpdateThread = new ContentResolverUpdateThread (mContext1, - contentUri, position); + contentUri); + if (V) Log.v(TAG, "Worker for Updation : Created"); uiUpdateThread.start ( ); } } @@ -530,6 +531,7 @@ public class BluetoothOppObexClientSession implements BluetoothOppObexSession { if (uiUpdateThread != null) { try { + if (V) Log.v(TAG, "Worker for Updation : Destroying"); uiUpdateThread.interrupt (); uiUpdateThread.join (); uiUpdateThread = null; diff --git a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java index 0278d99b2..2f6a48440 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java +++ b/src/com/android/bluetooth/opp/BluetoothOppObexServerSession.java @@ -109,7 +109,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen boolean mTransferInProgress = false; - private ContentResolverUpdateThread uiUpdateThread = null; + private int position; public BluetoothOppObexServerSession(Context context, ObexTransport transport) { mContext = context; @@ -171,39 +171,44 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen private class ContentResolverUpdateThread extends Thread { + private static final int sSleepTime = 1000; private Uri contentUri; private Context mContext1; - private long position; - - public ContentResolverUpdateThread(Context context, Uri cntUri, long pos) { + private volatile boolean interrupted = false; + public ContentResolverUpdateThread(Context context, Uri cntUri) { super("BtOpp Server ContentResolverUpdateThread"); mContext1 = context; contentUri = cntUri; - position = pos; } @Override public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); - synchronized (BluetoothOppObexServerSession.this) { - if (uiUpdateThread != this) { - throw new IllegalStateException( - "multiple UpdateThreads in BluetoothOppObexServerSession"); - } - } + ContentValues updateValues; if (V) Log.v(TAG, "Is ContentResolverUpdateThread Interrupted :" + isInterrupted()); /* Check if the Operation is interrupted before entering into loop */ - - ContentValues updateValues = new ContentValues(); - updateValues.put(BluetoothShare.CURRENT_BYTES, position); - mContext1.getContentResolver().update(contentUri, updateValues, - null, null); - synchronized (BluetoothOppObexServerSession.this) { - uiUpdateThread = null; - } - - } + while ( !isInterrupted() ) { + updateValues = new ContentValues(); + updateValues.put(BluetoothShare.CURRENT_BYTES, position); + mContext1.getContentResolver().update(contentUri, updateValues, + null, null); + /* Check if the Operation is interrupted before entering sleep */ + if (isInterrupted()) { + if (V) Log.v(TAG, "ContentResolverUpdateThread was interrupted before sleep !,"+ + " exiting"); + return ; + } + + try { + Thread.sleep(sSleepTime); + } catch (InterruptedException e1) { + if (V) Log.v(TAG, "Server ContentResolverUpdateThread was interrupted (1),"+ + " exiting"); + return ; + } + } + } } /* * Called when a ABORT request is received. @@ -501,6 +506,8 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen long beginTime = 0; int status = -1; BufferedOutputStream bos = null; + ContentResolverUpdateThread uiUpdateThread = null; + InputStream is = null; boolean error = false; @@ -520,7 +527,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen mContext.getContentResolver().update(contentUri, updateValues, null, null); } - long position = 0; + position = 0; if (!error) { bos = new BufferedOutputStream(fileInfo.mOutputStream, 0x10000); } @@ -552,7 +559,7 @@ public class BluetoothOppObexServerSession extends ServerRequestHandler implemen } if (uiUpdateThread == null) { - uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri, position); + uiUpdateThread = new ContentResolverUpdateThread (mContext, contentUri); if (V) Log.v(TAG, "Worker for Updation : Created"); uiUpdateThread.start(); } -- cgit v1.2.3 From 69e9fc8a71d1c210c06097d45f31b17b6d28278e Mon Sep 17 00:00:00 2001 From: Srinu Jella Date: Tue, 1 Dec 2015 19:33:45 +0530 Subject: Bluetooth: Avoid calls on Null reference When Bluetooth is turned on/off very fast. By the time Server starts listening BT goes to off state and all references becomes NULL. Change-Id: Icb8a01aea29d32e48a67570d280eb80e55c0e8ba --- .../android/bluetooth/opp/BluetoothOppService.java | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/com/android/bluetooth/opp/BluetoothOppService.java b/src/com/android/bluetooth/opp/BluetoothOppService.java index 080b220b6..88b69f40e 100644 --- a/src/com/android/bluetooth/opp/BluetoothOppService.java +++ b/src/com/android/bluetooth/opp/BluetoothOppService.java @@ -355,12 +355,29 @@ public class BluetoothOppService extends Service { private void startSocketListener() { if (V) Log.v(TAG, "start Socket Listeners"); - mBtRfcServerSocket = mSocketListener.openRfcommSocket(); - mBtL2cServerSocket = mL2cSocketListener.openL2capSocket(); - mOppSdpHandle = SdpManager.getDefaultManager().createOppOpsRecord("OBEX Object Push", - mBtRfcServerSocket.getChannel(),mBtL2cServerSocket.getChannel(),0x0102,SdpManager.OPP_FORMAT_ALL); - mSocketListener.start(mHandler); - mL2cSocketListener.start(mHandler); + if (mSocketListener != null ) { + mBtRfcServerSocket = mSocketListener.openRfcommSocket(); + } + + if (mL2cSocketListener != null) { + mBtL2cServerSocket = mL2cSocketListener.openL2capSocket(); + } + + if (mBtRfcServerSocket != null && mBtL2cServerSocket != null) { + mOppSdpHandle = SdpManager.getDefaultManager().createOppOpsRecord("OBEX Object Push", + mBtRfcServerSocket.getChannel(), mBtL2cServerSocket.getChannel(), + 0x0102, SdpManager.OPP_FORMAT_ALL); + } else { + Log.e(TAG, "ERROR:serversocket object is NULL"); + } + + if (mSocketListener != null) { + mSocketListener.start(mHandler); + } + + if (mL2cSocketListener != null) { + mL2cSocketListener.start(mHandler); + } } -- cgit v1.2.3