summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-10-30 17:21:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-10-30 17:21:19 +0000
commit0288688bd275b96606ecc1c82c33dd37de139d3a (patch)
treee93fb2211413e5feede15d81c9aa5c19b2f84d0c /java
parent1823bbbedc2ff08d2121a5e7e0e624a8dc2b4935 (diff)
parentf87dbfbf35f996738cb3f5436b654f615b1c1b27 (diff)
Merge "Roll forward cl/172154863: Do not load every DialtactsActivity fragment on app open"
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/app/calllog/CallLogAdapter.java44
-rw-r--r--java/com/android/dialer/app/calllog/CallLogFragment.java8
-rw-r--r--java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java18
-rw-r--r--java/com/android/dialer/app/list/DialtactsPagerAdapter.java2
-rw-r--r--java/com/android/dialer/app/list/ListsFragment.java6
-rw-r--r--java/com/android/dialer/databasepopulator/VoicemailPopulator.java10
6 files changed, 54 insertions, 34 deletions
diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java
index 589029827..47ef32d42 100644
--- a/java/com/android/dialer/app/calllog/CallLogAdapter.java
+++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java
@@ -610,29 +610,31 @@ public class CallLogAdapter extends GroupingListAdapter
// Restoring multi selected entries
ArrayList<String> listOfSelectedItems =
savedInstanceState.getStringArrayList(KEY_ACTION_MODE);
- LogUtil.i(
- "CallLogAdapter.onRestoreInstanceState",
- "restored selectedItemsList:%d",
- listOfSelectedItems.size());
-
- if (!listOfSelectedItems.isEmpty()) {
- for (int i = 0; i < listOfSelectedItems.size(); i++) {
- String voicemailUri = listOfSelectedItems.get(i);
- int id = getVoicemailId(voicemailUri);
+ if (listOfSelectedItems != null) {
+ LogUtil.i(
+ "CallLogAdapter.onRestoreInstanceState",
+ "restored selectedItemsList:%d",
+ listOfSelectedItems.size());
+
+ if (!listOfSelectedItems.isEmpty()) {
+ for (int i = 0; i < listOfSelectedItems.size(); i++) {
+ String voicemailUri = listOfSelectedItems.get(i);
+ int id = getVoicemailId(voicemailUri);
+ LogUtil.i(
+ "CallLogAdapter.onRestoreInstanceState",
+ "restoring selected index %d, id=%d, uri=%s ",
+ i,
+ id,
+ voicemailUri);
+ selectedItems.put(id, voicemailUri);
+ }
+
LogUtil.i(
- "CallLogAdapter.onRestoreInstanceState",
- "restoring selected index %d, id=%d, uri=%s ",
- i,
- id,
- voicemailUri);
- selectedItems.put(id, voicemailUri);
+ "CallLogAdapter.onRestoreInstance",
+ "restored selectedItems %s",
+ selectedItems.toString());
+ updateActionBar();
}
-
- LogUtil.i(
- "CallLogAdapter.onRestoreInstance",
- "restored selectedItems %s",
- selectedItems.toString());
- updateActionBar();
}
}
}
diff --git a/java/com/android/dialer/app/calllog/CallLogFragment.java b/java/com/android/dialer/app/calllog/CallLogFragment.java
index 5cb0244c5..5e8da032b 100644
--- a/java/com/android/dialer/app/calllog/CallLogFragment.java
+++ b/java/com/android/dialer/app/calllog/CallLogFragment.java
@@ -450,7 +450,9 @@ public class CallLogFragment extends Fragment
@Override
public void onDestroy() {
LogUtil.enterBlock("CallLogFragment.onDestroy");
- mAdapter.changeCursor(null);
+ if (mAdapter != null) {
+ mAdapter.changeCursor(null);
+ }
getActivity().getContentResolver().unregisterContentObserver(mCallLogObserver);
getActivity().getContentResolver().unregisterContentObserver(mContactsObserver);
@@ -467,7 +469,9 @@ public class CallLogFragment extends Fragment
outState.putBoolean(KEY_HAS_READ_CALL_LOG_PERMISSION, mHasReadCallLogPermission);
outState.putBoolean(KEY_REFRESH_DATA_REQUIRED, mRefreshDataRequired);
outState.putBoolean(KEY_SELECT_ALL_MODE, selectAllMode);
- mAdapter.onSaveInstanceState(outState);
+ if (mAdapter != null) {
+ mAdapter.onSaveInstanceState(outState);
+ }
}
@Override
diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java b/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
index 96d917318..9d8b04036 100644
--- a/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
+++ b/java/com/android/dialer/app/calllog/VisualVoicemailCallLogFragment.java
@@ -128,19 +128,23 @@ public class VisualVoicemailCallLogFragment extends CallLogFragment {
@Override
public void onDestroy() {
- getActivity()
- .getContentResolver()
- .unregisterContentObserver(mVoicemailErrorManager.getContentObserver());
- mVoicemailPlaybackPresenter.onDestroy();
- mVoicemailErrorManager.onDestroy();
- getActivity().getContentResolver().unregisterContentObserver(mVoicemailStatusObserver);
+ if (isAdded()) {
+ getActivity()
+ .getContentResolver()
+ .unregisterContentObserver(mVoicemailErrorManager.getContentObserver());
+ mVoicemailPlaybackPresenter.onDestroy();
+ mVoicemailErrorManager.onDestroy();
+ getActivity().getContentResolver().unregisterContentObserver(mVoicemailStatusObserver);
+ }
super.onDestroy();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
- mVoicemailPlaybackPresenter.onSaveInstanceState(outState);
+ if (mVoicemailPlaybackPresenter != null) {
+ mVoicemailPlaybackPresenter.onSaveInstanceState(outState);
+ }
}
@Override
diff --git a/java/com/android/dialer/app/list/DialtactsPagerAdapter.java b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java
index 1fbf0f01a..484ab0b9e 100644
--- a/java/com/android/dialer/app/list/DialtactsPagerAdapter.java
+++ b/java/com/android/dialer/app/list/DialtactsPagerAdapter.java
@@ -65,7 +65,7 @@ public class DialtactsPagerAdapter extends FragmentPagerAdapter {
private ContactsFragment contactsFragment;
private CallLogFragment voicemailFragment;
- public boolean hasActiveVoicemailProvider;
+ private boolean hasActiveVoicemailProvider;
public DialtactsPagerAdapter(
Context context, FragmentManager fm, String[] tabTitles, boolean hasVoicemailProvider) {
diff --git a/java/com/android/dialer/app/list/ListsFragment.java b/java/com/android/dialer/app/list/ListsFragment.java
index 362997a5a..05c647aec 100644
--- a/java/com/android/dialer/app/list/ListsFragment.java
+++ b/java/com/android/dialer/app/list/ListsFragment.java
@@ -203,7 +203,11 @@ public class ListsFragment extends Fragment implements OnPageChangeListener, Lis
mPrefs.getBoolean(
VisualVoicemailEnabledChecker.PREF_KEY_HAS_ACTIVE_VOICEMAIL_PROVIDER, false));
mViewPager.setAdapter(mAdapter);
- mViewPager.setOffscreenPageLimit(DialtactsPagerAdapter.TAB_COUNT_WITH_VOICEMAIL - 1);
+
+ // This is deliberate. See cl/172018946 for the app startup implications of using 1 here
+ // versus loading more fragments upfront.
+ mViewPager.setOffscreenPageLimit(1);
+
mViewPager.addOnPageChangeListener(this);
showTab(DialtactsPagerAdapter.TAB_INDEX_SPEED_DIAL);
diff --git a/java/com/android/dialer/databasepopulator/VoicemailPopulator.java b/java/com/android/dialer/databasepopulator/VoicemailPopulator.java
index e99f7c7d4..9e0f45345 100644
--- a/java/com/android/dialer/databasepopulator/VoicemailPopulator.java
+++ b/java/com/android/dialer/databasepopulator/VoicemailPopulator.java
@@ -19,9 +19,12 @@ package com.android.dialer.databasepopulator;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
+import android.os.Build.VERSION;
+import android.os.Build.VERSION_CODES;
import android.provider.VoicemailContract.Status;
import android.provider.VoicemailContract.Voicemails;
import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
import android.telecom.PhoneAccountHandle;
import android.telephony.TelephonyManager;
@@ -98,13 +101,16 @@ public final class VoicemailPopulator {
.delete(Voicemails.buildSourceUri(context.getPackageName()), "", new String[] {});
}
- private static void enableVoicemail(@NonNull Context context) {
+ @VisibleForTesting
+ public static void enableVoicemail(@NonNull Context context) {
PhoneAccountHandle handle =
new PhoneAccountHandle(new ComponentName(context, VoicemailPopulator.class), ACCOUNT_ID);
ContentValues values = new ContentValues();
values.put(Status.SOURCE_PACKAGE, handle.getComponentName().getPackageName());
- values.put(Status.SOURCE_TYPE, TelephonyManager.VVM_TYPE_OMTP);
+ if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) {
+ values.put(Status.SOURCE_TYPE, TelephonyManager.VVM_TYPE_OMTP);
+ }
values.put(Status.PHONE_ACCOUNT_COMPONENT_NAME, handle.getComponentName().flattenToString());
values.put(Status.PHONE_ACCOUNT_ID, handle.getId());
values.put(Status.CONFIGURATION_STATE, Status.CONFIGURATION_STATE_OK);