Merge "Don't set FilteredNumberAsyncQueryHandler." into ub-contactsdialer-a-dev
diff --git a/res/drawable-hdpi/ic_block_24dp.png b/res/drawable-hdpi/ic_block_24dp.png
new file mode 100644
index 0000000..2ccc89d
--- /dev/null
+++ b/res/drawable-hdpi/ic_block_24dp.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_content_copy_24dp.png b/res/drawable-hdpi/ic_content_copy_24dp.png
new file mode 100644
index 0000000..70eb073
--- /dev/null
+++ b/res/drawable-hdpi/ic_content_copy_24dp.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_report_24dp.png b/res/drawable-hdpi/ic_report_24dp.png
new file mode 100644
index 0000000..dc0c995
--- /dev/null
+++ b/res/drawable-hdpi/ic_report_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_block_24dp.png b/res/drawable-mdpi/ic_block_24dp.png
new file mode 100644
index 0000000..ec1b33f
--- /dev/null
+++ b/res/drawable-mdpi/ic_block_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_content_copy_24dp.png b/res/drawable-mdpi/ic_content_copy_24dp.png
new file mode 100644
index 0000000..80c0695
--- /dev/null
+++ b/res/drawable-mdpi/ic_content_copy_24dp.png
Binary files differ
diff --git a/res/drawable-mdpi/ic_report_24dp.png b/res/drawable-mdpi/ic_report_24dp.png
new file mode 100644
index 0000000..70b82d6
--- /dev/null
+++ b/res/drawable-mdpi/ic_report_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_block_24dp.png b/res/drawable-xhdpi/ic_block_24dp.png
new file mode 100644
index 0000000..7aba97b
--- /dev/null
+++ b/res/drawable-xhdpi/ic_block_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_content_copy_24dp.png b/res/drawable-xhdpi/ic_content_copy_24dp.png
new file mode 100644
index 0000000..537fd4e
--- /dev/null
+++ b/res/drawable-xhdpi/ic_content_copy_24dp.png
Binary files differ
diff --git a/res/drawable-xhdpi/ic_report_24dp.png b/res/drawable-xhdpi/ic_report_24dp.png
new file mode 100644
index 0000000..18e7764
--- /dev/null
+++ b/res/drawable-xhdpi/ic_report_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_block_24dp.png b/res/drawable-xxhdpi/ic_block_24dp.png
new file mode 100644
index 0000000..fddfa54
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_block_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_content_copy_24dp.png b/res/drawable-xxhdpi/ic_content_copy_24dp.png
new file mode 100644
index 0000000..9dff893
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_content_copy_24dp.png
Binary files differ
diff --git a/res/drawable-xxhdpi/ic_report_24dp.png b/res/drawable-xxhdpi/ic_report_24dp.png
new file mode 100644
index 0000000..aed7668
--- /dev/null
+++ b/res/drawable-xxhdpi/ic_report_24dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_block_24dp.png b/res/drawable-xxxhdpi/ic_block_24dp.png
new file mode 100644
index 0000000..0378d1b
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_block_24dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_content_copy_24dp.png b/res/drawable-xxxhdpi/ic_content_copy_24dp.png
new file mode 100644
index 0000000..4ddee9e
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_content_copy_24dp.png
Binary files differ
diff --git a/res/drawable-xxxhdpi/ic_report_24dp.png b/res/drawable-xxxhdpi/ic_report_24dp.png
new file mode 100644
index 0000000..855e590
--- /dev/null
+++ b/res/drawable-xxxhdpi/ic_report_24dp.png
Binary files differ
diff --git a/res/layout/call_detail.xml b/res/layout/call_detail.xml
index 591ba5c..7d91248 100644
--- a/res/layout/call_detail.xml
+++ b/res/layout/call_detail.xml
@@ -13,91 +13,12 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/call_detail"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:layout_alignParentStart="true"
-    android:layout_alignParentTop="true"
     android:background="@color/background_dialer_call_log" >
 
