summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRohit Yengisetty <rohit@cyngn.com>2016-05-10 16:53:52 -0700
committerRohit Yengisetty <rohit@cyngn.com>2016-05-10 16:56:30 -0700
commitc0b01a37a2fc190cc839f362680e6774d4414ed1 (patch)
treeab452e27077b01ce45e1c93c43e9915c92c502bd
parentb2d69a0ab47802c6161afa802625cecf8d68661d (diff)
downloadandroid_packages_apps_ContactsCommon-c0b01a37a2fc190cc839f362680e6774d4414ed1.tar.gz
android_packages_apps_ContactsCommon-c0b01a37a2fc190cc839f362680e6774d4414ed1.tar.bz2
android_packages_apps_ContactsCommon-c0b01a37a2fc190cc839f362680e6774d4414ed1.zip
Add additional synchronization around caller-info Provider state
LookupProviderImpl isn't thread while processing Provider updates and whilst inssuing lookup requests. Adding locks around these calls to ensure thread safety. Issue-Id: CYNGNOS-2593 Change-Id: I003d712a5f356123d16e1707825afd4fb1fdeb5e
-rw-r--r--info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java85
1 files changed, 46 insertions, 39 deletions
diff --git a/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java b/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java
index 908bff4f..7ccb8227 100644
--- a/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java
+++ b/info_lookup/src/com/cyanogen/lookup/phonenumber/provider/LookupProviderImpl.java
@@ -89,17 +89,20 @@ public class LookupProviderImpl implements LookupProvider {
new ProviderUpdateListener.Callback() {
@Override
public void onProviderChanged(ProviderInfo providerInfo) {
- boolean isProviderEnabled;
- if (providerInfo != null &&
- providerInfo.getStatus() == PluginStatus.ACTIVE) {
- mProviderInfo = providerInfo;
- isProviderEnabled = true;
- } else {
- isProviderEnabled = false;
- }
- // notify callbacks
- for (StatusCallback callback : mStatusChangeCallbacks) {
- callback.onStatusChanged(isProviderEnabled);
+ synchronized (mLock) {
+ boolean isProviderEnabled;
+ if (providerInfo != null &&
+ providerInfo.getStatus() == PluginStatus.ACTIVE) {
+ mProviderInfo = providerInfo;
+ isProviderEnabled = true;
+ } else {
+ mProviderInfo = null;
+ isProviderEnabled = false;
+ }
+ // notify callbacks
+ for (StatusCallback callback : mStatusChangeCallbacks) {
+ callback.onStatusChanged(isProviderEnabled);
+ }
}
}
});
@@ -121,7 +124,9 @@ public class LookupProviderImpl implements LookupProvider {
@Override
public boolean isEnabled() {
- return mProviderInfo != null;
+ synchronized (mLock) {
+ return mProviderInfo != null;
+ }
}
@Override
@@ -151,37 +156,39 @@ public class LookupProviderImpl implements LookupProvider {
private PendingResult<LookupByNumberResult> issueAmbientRequest(LookupRequest request) {
String number = request.mPhoneNumber;
- if (!TextUtils.isEmpty(number) && mAmbientClient != null &&
- (mAmbientClient.isConnecting() || mAmbientClient.isConnected())) {
+ synchronized (mLock) {
+ if (mProviderInfo != null && !TextUtils.isEmpty(number) && mAmbientClient != null &&
+ (mAmbientClient.isConnecting() || mAmbientClient.isConnected())) {
+
+ int originCode;
+ switch (request.mRequestOrigin) {
+ case INCOMING_CALL:
+ originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_INCOMING_CALL;
+ break;
+ case OUTGOING_CALL:
+ originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_OUTGOING_CALL;
+ break;
+ case INCOMING_SMS:
+ originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_INCOMING_SMS;
+ break;
+ case OUTGOING_SMS:
+ originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_OUTGOING_SMS;
+ break;
+ default:
+ originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_HISTORY;
+ break;
+ }
+ com.cyanogen.ambient.callerinfo.extension.LookupRequest ambientRequest =
+ new com.cyanogen.ambient.callerinfo.extension.LookupRequest(number,
+ com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_HISTORY);
+ PendingResult<LookupByNumberResult> result = CallerInfoServices.CallerInfoApi.
+ lookupByNumber(mAmbientClient, ambientRequest);
- int originCode;
- switch(request.mRequestOrigin) {
- case INCOMING_CALL:
- originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_INCOMING_CALL;
- break;
- case OUTGOING_CALL:
- originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_OUTGOING_CALL;
- break;
- case INCOMING_SMS:
- originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_INCOMING_SMS;
- break;
- case OUTGOING_SMS:
- originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_OUTGOING_SMS;
- break;
- default:
- originCode = com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_HISTORY;
- break;
+ return result;
}
- com.cyanogen.ambient.callerinfo.extension.LookupRequest ambientRequest =
- new com.cyanogen.ambient.callerinfo.extension.LookupRequest(number,
- com.cyanogen.ambient.callerinfo.extension.LookupRequest.ORIGIN_CODE_HISTORY);
- PendingResult<LookupByNumberResult> result = CallerInfoServices.CallerInfoApi.
- lookupByNumber(mAmbientClient, ambientRequest);
- return result;
+ return null;
}
-
- return null;
}
private LookupResponse createLookupResponse(