am 2c10d3a7: (-s ours) am c52a78cb: am 5dba48f2: DO NOT MERGE Fix NPE during activity recreation

* commit '2c10d3a70ef31d8e8e143f031dc50a8fe071c718':
diff --git a/res/drawable/background_all_contacts.xml b/res/drawable/background_favorites_menu.xml
similarity index 86%
rename from res/drawable/background_all_contacts.xml
rename to res/drawable/background_favorites_menu.xml
index 0d3703f..60933fd 100644
--- a/res/drawable/background_all_contacts.xml
+++ b/res/drawable/background_favorites_menu.xml
@@ -18,12 +18,12 @@
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="false">
         <shape android:shape="rectangle" >
-            <solid android:color="@color/all_contacts_button_color" />
+            <solid android:color="@color/favorites_menu_background_color" />
         </shape>
     </item>
     <item android:state_pressed="true">
         <shape android:shape="rectangle" >
-            <solid android:color="@color/all_contacts_button_pressed_color" />
+            <solid android:color="@color/favorites_menu_pressed_color" />
         </shape>
     </item>
 </selector>
\ No newline at end of file
diff --git a/res/layout/dialtacts_activity.xml b/res/layout/dialtacts_activity.xml
index 0f80564..f708919 100644
--- a/res/layout/dialtacts_activity.xml
+++ b/res/layout/dialtacts_activity.xml
@@ -141,12 +141,6 @@
                     android:layout_alignParentRight="true"
                     />
             </RelativeLayout>
-            <Space
-                android:id="@+id/contact_tile_frame_spacer"
-                android:layout_height="wrap_content"
-                android:layout_width="match_parent"
-                android:layout_alignParentBottom="true"
-                android:visibility="gone"/>
         </LinearLayout>
     </FrameLayout>
 
diff --git a/res/layout/phone_favorites_fragment.xml b/res/layout/phone_favorites_fragment.xml
index d1ff3d7..23987a8 100644
--- a/res/layout/phone_favorites_fragment.xml
+++ b/res/layout/phone_favorites_fragment.xml
@@ -58,4 +58,5 @@
         android:layout_alignParentBottom="true"
         layout="@layout/phone_no_favorites"
         android:visibility="gone"/>
+
 </RelativeLayout>
diff --git a/res/layout/phone_favorites_menu.xml b/res/layout/phone_favorites_menu.xml
index 387ea5b..5f7a5a6 100644
--- a/res/layout/phone_favorites_menu.xml
+++ b/res/layout/phone_favorites_menu.xml
@@ -25,7 +25,8 @@
                 android:paddingRight="@dimen/favorites_menu_padding_horizontal"
                 android:paddingTop="@dimen/favorites_menu_padding_top"
                 android:paddingBottom="@dimen/favorites_menu_padding_bottom"
-                android:background="@color/favorites_menu_background_color"
+                android:background="@drawable/background_favorites_menu"
+                android:addStatesFromChildren="true"
         >
     <TextView
             android:layout_width="wrap_content"
@@ -38,7 +39,7 @@
             android:layout_centerVertical="true"
             android:gravity="center"
         />
-    <Button
+    <TextView
             android:id="@+id/all_contacts_button"
             android:fontFamily="@string/favorites_menu_all_contacts_font_family"
             android:layout_width="wrap_content"
@@ -47,10 +48,11 @@
             android:paddingRight="@dimen/favorites_menu_padding_horizontal"
             android:text="@string/favorites_menu_all_contacts"
             android:textSize="@dimen/favorites_menu_all_contacts_text_size"
-            android:background="@drawable/background_all_contacts"
+            android:background="@color/all_contacts_button_color"
             android:textColor="@color/all_contacts_button_text_color"
             android:layout_alignParentRight="true"
             android:layout_centerVertical="true"
             android:gravity="center"
+            android:focusable="true"
         />
 </RelativeLayout>
\ No newline at end of file
diff --git a/res/layout/phone_no_favorites.xml b/res/layout/phone_no_favorites.xml
index b95afd1..1a0079f 100644
--- a/res/layout/phone_no_favorites.xml
+++ b/res/layout/phone_no_favorites.xml
@@ -18,6 +18,7 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
+    android:orientation="vertical"
     android:minHeight="?android:attr/listPreferredItemHeight">
 
     <include