-    <!-- Caller information "card" -->
-    <LinearLayout
-        android:id="@+id/caller_information"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:paddingStart="@dimen/call_detail_horizontal_margin"
-        android:paddingTop="@dimen/call_detail_top_margin"
-        android:paddingBottom="@dimen/call_detail_bottom_margin"
-        android:baselineAligned="false"
-        android:orientation="horizontal"
-        android:translationZ="@dimen/call_detail_translation_z"
-        android:focusable="true"
-        android:background="@color/background_dialer_white" >
-
-        <QuickContactBadge
-            android:id="@+id/quick_contact_photo"
-            android:layout_width="@dimen/contact_photo_size"
-            android:layout_height="@dimen/contact_photo_size"
-            android:layout_alignParentStart="true"
-            android:layout_gravity="top"
-            android:layout_marginTop="3dp"
-            android:focusable="true" />
-
-        <LinearLayout
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_weight="1"
-            android:orientation="vertical"
-            android:gravity="center_vertical"
-            android:layout_marginStart="@dimen/call_detail_horizontal_margin">
-
-            <TextView
-                android:id="@+id/caller_name"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textColor="?attr/call_log_primary_text_color"
-                android:textSize="@dimen/call_log_primary_text_size"
-                android:includeFontPadding="false"
-                android:layout_marginTop="2dp"
-                android:layout_marginBottom="3dp"
-                android:singleLine="true" />
-
-            <TextView
-                android:id="@+id/caller_number"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textColor="?attr/call_log_secondary_text_color"
-                android:textSize="@dimen/call_log_secondary_text_size"
-                android:layout_marginBottom="1dp"
-                android:singleLine="true" />
-
-            <TextView
-                android:id="@+id/phone_account_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:textColor="?attr/call_log_secondary_text_color"
-                android:textSize="@dimen/call_log_secondary_text_size"
-                android:singleLine="true"
-                android:visibility="gone" />
-
-        </LinearLayout>
-
-        <ImageView
-            android:id="@+id/call_back_button"
-            android:layout_width="@dimen/call_log_list_item_primary_action_dimen"
-            android:layout_height="@dimen/call_log_list_item_primary_action_dimen"
-            android:layout_marginEnd="16dp"
-            android:background="?android:attr/selectableItemBackgroundBorderless"
-            android:src="@drawable/ic_call_24dp"
-            android:scaleType="center"
-            android:tint="@color/call_log_list_item_primary_action_icon_tint"
-            android:contentDescription="@string/description_call_log_call_action"
-            android:visibility="gone" />
-
-    </LinearLayout>
-
     <!--
       The list view is under everything.
       It contains a first header element which is hidden under the controls UI.
@@ -108,4 +29,4 @@
         android:layout_width="match_parent"
         android:layout_height="fill_parent" />
 
