summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-08-17 17:38:03 -0700
committerEric Erfanian <erfanian@google.com>2017-08-30 15:45:48 +0000
commitd8a0585d28f966733e4d5f8f2fc4f3bdb3ad82b7 (patch)
tree49ec936a33ba8c1b04193b6b0b53cb5c75558f52 /java/com/android/dialer/app
parent638bd2def0782ee60647a30bf9fdf0d702957068 (diff)
Workaround bug where system clobbered StrictMode thread policy.
There is a bug (b/36951662) in many versions of the system where if you set the thread policy in Application.onCreate it could get clobbered. When this happened, strict mode violations could sometimes go unreported. This CL works around the problem by re-enabling our custom policy after onCreate by posting to the main thread. Additionally, it copies most of java/com/google/android/libraries/strictmode/StrictModeUtils.java into our codebase and uses it to better handle known violations. Finally, fixed or bypassed a few violations which were exposed by this change. Bug: 64690143,64772057 Test: observed that certain strict mode violations which were flaky before now consistently reproduce PiperOrigin-RevId: 165653027 Change-Id: If58966cfce251a22945f3aada6570b303c6af0ee
Diffstat (limited to 'java/com/android/dialer/app')
-rw-r--r--java/com/android/dialer/app/list/ListsFragment.java2
-rw-r--r--java/com/android/dialer/app/list/RegularSearchFragment.java46
2 files changed, 45 insertions, 3 deletions
diff --git a/java/com/android/dialer/app/list/ListsFragment.java b/java/com/android/dialer/app/list/ListsFragment.java
index dbb6c8b5c..86a3d2fbb 100644
--- a/java/com/android/dialer/app/list/ListsFragment.java
+++ b/java/com/android/dialer/app/list/ListsFragment.java
@@ -98,7 +98,7 @@ public class ListsFragment extends Fragment implements OnPageChangeListener, Lis
LogUtil.d("ListsFragment.onCreate", null);
Trace.beginSection(TAG + " onCreate");
super.onCreate(savedInstanceState);
- mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
+ mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
Trace.endSection();
}
diff --git a/java/com/android/dialer/app/list/RegularSearchFragment.java b/java/com/android/dialer/app/list/RegularSearchFragment.java
index 728948bfc..73120c547 100644
--- a/java/com/android/dialer/app/list/RegularSearchFragment.java
+++ b/java/com/android/dialer/app/list/RegularSearchFragment.java
@@ -18,7 +18,10 @@ package com.android.dialer.app.list;
import static android.Manifest.permission.READ_CONTACTS;
import android.app.Activity;
+import android.content.Context;
import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
import android.support.v13.app.FragmentCompat;
import android.view.LayoutInflater;
import android.view.ViewGroup;
@@ -27,7 +30,11 @@ import com.android.contacts.common.list.PinnedHeaderListView;
import com.android.dialer.app.R;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.concurrent.DialerExecutor;
+import com.android.dialer.common.concurrent.DialerExecutor.Worker;
+import com.android.dialer.common.concurrent.DialerExecutors;
import com.android.dialer.phonenumbercache.CachedNumberLookupService;
+import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedContactInfo;
import com.android.dialer.phonenumbercache.PhoneNumberCache;
import com.android.dialer.util.PermissionsUtil;
import com.android.dialer.widget.EmptyContentView;
@@ -43,6 +50,8 @@ public class RegularSearchFragment extends SearchFragment
private static final int SEARCH_DIRECTORY_RESULT_LIMIT = 5;
protected String mPermissionToRequest;
+ private DialerExecutor<CachedContactInfo> addContactTask;
+
public RegularSearchFragment() {
configureDirectorySearch();
}
@@ -53,6 +62,18 @@ public class RegularSearchFragment extends SearchFragment
}
@Override
+ public void onCreate(Bundle savedState) {
+ super.onCreate(savedState);
+
+ addContactTask =
+ DialerExecutors.createUiTaskBuilder(
+ getFragmentManager(),
+ "RegularSearchFragment.addContact",
+ new AddContactWorker(getContext().getApplicationContext()))
+ .build();
+ }
+
+ @Override
protected void onCreateView(LayoutInflater inflater, ViewGroup container) {
super.onCreateView(inflater, container);
((PinnedHeaderListView) getListView()).setScrollToSectionOnHeaderTouch(true);
@@ -73,8 +94,9 @@ public class RegularSearchFragment extends SearchFragment
PhoneNumberCache.get(getContext()).getCachedNumberLookupService();
if (cachedNumberLookupService != null) {
final RegularSearchListAdapter adapter = (RegularSearchListAdapter) getAdapter();
- cachedNumberLookupService.addContact(
- getContext(), adapter.getContactInfo(cachedNumberLookupService, position));
+ CachedContactInfo cachedContactInfo =
+ adapter.getContactInfo(cachedNumberLookupService, position);
+ addContactTask.executeSerial(cachedContactInfo);
}
}
@@ -152,4 +174,24 @@ public class RegularSearchFragment extends SearchFragment
boolean isNearbyPlacesSearchEnabled();
}
+
+ private static class AddContactWorker implements Worker<CachedContactInfo, Void> {
+
+ private final Context appContext;
+
+ private AddContactWorker(Context appContext) {
+ this.appContext = appContext;
+ }
+
+ @Nullable
+ @Override
+ public Void doInBackground(@Nullable CachedContactInfo contactInfo) throws Throwable {
+ CachedNumberLookupService cachedNumberLookupService =
+ PhoneNumberCache.get(appContext).getCachedNumberLookupService();
+ if (cachedNumberLookupService != null) {
+ cachedNumberLookupService.addContact(appContext, contactInfo);
+ }
+ return null;
+ }
+ }
}