@@ -32,18 +33,23 @@
     <LinearLayout
         android:id="@+id/nofavorite_frame"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="match_parent"
         android:orientation="vertical"
+        android:layout_gravity="center"
         android:gravity="center"
-        android:layout_centerInParent="true">
+        android:layout_alignParentLeft="true"
+        android:layout_alignParentStart="true"
+        android:layout_alignParentTop="true"
+        android:layout_above="@id/show_all_contact_button_in_nofav">
+
         <ImageView
             android:id="@+id/nofavorite_image"
             android:layout_height="wrap_content"
             android:layout_width="match_parent"
             android:gravity="center_horizontal"
             android:src="@drawable/no_favorites_banner"
-            android:layout_marginBottom="14dp"
-            android:contentDescription="@string/no_favorites"/>
+            android:layout_marginBottom="14dp"/>
+
         <TextView
             android:id="@+id/title"
             android:layout_width="match_parent"
diff --git a/res/values/colors.xml b/res/values/colors.xml
index e9730ea..8712b25 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -57,12 +57,10 @@
     <!-- Background color of dialer list items (contacts, call log entries) -->
     <color name="background_dialer_list_items">#eeeeee</color>
 
-    <!-- Background color of action bars.  Ensure this stays in sync with packages/Telephony
-         actionbar_background_color. -->
+    <!-- Background color of action bars -->
     <color name="actionbar_background_color">#3B77E7</color>
 
-    <!-- Underline color of action bars.  Ensure this stays in sync with packages/Telephony
-         actionbar_underline. -->
+    <!-- Underline color of action bars -->
     <color name="actionbar_underline">#3265C1</color>
 
     <!-- Color of the 1dp divider that separates favorites -->
@@ -96,11 +94,11 @@
     <!-- Background color for the "All Contacts" button in the favorites menu. -->
     <color name="all_contacts_button_color">#999999</color>
 
-    <!-- Background color for the "All Contacts" button in the favorites menu when pressed. -->
-    <color name="all_contacts_button_pressed_color">#808080</color>
+    <!-- Background color for the favorites menu when pressed. -->
+    <color name="favorites_menu_pressed_color">#d6d6d6</color>
 
     <!-- Background color for the favorites menu. -->
-    <color name="favorites_menu_background_color">#eeeeee</color>
+    <color name="favorites_menu_background_color">#ebebeb</color>
 
     <!-- Text color for the "All Contacts" button above the favorite callers -->
     <color name="all_contacts_button_text_color">#ffffff</color>
@@ -132,7 +130,6 @@
     <!-- Color of the bottom border below the contacts grid on the main dialer screen. -->
     <color name="contacts_grid_bottom_border_color">#16000000</color>
 
-    <!-- Color of action bar text. Ensure this stays in sync with packages/Telephony
-         phone_settings_actionbar_text_color-->
+    <!-- Color of action bar text. -->
     <color name="actionbar_text_color">#FFFFFF</color>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 1025d0f..3921a5d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -86,7 +86,12 @@
     <!-- A "hidden" action bar style.  Used when loading the launcher activity so that the
          default actionbar is effectively hidden. -->
     <style name="DialtactsHiddenActionBarStyle" parent="DialtactsActionBarStyle">
-        <item name="android:height">0dp</item>
+        <item name="android:background">@color/background_dialer_light</item>
+        <item name="android:titleTextStyle">@style/DialtactsHiddenActionBarTextStyle</item>
+    </style>
+
+    <style name="DialtactsHiddenActionBarTextStyle" parent="@android:style/TextAppearance">
+        <item name="android:textColor">@color/background_dialer_light</item>
     </style>
 
     <!-- Action bar overflow menu icon. -->
@@ -107,9 +112,6 @@
         <item name="android:windowBackground">@color/background_dialer_list_items</item>
         <item name="android:gravity">top</item>
         <item name="android:listViewStyle">@style/ListViewStyle</item>