-</LinearLayout>
+</FrameLayout>
diff --git a/res/layout/call_detail_header.xml b/res/layout/call_detail_header.xml
new file mode 100644
index 0000000..5931445
--- /dev/null
+++ b/res/layout/call_detail_header.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/caller_information"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:paddingStart="@dimen/call_detail_horizontal_margin"
+    android:paddingTop="@dimen/call_detail_top_margin"
+    android:paddingBottom="@dimen/call_detail_bottom_margin"
+    android:baselineAligned="false"
+    android:orientation="horizontal"
+    android:elevation="@dimen/call_detail_elevation"
+    android:focusable="true"
+    android:background="@color/background_dialer_white" >
+
+    <QuickContactBadge
+        android:id="@+id/quick_contact_photo"
+        android:layout_width="@dimen/contact_photo_size"
+        android:layout_height="@dimen/contact_photo_size"
+        android:layout_alignParentStart="true"
+        android:layout_gravity="top"
+        android:layout_marginTop="3dp"
+        android:focusable="true" />
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:orientation="vertical"
+        android:gravity="center_vertical"
+        android:layout_marginStart="@dimen/call_detail_horizontal_margin">
+
+        <TextView
+            android:id="@+id/caller_name"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textColor="?attr/call_log_primary_text_color"
+            android:textSize="@dimen/call_log_primary_text_size"
+            android:includeFontPadding="false"
+            android:layout_marginTop="2dp"
+            android:layout_marginBottom="3dp"
+            android:singleLine="true" />
+
+        <TextView
+            android:id="@+id/caller_number"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textColor="?attr/call_log_secondary_text_color"
+            android:textSize="@dimen/call_log_secondary_text_size"
+            android:layout_marginBottom="1dp"
+            android:singleLine="true" />
+
+        <TextView
+            android:id="@+id/phone_account_label"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:textColor="?attr/call_log_secondary_text_color"
+            android:textSize="@dimen/call_log_secondary_text_size"
+            android:singleLine="true"
+            android:visibility="gone" />
+
+    </LinearLayout>
+
+    <ImageView
+        android:id="@+id/call_back_button"
+        android:layout_width="@dimen/call_log_list_item_primary_action_dimen"
+        android:layout_height="@dimen/call_log_list_item_primary_action_dimen"
+        android:layout_marginEnd="16dp"
+        android:background="?android:attr/selectableItemBackgroundBorderless"
+        android:src="@drawable/ic_call_24dp"
+        android:scaleType="center"
+        android:tint="@color/call_log_list_item_primary_action_icon_tint"
+        android:contentDescription="@string/description_call_log_call_action"
+        android:visibility="gone" />
+
+</LinearLayout>
diff --git a/res/layout/call_details_voicemail_header.xml b/res/layout/call_details_voicemail_header.xml
deleted file mode 100644
index e3640fa..0000000
--- a/res/layout/call_details_voicemail_header.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="vertical" >
-
-        <LinearLayout
-            android:id="@+id/voicemail_container"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="vertical"
-            android:paddingBottom="@dimen/call_detail_button_spacing"
-            android:visibility="gone">
-            <!-- The voicemail fragment will be put here. -->
-        </LinearLayout>
-
-</LinearLayout>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index e80ee69..f0765ba 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -92,9 +92,10 @@
 
     <!-- Color for missed call icons. -->
     <color name="missed_call">#ff2e58</color>
-
     <!-- Color for answered or outgoing call icons. -->
     <color name="answered_call">@color/dialer_green_highlight_color</color>
+    <!-- Color for blocked call icons. -->
+    <color name="blocked_call">@color/dialtacts_secondary_text_color</color>
 
     <!-- Color for icons in the actionbar -->
     <color name="actionbar_icon_color">#ffffff</color>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d35a78d..093e80f 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -44,7 +44,7 @@
     <dimen name="call_detail_bottom_margin">16dp</dimen>
     <dimen name="call_detail_header_top_margin">20dp</dimen>
     <dimen name="call_detail_header_bottom_margin">9dp</dimen>
-    <dimen name="call_detail_translation_z">0.5dp</dimen>
+    <dimen name="call_detail_elevation">0.5dp</dimen>
     <dimen name="transcription_top_margin">18dp</dimen>
     <dimen name="transcription_bottom_margin">18dp</dimen>
 
@@ -154,4 +154,6 @@
     <dimen name="blocked_number_secondary_text_size">12sp</dimen>
     <dimen name="blocked_number_delete_icon_size">32dp</dimen>
     <dimen name="blocked_number_search_text_size">14sp</dimen>
+
+    <dimen name="call_type_icon_size">12dp</dimen>
 </resources>
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index c8a5356..12849f4 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -47,6 +47,7 @@
 import com.android.contacts.common.util.UriUtils;
 import com.android.dialer.calllog.CallDetailHistoryAdapter;
 import com.android.dialer.calllog.CallLogAsyncTaskUtil.CallLogAsyncTaskListener;
+import com.android.dialer.onboard.OnboardingActivity;
 import com.android.dialer.calllog.CallLogAsyncTaskUtil;
 import com.android.dialer.calllog.CallTypeHelper;
 import com.android.dialer.calllog.ContactInfoHelper;
@@ -220,6 +221,11 @@
     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
 
+        if (OnboardingActivity.shouldStartOnboardingActivity(this)) {
+            OnboardingActivity.startOnboardingActivity(this);
+            finish();
+        }
+
         mContext = this;
 
         setContentView(R.layout.call_detail);
@@ -231,6 +237,9 @@
 
         mVoicemailUri = getIntent().getParcelableExtra(EXTRA_VOICEMAIL_URI);
 
