summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshwini Munigala <AshwiniM@codeaurora.org>2016-01-18 17:48:39 +0530
committerGerrit - the friendly Code Review server <code-review@localhost>2016-01-23 10:57:29 -0800
commitb2d3d09bf1792f65e7e917ef13e76ded8b4c0d00 (patch)
treeb08dd8c2e84988343880c341a0269cc8e205c065
parent76da92505dfd30673fab642c8fec5a15225638c7 (diff)
downloadandroid_packages_apps_Bluetooth-b2d3d09bf1792f65e7e917ef13e76ded8b4c0d00.tar.gz
android_packages_apps_Bluetooth-b2d3d09bf1792f65e7e917ef13e76ded8b4c0d00.tar.bz2
android_packages_apps_Bluetooth-b2d3d09bf1792f65e7e917ef13e76ded8b4c0d00.zip
MAP: Add following conditional checks from MAPServer :
- Track registration and unregistration for BroadcastReceiver through a instancee flag to avoid illegalArg and null pointer execption. This useecase is hit when onStop() for MAPService is triggered without onStart() being triggered for shutdown process is invoked even before MAP profile is actually started. - Avoid running contentobserver for SMS/MMS instance on main thread looper to fix ANR reported while handling content changes for SMS and MMS listing. - For GETMessagesLisitng ensure blank subject string is set to include this mandatory feild and handle possible "null" value fetched from db. CRs-Fixed: 963374 Change-Id: I8a1d3524784ec3942b962992059a1678d3b74d1e
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapContent.java2
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapContentEmail.java2
-rw-r--r--src/com/android/bluetooth/map/BluetoothMapContentObserver.java3
-rwxr-xr-x[-rw-r--r--]src/com/android/bluetooth/map/BluetoothMapService.java59
4 files changed, 39 insertions, 27 deletions
diff --git a/src/com/android/bluetooth/map/BluetoothMapContent.java b/src/com/android/bluetooth/map/BluetoothMapContent.java
index 62c90a9bc..2d27c6b87 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContent.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContent.java
@@ -1242,6 +1242,8 @@ public class BluetoothMapContent {
}
if (subject != null && subject.length() > subLength) {
subject = subject.substring(0, subLength);
+ } else if (subject == null ) {
+ subject = "";
}
if (V) Log.d(TAG, "setSubject: " + subject);
e.setSubject(subject);
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentEmail.java b/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
index 32864f3cb..da0287e11 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContentEmail.java
@@ -688,6 +688,8 @@ public class BluetoothMapContentEmail extends BluetoothMapContent {
}
if (subject != null && subject.length() > subLength) {
subject = subject.substring(0, subLength);
+ } else if(subject == null ) {
+ subject = "";
}
if (V) Log.d(TAG, "setSubject: " + subject);
e.setSubject(subject);
diff --git a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
index ef8d14dbc..f39264eb2 100644
--- a/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
+++ b/src/com/android/bluetooth/map/BluetoothMapContentObserver.java
@@ -468,8 +468,7 @@ public class BluetoothMapContentObserver {
return smsType;
}
- private final ContentObserver mObserver = new ContentObserver(
- new Handler(Looper.getMainLooper())) {
+ private final ContentObserver mObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
onChange(selfChange, null);
diff --git a/src/com/android/bluetooth/map/BluetoothMapService.java b/src/com/android/bluetooth/map/BluetoothMapService.java
index 917fcc16f..743c1b924 100644..100755
--- a/src/com/android/bluetooth/map/BluetoothMapService.java
+++ b/src/com/android/bluetooth/map/BluetoothMapService.java
@@ -144,6 +144,7 @@ public class BluetoothMapService extends ProfileService {
private boolean mIsWaitingAuthorization = false;
private boolean mRemoveTimeoutMsg = false;
+ private boolean mRegisteredMapReceiver = false;
private int mPermission = BluetoothDevice.ACCESS_UNKNOWN;
private boolean mAccountChanged = false;
private boolean mSdpSearchInitiated = false;
@@ -194,7 +195,7 @@ public class BluetoothMapService extends ProfileService {
}
mRemoteDevice = null;
- if (VERBOSE) Log.v(TAG, "MAP Service closeService out");
+ if (DEBUG) Log.d(TAG, "MAP Service closeService out");
if(latch != null) {
latch.countDown();
}
@@ -232,7 +233,7 @@ public class BluetoothMapService extends ProfileService {
"StartingObexMapTransaction");
mWakeLock.setReferenceCounted(false);
mWakeLock.acquire();
- if (VERBOSE) Log.v(TAG, "startObexSessions(): Acquire Wake Lock");
+ if (DEBUG) Log.d(TAG, "startObexSessions(): Acquire Wake Lock");
}
if(mBluetoothMnsObexClient == null) {
@@ -265,7 +266,7 @@ public class BluetoothMapService extends ProfileService {
mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler
.obtainMessage(MSG_RELEASE_WAKE_LOCK), RELEASE_WAKE_LOCK_DELAY);
- if (VERBOSE) Log.v(TAG, "startObexServerSessions() success!");
+ if (DEBUG) Log.d(TAG, "startObexServerSessions() success!");
}
public Handler getHandler() {
@@ -329,7 +330,7 @@ public class BluetoothMapService extends ProfileService {
}
@Override
public void handleMessage(Message msg) {
- if (DEBUG) Log.v(TAG, "Handler(): got msg=" + msg.what);
+ if (DEBUG) Log.d(TAG, "Handler(): got msg=" + msg.what);
switch (msg.what) {
case UPDATE_MAS_INSTANCES:
@@ -612,12 +613,14 @@ public class BluetoothMapService extends ProfileService {
} catch (MalformedMimeTypeException e) {
Log.e(TAG, "Wrong mime type!!!", e);
}
-
- try {
- registerReceiver(mMapReceiver, filter);
- registerReceiver(mMapReceiver, filterMessageSent);
- } catch (Exception e) {
- Log.w(TAG,"Unable to register map receiver",e);
+ if (!mRegisteredMapReceiver) {
+ try {
+ registerReceiver(mMapReceiver, filter);
+ registerReceiver(mMapReceiver, filterMessageSent);
+ mRegisteredMapReceiver = true;
+ } catch (Exception e) {
+ Log.e(TAG,"Unable to register map receiver",e);
+ }
}
mAdapter = BluetoothAdapter.getDefaultAdapter();
mAppObserver = new BluetoothMapAppObserver(this, this);
@@ -785,11 +788,14 @@ public class BluetoothMapService extends ProfileService {
@Override
protected boolean stop() {
if (DEBUG) Log.d(TAG, "stop()");
- try {
- unregisterReceiver(mMapReceiver);
- mAppObserver.shutdown();
- } catch (Exception e) {
- Log.w(TAG,"Unable to unregister map receiver",e);
+ if (mRegisteredMapReceiver) {
+ try {
+ mRegisteredMapReceiver = false;
+ unregisterReceiver(mMapReceiver);
+ mAppObserver.shutdown();
+ } catch (Exception e) {
+ Log.e(TAG,"Unable to unregister map receiver",e);
+ }
}
CountDownLatch latch = new CountDownLatch(1);
sendShutdownMessage(latch);
@@ -810,7 +816,7 @@ public class BluetoothMapService extends ProfileService {
mSessionStatusHandler = null;
}
setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
- if (VERBOSE) Log.d(TAG, "stop() out");
+ if (DEBUG) Log.d(TAG, "stop() out");
return true;
}
@@ -954,19 +960,22 @@ public class BluetoothMapService extends ProfileService {
mIsWaitingAuthorization = false;
cancelUserTimeoutAlarm();
}
- mSessionStatusHandler.removeCallbacksAndMessages(null);
- // Request release of all resources
- Message msg = mSessionStatusHandler.obtainMessage(SHUTDOWN,latch);
- if( mSessionStatusHandler.sendMessage(msg) == false) {
+ if (mSessionStatusHandler != null) {
+ mSessionStatusHandler.removeCallbacksAndMessages(null);
+ // Request release of all resources
+ Message msg = mSessionStatusHandler.obtainMessage(SHUTDOWN,latch);
+ if( mSessionStatusHandler.sendMessage(msg) == false) {
/* most likely caused by shutdown being called from multiple sources - e.g.BT off
* signaled through intent and a service shutdown simultaneously.
* Intended behavior not documented, hence we need to be able to handle all cases. */
- Log.e(TAG, "mSessionStatusHandler.sendMessage() failed trigger latch locally");
- if(latch != null) {
- latch.countDown();
+ Log.e(TAG, "mSessionStatusHandler.sendMessage() failed trigger latch locally");
+ if(latch != null) {
+ latch.countDown();
+ }
+ } else {
+ if(DEBUG)
+ Log.e(TAG, "mSessionStatusHandler.sendMessage() dispatched shutdown message");
}
- } else {
- if(DEBUG) Log.e(TAG, "mSessionStatusHandler.sendMessage() dispatched shutdown message");
}
}