-        <item name="android:actionBarStyle">@style/DialtactsActionBarStyle</item>
-        <item name="android:actionOverflowButtonStyle">@style/DialtactsActionBarOverflow</item>
-        <item name="android:homeAsUpIndicator">@drawable/ic_back_arrow</item>
         <!-- CallLog -->
         <item name="call_log_primary_text_color">#333333</item>
         <item name="call_log_primary_background_color">#FFFFFF</item>
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index b78a7bc..1e99b23 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -154,9 +154,7 @@
     private PopupMenu mOverflowMenu;
     private PopupMenu mDialpadOverflowMenu;
 
-    // Padding view used to shift the fragment frame up when the dialpad is shown so that
-    // the contents of the fragment frame continue to exist in a layout of the same height
-    private View mFragmentsSpacer;
+    // Padding view used to shift the fragments up when the dialpad is shown.
     private View mFragmentsFrame;
 
     private boolean mInDialpadSearch;
@@ -317,26 +315,12 @@
         }
 
         mFragmentsFrame = findViewById(R.id.dialtacts_frame);
-        mFragmentsSpacer = findViewById(R.id.contact_tile_frame_spacer);
 
         mRemoveViewContainer = (RemoveView) findViewById(R.id.remove_view_container);
+
         mSearchAndRemoveViewContainer = findViewById(R.id.search_and_remove_view_container);
 
-        // When the first global layout pass is completed (and mSearchAndRemoveViewContainer has
-        // been assigned a valid height), assign that height to mFragmentsSpacer as well.
-        mSearchAndRemoveViewContainer.getViewTreeObserver().addOnGlobalLayoutListener(
-                new OnGlobalLayoutListener() {
-                    @Override
-                    public void onGlobalLayout() {
-                        mSearchAndRemoveViewContainer.getViewTreeObserver()
-                                .removeOnGlobalLayoutListener(this);
-                        mFragmentsSpacer.setLayoutParams(
-                                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
-                                        mSearchAndRemoveViewContainer.getHeight()));
-                    }
-                });
-
-
+        setupFakeActionBarItems();
         prepareSearchView();
 
         if (UI.FILTER_CONTACTS_ACTION.equals(intent.getAction())
@@ -353,7 +337,6 @@
     @Override
     protected void onResume() {
         super.onResume();
-        setupFakeActionBarItems();
         if (mFirstLaunch) {
             displayFragment(getIntent());
         } else if (!phoneIsInUse() && mInCallDialpadUp) {
@@ -552,6 +535,11 @@
         ft.commit();
         mDialButton.setVisibility(shouldShowOnscreenDialButton() ? View.VISIBLE : View.GONE);
         mDialpadButton.setVisibility(View.GONE);
+
+        if (mDialpadOverflowMenu == null) {
+            mDialpadOverflowMenu = mDialpadFragment.buildOptionsMenu(mMenuButton);
+        }
+
         mMenuButton.setOnTouchListener(mDialpadOverflowMenu.getDragToOpenListener());
     }
 
@@ -619,7 +607,6 @@
 
     public void hideSearchBar() {
         final int height = mSearchAndRemoveViewContainer.getHeight();
-
         mSearchAndRemoveViewContainer.animate().cancel();
         mSearchAndRemoveViewContainer.setAlpha(1);
         mSearchAndRemoveViewContainer.setTranslationY(0);
@@ -633,10 +620,6 @@
                     @Override
                     public void onAnimationEnd(Animator animation) {
                         mFragmentsFrame.setTranslationY(0);
-                        // Display the fragments spacer (which has the same height as the
-                        // search box) now that the search box is hidden, so that
-                        // mFragmentsFrame always retains the same height
-                        mFragmentsSpacer.setVisibility(View.VISIBLE);
                     }
                 });
 
@@ -666,9 +649,6 @@
                         new AnimatorListenerAdapter() {
                             @Override
                             public void onAnimationStart(Animator animation) {
-                                // Hide the fragment spacer now that the search box will
-                                // be displayed again
-                                mFragmentsSpacer.setVisibility(View.GONE);
                             }
                         });
     }
@@ -680,17 +660,12 @@
             if (mOverflowMenu == null) {
                 mOverflowMenu = buildOptionsMenu(mMenuButton);
             }