+        ListView historyList = (ListView) findViewById(R.id.history);
+        historyList.addHeaderView(mInflater.inflate(R.layout.call_detail_header, null));
+
         mQuickContactBadge = (QuickContactBadge) findViewById(R.id.quick_contact_photo);
         mQuickContactBadge.setOverlay(null);
         mQuickContactBadge.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 9978bbe..455b097 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -80,6 +80,7 @@
 import com.android.dialer.list.SearchFragment;
 import com.android.dialer.list.SmartDialSearchFragment;
 import com.android.dialer.list.SpeedDialFragment;
+import com.android.dialer.onboard.OnboardingActivity;
 import com.android.dialer.settings.DialerSettingsActivity;
 import com.android.dialer.util.IntentUtil;
 import com.android.dialer.util.TelecomUtil;
@@ -374,6 +375,11 @@
         Trace.beginSection(TAG + " onCreate");
         super.onCreate(savedInstanceState);
 
+        if (OnboardingActivity.shouldStartOnboardingActivity(this)) {
+            OnboardingActivity.startOnboardingActivity(this);
+            finish();
+        }
+
         mFirstLaunch = true;
 
         final Resources resources = getResources();
diff --git a/src/com/android/dialer/calllog/CallTypeIconsView.java b/src/com/android/dialer/calllog/CallTypeIconsView.java
index d680cfe..cfd8f97 100644
--- a/src/com/android/dialer/calllog/CallTypeIconsView.java
+++ b/src/com/android/dialer/calllog/CallTypeIconsView.java
@@ -114,6 +114,8 @@
                 return mResources.missed;
             case AppCompatConstants.CALLS_VOICEMAIL_TYPE:
                 return mResources.voicemail;
+            case AppCompatConstants.CALLS_BLOCKED_TYPE:
+                return mResources.blocked;
             default:
                 // It is possible for users to end up with calls with unknown call types in their
                 // call history, possibly due to 3rd party call log implementations (e.g. to