-            if (mDialpadOverflowMenu == null) {
-                mDialpadOverflowMenu = mDialpadFragment.buildOptionsMenu(mMenuButton);
-            }
-            // Initial state is with dialpad fragment not shown
             mMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
         }
 
         mFakeActionBar = findViewById(R.id.fake_action_bar);
 
         mCallHistoryButton = findViewById(R.id.call_history_button);
-        // mCallHistoryButton.setMinimumWidth(fakeMenuItemWidth);
         mCallHistoryButton.setOnClickListener(this);
 
         mDialButton = findViewById(R.id.dial_button);
@@ -698,7 +673,6 @@
         mDialButton.setOnLongClickListener(this);
 
         mDialpadButton = findViewById(R.id.dialpad_button);
-        // DialpadButton.setMinimumWidth(fakeMenuItemWidth);
         mDialpadButton.setOnClickListener(this);
     }
 
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index aee24ba..175a733 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -642,8 +642,11 @@
             contactType = ContactPhotoManager.TYPE_BUSINESS;
         }
 
-        String lookupKey = lookupUri == null ? null
-                : ContactInfoHelper.getLookupKeyFromUri(lookupUri);
+        String lookupKey = info.lookupKey;
+        if (lookupUri != null) {
+            //lookupKey = ContactInfoHelper.getLookupKeyFromUri(lookupUri);
+
+        }
 
         String nameForDefaultImage = null;
         if (TextUtils.isEmpty(name)) {
diff --git a/src/com/android/dialer/list/PhoneFavoriteFragment.java b/src/com/android/dialer/list/PhoneFavoriteFragment.java
index 0d33b4c..484a3d9 100644
--- a/src/com/android/dialer/list/PhoneFavoriteFragment.java
+++ b/src/com/android/dialer/list/PhoneFavoriteFragment.java
@@ -448,8 +448,7 @@
                     child instanceof ContactTileRow) {
                 // This is a tiled row, so save horizontal offsets instead
                 saveHorizontalOffsets((ContactTileRow) child, (ArrayList<ContactEntry>)
-                        mAdapter.getItem(position),
-                        mAdapter.getAdjustedPositionInContactTileAdapter(position));
+                        mAdapter.getItem(position), position);
             }
             if (DEBUG) {
                 Log.d(TAG, "Saving itemId: " + itemId + " for listview child " + i + " Top: "
@@ -508,6 +507,7 @@
                 int left = child.getLeft();
 
                 Integer startRow = mItemIdTopMap.get(itemId);
+
                 if (startRow != null) {
                     if (startRow > currentRow) {
                         // Item has shifted upwards to the previous row.
@@ -536,6 +536,10 @@
                         animators.add(ObjectAnimator.ofFloat(
                                 child, "translationX", delta, 0.0f));
                     }
+                } else {
+                    // In case the last square row is pushed up from the non-square section.
+                    animators.add(ObjectAnimator.ofFloat(
+                            child, "translationX", left, 0.0f));
                 }
             }
         }
@@ -577,7 +581,7 @@
                         // This is a tiled row, so perform horizontal animations instead
                         performHorizontalAnimations((ContactTileRow) child, (
                                 ArrayList<ContactEntry>) mAdapter.getItem(position), idsInPlace,
-                                mAdapter.getAdjustedPositionInContactTileAdapter(position));
+                                position);
                     }
 
                     final long itemId = mAdapter.getItemId(position);
@@ -607,6 +611,11 @@
                             }
                             startTop = top + (i > 0 ? itemHeight : -itemHeight);
                             delta = startTop - top;
+                        } else {
+                            // In case the first non-square row is pushed down
+                            // from the square section.
+                            animators.add(ObjectAnimator.ofFloat(
+                                    child, "alpha", 0.0f, 1.0f));
                         }
                         if (DEBUG) {
                             Log.d(TAG, "Found itemId: " + itemId + " for listview child " + i +
@@ -665,12 +674,12 @@
 
     /**
      * Prepares the favorites menu which contains the static label "Speed Dial" and the
-     * "All Contacts" button.  Sets the onClickListener for the "All Contacts" button.
+     * "All Contacts" button.  Taps anywhere in the view take the user to "All Contacts".
+     * This emulates how the headers in Play Store work.
      */
     private void prepareFavoritesMenu(View favoritesMenu) {
-        Button allContactsButton = (Button) favoritesMenu.findViewById(R.id.all_contacts_button);
-        // Set the onClick listener for the button to bring up the all contacts view.
-        allContactsButton.setOnClickListener(new OnClickListener() {
+        // Set the onClick listener for the view to bring up the all contacts view.
+        favoritesMenu.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View view) {
                 showAllContacts();
diff --git a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
index 6307613..d2288e4 100644
--- a/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
+++ b/src/com/android/dialer/list/PhoneFavoriteMergedAdapter.java
@@ -144,7 +144,7 @@
             }
         }
         // Set position to the position of the actual favorite contact in the favorites adapter
-        position = getAdjustedPositionInContactTileAdapter(position);
+        position = getAdjustedFavoritePosition(position, callLogAdapterCount);
 
         return mContactTileAdapter.getItem(position);
     }
@@ -176,7 +176,7 @@
         } else if (position < (callLogAdapterCount + mContactTileAdapter.getCount() +
                 getTeaserViewCount() + 1)) {
             return mContactTileAdapter.getItemId(
-                    getAdjustedPositionInContactTileAdapter(position));
+                    getAdjustedFavoritePosition(position, callLogAdapterCount));
         } else {
             // Default fallback.  We don't normally get here.
             return FAVORITES_MENU_ITEM_ID;
@@ -216,7 +216,7 @@
             return mContactTileAdapter.getViewTypeCount() + 3;
         } else if (position < getCount()) {
             return mContactTileAdapter.getItemViewType(
-                    getAdjustedPositionInContactTileAdapter(position));
+                    getAdjustedFavoritePosition(position, callLogAdapterCount));
         } else {
             // Catch-all - we shouldn't get here but if we do use the same as the favorites menu.
             return mContactTileAdapter.getViewTypeCount() + 3;
@@ -269,7 +269,7 @@
 
         // Set position to the position of the actual favorite contact in the favorites adapter.
         // Adjusts based on the presence of other views, such as the favorites menu.
-        position = getAdjustedPositionInContactTileAdapter(position);
+        position = getAdjustedFavoritePosition(position, callLogAdapterCount);
 
         // Favorites section
         final View view = mContactTileAdapter.getView(position, convertView, parent);
@@ -296,19 +296,18 @@
             return mCallLogAdapter.isEnabled(position);
         } else { // For favorites section
             return mContactTileAdapter.isEnabled(
-                    getAdjustedPositionInContactTileAdapter(position));
+                    getAdjustedFavoritePosition(position, callLogAdapterCount));
         }
     }
 
     /**
-     * Given the current position in the merged adapter, return the index in the
-     * mContactTileAdapter this position corresponds to.
+     * Determines the index into the mContactTileAdapter for the current position.
      *
-     * @param position current position in the overall (merged) adapter.
+     * @param position current position in the overall adapter.
+     * @param callLogAdapterCount number of entries in "last calls" list (ie 0 or 1).
      * @return position in the mContactTileAdapter.
      */