@@ -150,29 +152,22 @@
 
     private static class Resources {
 
-        /**
-         * Drawable representing an incoming answered call.
-         */
+        // Drawable representing an incoming answered call.
         public final Drawable incoming;
 
-        /**
-         * Drawable respresenting an outgoing call.
-         */
+        // Drawable respresenting an outgoing call.
         public final Drawable outgoing;
 
-        /**
-         * Drawable representing an incoming missed call.
-         */
+        // Drawable representing an incoming missed call.
         public final Drawable missed;
 
-        /**
-         * Drawable representing a voicemail.
-         */
+        // Drawable representing a voicemail.
         public final Drawable voicemail;
 
-        /**
-         * Drawable repesenting a video call.
-         */
+        // Drawable representing a blocked call.
+        public final Drawable blocked;
+
+        //  Drawable repesenting a video call.
         public final Drawable videoCall;
 
         /**
@@ -204,21 +199,26 @@
 
             voicemail = r.getDrawable(R.drawable.ic_call_voicemail_holo_dark);
 
-            // Get the video call icon, scaled to match the height of the call arrows.
-            // We want the video call icon to be the same height as the call arrows, while keeping
-            // the same width aspect ratio.
-            Bitmap videoIcon = BitmapFactory.decodeResource(context.getResources(),
-                    R.drawable.ic_videocam_24dp);
-            int scaledHeight = missed.getIntrinsicHeight();
-            int scaledWidth = (int) ((float) videoIcon.getWidth() *
-                    ((float) missed.getIntrinsicHeight() /
-                            (float) videoIcon.getHeight()));
-            Bitmap scaled = Bitmap.createScaledBitmap(videoIcon, scaledWidth, scaledHeight, false);
-            videoCall = new BitmapDrawable(context.getResources(), scaled);
+            blocked = getScaledBitmap(context, R.drawable.ic_block_24dp);
+            blocked.setColorFilter(r.getColor(R.color.blocked_call), PorterDuff.Mode.MULTIPLY);
+
+            videoCall = getScaledBitmap(context, R.drawable.ic_videocam_24dp);
             videoCall.setColorFilter(r.getColor(R.color.dialtacts_secondary_text_color),
                     PorterDuff.Mode.MULTIPLY);
 
             iconMargin = r.getDimensionPixelSize(R.dimen.call_log_icon_margin);
         }
+
+        // Gets the icon, scaled to the height of the call type icons. This helps display all the
+        // icons to be the same height, while preserving their width aspect ratio.
+        private Drawable getScaledBitmap(Context context, int resourceId) {
+            Bitmap icon = BitmapFactory.decodeResource(context.getResources(), resourceId);
+            int scaledHeight =
+                    context.getResources().getDimensionPixelSize(R.dimen.call_type_icon_size);
+            int scaledWidth = (int) ((float) icon.getWidth()
+                    * ((float) scaledHeight / (float) icon.getHeight()));
+            Bitmap scaledIcon = Bitmap.createScaledBitmap(icon, scaledWidth, scaledHeight, false);
+            return new BitmapDrawable(context.getResources(), scaledIcon);
+        }
     }
 }
diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
index 9da9cc1..c5d2f6f 100644
--- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
+++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
@@ -247,4 +247,4 @@
             }
         }, uri, null, null, null, null);
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
index ce2a0da..69039c8 100644
--- a/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
+++ b/src/com/android/dialer/filterednumber/FilterNumberDialogFragment.java
@@ -121,6 +121,12 @@
         return builder.create();
     }
 
+    @Override
+    public void onDestroy() {
+        this.dismissAllowingStateLoss();
+        super.onDestroy();
+    }
+
     private String getBlockedMessage(String displayNumber) {
         return getString(R.string.snackbar_number_blocked, displayNumber);
     }
diff --git a/src/com/android/dialer/onboard/OnboardingActivity.java b/src/com/android/dialer/onboard/OnboardingActivity.java
index 75378e9..144e6d4 100644
--- a/src/com/android/dialer/onboard/OnboardingActivity.java
+++ b/src/com/android/dialer/onboard/OnboardingActivity.java
@@ -19,9 +19,11 @@
 import static android.Manifest.permission.CALL_PHONE;
 import static android.Manifest.permission.READ_CONTACTS;
 
+import android.Manifest;
 import android.app.Activity;
 import android.app.Fragment;
 import android.app.FragmentTransaction;
+import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
@@ -45,6 +47,8 @@
         PermissionsChecker, OnboardingFragment.HostInterface {
     public static final String KEY_ALREADY_REQUESTED_DEFAULT_DIALER =
             "key_already_requested_default_dialer";
+    public static final String KEY_CALLING_ACTIVITY_INTENT =
+            "key_calling_activity_intent";
 
     public static final int SCREEN_DEFAULT_DIALER = 0;
     public static final int SCREEN_PERMISSIONS = 1;
@@ -95,6 +99,16 @@
     public void completeOnboardingFlow() {
         final Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
         editor.putBoolean(KEY_ALREADY_REQUESTED_DEFAULT_DIALER, true).apply();
+
+        // Once we have completed the onboarding flow, relaunch the activity that called us, so
+        // that we return the user to the intended activity.
+        if (getIntent() != null && getIntent().getExtras() != null) {
+            final Intent previousActivityIntent =
+                    getIntent().getExtras().getParcelable(KEY_CALLING_ACTIVITY_INTENT);
+            if (previousActivityIntent != null) {
+                startActivity(previousActivityIntent);
+            }
+        }
         finish();
     }
 
@@ -114,12 +128,61 @@
     }
 
     @Override
-    public boolean previouslyRequestedDefaultDialer() {
-        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+    public boolean hasAlreadyRequestedDefaultDialer() {
+        return getAlreadyRequestedDefaultDialerFromPreferences(this);
+    }
+
+    private static boolean getAlreadyRequestedDefaultDialerFromPreferences(Context context) {
+        final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
         return preferences.getBoolean(KEY_ALREADY_REQUESTED_DEFAULT_DIALER, false);
     }
 
     /**
+     * Checks the current permissions/application state to determine if the
+     * {@link OnboardingActivity} should be displayed. The onboarding flow should be launched if
+     * the current application is NOT the system dialer AND any of these criteria are true.
+     *
+     * 1) The phone application is not currently the default dialer AND we have not
+     * previously displayed a prompt to ask the user to set our app as the default dialer.
+     * 2) The phone application does not have the Phone permission.
+     * 3) The phone application does not have the Contacts permission.
+     *
+     * The exception if the current application is the system dialer applies because:
+     *
+     * 1) The system dialer must always provide immediate access to the dialpad to allow
+     * emergency calls to be made.
+     * 2) In order for the system dialer to require the onboarding flow, the user must have
+     * intentionally removed certain permissions/selected a different dialer. This assumes the
+     * that the user understands the implications of the actions previously taken. For example,
+     * removing the Phone permission from the system dialer displays a dialog that warns the
+     * user that this might break certain core phone functionality. Furthermore, various elements in
+     * the Dialer will prompt the user to grant permissions as needed.
+     *
+     * @param context A valid context object.
+     * @return {@code true} if the onboarding flow should be launched to request for the
+     *         necessary permissions or prompt the user to make us the default dialer, {@code false}
+     *         otherwise.
+     */
+    public static boolean shouldStartOnboardingActivity(Context context) {
+        // Since there is no official TelecomManager API to check for the system dialer,
+        // check to see if we have the system-only MODIFY_PHONE_STATE permission.
+        if (PermissionsUtil.hasPermission(context, Manifest.permission.MODIFY_PHONE_STATE)) {
+            return false;
+        }
+
+        return (!getAlreadyRequestedDefaultDialerFromPreferences(context)
+                && !TelecomUtil.isDefaultDialer(context))
+                        || !PermissionsUtil.hasPhonePermissions(context)
+                        || !PermissionsUtil.hasContactsPermissions(context);
+    }
+
+    public static void startOnboardingActivity(Activity callingActivity) {
+        final Intent intent = new Intent(callingActivity, OnboardingActivity.class);
+        intent.putExtra(KEY_CALLING_ACTIVITY_INTENT, callingActivity.getIntent());
+        callingActivity.startActivity(intent);
+    }
+
+    /**
      * Triggers the screen-specific logic that should occur when the next button is clicked.
      */
     @Override
@@ -180,7 +243,7 @@
 
         @Override
         public boolean shouldShowScreen() {
-            return !mPermissionsChecker.previouslyRequestedDefaultDialer()
+            return !mPermissionsChecker.hasAlreadyRequestedDefaultDialer()
                     && !mPermissionsChecker.isDefaultOrSystemDialer();
         }
 
diff --git a/src/com/android/dialer/onboard/PermissionsChecker.java b/src/com/android/dialer/onboard/PermissionsChecker.java
index 78d175e..c6b0bbf 100644
--- a/src/com/android/dialer/onboard/PermissionsChecker.java
+++ b/src/com/android/dialer/onboard/PermissionsChecker.java
@@ -23,5 +23,5 @@
     public boolean hasPhonePermissions();
     public boolean hasContactsPermissions();
     public boolean isDefaultOrSystemDialer();
-    public boolean previouslyRequestedDefaultDialer();
+    public boolean hasAlreadyRequestedDefaultDialer();
 }
diff --git a/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java b/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java
index f9724c1..26e513f 100644
--- a/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java
+++ b/tests/src/com/android/dialer/onboard/DefaultDialerOnboardScreenTest.java
@@ -36,17 +36,17 @@
     }
 
     public void testNeverRequestedForDefaultDialer_shouldShowScreen() {
-        when(mPermissionsChecker.previouslyRequestedDefaultDialer()).thenReturn(false);
+        when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(false);
         assertTrue(mScreen.shouldShowScreen());
     }
 
     public void testAlreadyAskedForDefaultDialer_shouldNotShowScreen() {
-        when(mPermissionsChecker.previouslyRequestedDefaultDialer()).thenReturn(true);
+        when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(true);
         assertFalse(mScreen.shouldShowScreen());
     }
 
     public void testAlreadySetAsDefaultDialer_shouldNotShowScreen() {
-        when(mPermissionsChecker.previouslyRequestedDefaultDialer()).thenReturn(false);
+        when(mPermissionsChecker.hasAlreadyRequestedDefaultDialer()).thenReturn(false);
         when(mPermissionsChecker.isDefaultOrSystemDialer()).thenReturn(true);
         assertFalse(mScreen.shouldShowScreen());
     }