-    public int getAdjustedPositionInContactTileAdapter(int position) {
-        final int callLogAdapterCount = mCallLogAdapter.getCount();
+    private int getAdjustedFavoritePosition(int position, int callLogAdapterCount) {
         if (position - callLogAdapterCount > TILE_INTERACTION_TEASER_VIEW_POSITION &&
                 mTileInteractionTeaserView.getShouldDisplayInList()) {
             return position - callLogAdapterCount - 2;
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
index 826dec0..1dbae65 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackFragment.java
@@ -74,9 +74,7 @@
     };
 
     private VoicemailPlaybackPresenter mPresenter;
-    private static int mMediaPlayerRefCount = 0;
-    private static MediaPlayerProxy mMediaPlayerInstance;
-    private static ScheduledExecutorService mScheduledExecutorService;
+    private ScheduledExecutorService mScheduledExecutorService;
     private View mPlaybackLayout;
 
     @Override
@@ -89,6 +87,7 @@
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
+        mScheduledExecutorService = createScheduledExecutorService();
         Bundle arguments = getArguments();
         Preconditions.checkNotNull(arguments, "fragment must be started with arguments");
         Uri voicemailUri = arguments.getParcelable(EXTRA_VOICEMAIL_URI);
@@ -100,8 +99,8 @@
                 powerManager.newWakeLock(
                         PowerManager.SCREEN_DIM_WAKE_LOCK, getClass().getSimpleName());
         mPresenter = new VoicemailPlaybackPresenter(createPlaybackViewImpl(),
-                getMediaPlayerInstance(), voicemailUri,
-                getScheduledExecutorServiceInstance(), startPlayback,
+                createMediaPlayer(mScheduledExecutorService), voicemailUri,
+                mScheduledExecutorService, startPlayback,
                 AsyncTaskExecutors.createAsyncTaskExecutor(), wakeLock);
         mPresenter.onCreate(savedInstanceState);
     }
@@ -114,8 +113,8 @@
 
     @Override
     public void onDestroy() {
-        shutdownMediaPlayer();
         mPresenter.onDestroy();
+        mScheduledExecutorService.shutdown();
         super.onDestroy();
     }
 
@@ -130,36 +129,12 @@
                 mPlaybackLayout);
     }
 
-    private static synchronized MediaPlayerProxy getMediaPlayerInstance() {
-        ++mMediaPlayerRefCount;
-        if (mMediaPlayerInstance == null) {
-            mMediaPlayerInstance = VariableSpeed.createVariableSpeed(
-                    getScheduledExecutorServiceInstance());
-        }
-        return mMediaPlayerInstance;
+    private MediaPlayerProxy createMediaPlayer(ExecutorService executorService) {
+        return VariableSpeed.createVariableSpeed(executorService);
     }
 
-    private static synchronized ScheduledExecutorService getScheduledExecutorServiceInstance() {
-        if (mScheduledExecutorService == null) {
-            mScheduledExecutorService = Executors.newScheduledThreadPool(
-                    NUMBER_OF_THREADS_IN_POOL);
-        }
-        return mScheduledExecutorService;
-    }
-
-    private static synchronized void shutdownMediaPlayer() {
-        --mMediaPlayerRefCount;
-        if (mMediaPlayerRefCount > 0) {
-            return;
-        }
-        if (mScheduledExecutorService != null) {
-            mScheduledExecutorService.shutdown();
-            mScheduledExecutorService = null;
-        }
-        if (mMediaPlayerInstance != null) {
-            mMediaPlayerInstance.release();
-            mMediaPlayerInstance = null;
-        }
+    private ScheduledExecutorService createScheduledExecutorService() {
+        return Executors.newScheduledThreadPool(NUMBER_OF_THREADS_IN_POOL);
     }
 
     /**
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
index 085ef66..ebda0eb 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
@@ -35,7 +35,6 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
-import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
@@ -312,7 +311,6 @@
                             mPlayer.setDataSource(mView.getDataSourceContext(), mVoicemailUri);
                             mPlayer.setAudioStreamType(PLAYBACK_STREAM);
                             mPlayer.prepare();
-                            mDuration.set(mPlayer.getDuration());
                             return null;
                         } catch (Exception e) {
                             return e;
@@ -346,7 +344,7 @@
         mView.setSpeakerPhoneOn(mView.isSpeakerPhoneOn());
         mView.setRateDecreaseButtonListener(createRateDecreaseListener());
         mView.setRateIncreaseButtonListener(createRateIncreaseListener());
-        mView.setClipPosition(0, mDuration.get());
+        mView.setClipPosition(0, mPlayer.getDuration());
         mView.playbackStopped();
         // Always disable on stop.
         mView.disableProximitySensor();
@@ -365,10 +363,6 @@
     }
 
     public void onDestroy() {
-        if (mPrepareTask != null) {
-            mPrepareTask.cancel(false);
-            mPrepareTask = null;
-        }
         mPlayer.release();
         if (mFetchResultHandler != null) {
             mFetchResultHandler.destroy();
@@ -436,67 +430,49 @@
         }
     }
 
-    private class AsyncPrepareTask extends AsyncTask<Void, Void, Exception> {
-        private int mClipPositionInMillis;
-
-        AsyncPrepareTask(int clipPositionInMillis) {
-            mClipPositionInMillis = clipPositionInMillis;
-        }
-
-        @Override
-        public Exception doInBackground(Void... params) {
-            try {
-                if (!mPlayer.isReadyToPlay()) {
-                    mPlayer.reset();
-                    mPlayer.setDataSource(mView.getDataSourceContext(), mVoicemailUri);
-                    mPlayer.setAudioStreamType(PLAYBACK_STREAM);
-                    mPlayer.prepare();
-                }
-                return null;
-            } catch (Exception e) {
-                return e;
-            }
-        }
-
-        @Override
-        public void onPostExecute(Exception exception) {
-            mPrepareTask = null;
-            if (exception == null) {
-                final int duration = mPlayer.getDuration();
-                mDuration.set(duration);
-                int startPosition =
-                    constrain(mClipPositionInMillis, 0, duration);
-                mPlayer.seekTo(startPosition);
-                mView.setClipPosition(startPosition, duration);
-                try {
-                    // Can throw RejectedExecutionException
-                    mPlayer.start();
-                    mView.playbackStarted();
-                    if (!mWakeLock.isHeld()) {
-                        mWakeLock.acquire();
-                    }
-                    // Only enable if we are not currently using the speaker phone.
-                    if (!mView.isSpeakerPhoneOn()) {
-                        mView.enableProximitySensor();
-                    }
-                    // Can throw RejectedExecutionException
-                    mPositionUpdater.startUpdating(startPosition, duration);
-                } catch (RejectedExecutionException e) {
-                    handleError(e);
-                }
-            } else {
-                handleError(exception);
-            }
-        }
-    }
-
     private void resetPrepareStartPlaying(final int clipPositionInMillis) {
         if (mPrepareTask != null) {
             mPrepareTask.cancel(false);
-            mPrepareTask = null;
         }
         mPrepareTask = mAsyncTaskExecutor.submit(Tasks.RESET_PREPARE_START_MEDIA_PLAYER,
-                new AsyncPrepareTask(clipPositionInMillis));
+                new AsyncTask<Void, Void, Exception>() {
+                    @Override
+                    public Exception doInBackground(Void... params) {
+                        try {
+                            mPlayer.reset();
+                            mPlayer.setDataSource(mView.getDataSourceContext(), mVoicemailUri);
+                            mPlayer.setAudioStreamType(PLAYBACK_STREAM);
+                            mPlayer.prepare();
+                            return null;
+                        } catch (Exception e) {
+                            return e;
+                        }
+                    }
+
+                    @Override
+                    public void onPostExecute(Exception exception) {
+                        mPrepareTask = null;
+                        if (exception == null) {
+                            mDuration.set(mPlayer.getDuration());
+                            int startPosition =
+                                    constrain(clipPositionInMillis, 0, mDuration.get());
+                            mView.setClipPosition(startPosition, mDuration.get());
+                            mPlayer.seekTo(startPosition);
+                            mPlayer.start();
+                            mView.playbackStarted();
+                            if (!mWakeLock.isHeld()) {
+                                mWakeLock.acquire();
+                            }
+                            // Only enable if we are not currently using the speaker phone.
+                            if (!mView.isSpeakerPhoneOn()) {
+                                mView.enableProximitySensor();
+                            }
+                            mPositionUpdater.startUpdating(startPosition, mDuration.get());
+                        } else {
+                            handleError(exception);
+                        }
+                    }
+                });
     }
 
     private void handleError(Exception e) {
@@ -622,7 +598,6 @@
             synchronized (mLock) {
                 if (mScheduledFuture != null) {
                     mScheduledFuture.cancel(false);
-                    mScheduledFuture = null;
                 }
                 mScheduledFuture = mExecutorService.scheduleAtFixedRate(this, 0, mPeriodMillis,
                         TimeUnit.MILLISECONDS);
@@ -645,7 +620,6 @@
         }
         if (mPrepareTask != null) {
             mPrepareTask.cancel(false);
-            mPrepareTask = null;
         }
         if (mWakeLock.isHeld()) {
             mWakeLock.release();