Merge "Revert "Revert "Convert BT preference to use TwoTargetPreference""" into oc-dev
diff --git a/res/layout/app_details.xml b/res/layout/app_details.xml
index 4aa1496..5ffeec5 100644
--- a/res/layout/app_details.xml
+++ b/res/layout/app_details.xml
@@ -26,17 +26,23 @@
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
     android:paddingTop="24dp"
-    android:paddingBottom="24dp" >
+    android:paddingBottom="24dp"
+    android:clipChildren="false"
+    android:clipToPadding="false">
 
     <!-- App snippet with buttons -->
     <RelativeLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:paddingStart="8dp">
+        android:paddingStart="8dp"
+        android:clipChildren="false"
+        android:clipToPadding="false">
 
         <FrameLayout android:id="@+id/app_icon_frame"
                      android:layout_width="80dp"
-                     android:layout_height="80dp">
+                     android:layout_height="80dp"
+                     android:clipChildren="false"
+                     android:clipToPadding="false">
             <ImageView
                 android:id="@+id/app_detail_icon"
                 android:layout_width="match_parent"
diff --git a/res/layout/preference_widget_summary.xml b/res/layout/preference_widget_summary.xml
index aa4c76b..2d7ed1d 100644
--- a/res/layout/preference_widget_summary.xml
+++ b/res/layout/preference_widget_summary.xml
@@ -18,5 +18,6 @@
     android:id="@+id/widget_summary"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:textAlignment="viewEnd"
     android:textAppearance="?android:attr/textAppearanceSmall"
     android:textColor="?android:attr/textColorSecondary" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 5efaf1e..09f7cda 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -240,6 +240,8 @@
     <dimen name="mdm_app_name_padding_left">16dp</dimen>
     <dimen name="mdm_app_icon_width_height">56dp</dimen>
 
+    <!-- Launcher Icons -->
+    <dimen name="launcher_icon_elevation">6dp</dimen>
     <dimen name="shortcut_size_maskable">120dp</dimen>
     <dimen name="shortcut_size">40dp</dimen>
     <dimen name="shortcut_icon_size">16dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fba0ef5..2b75bd9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8421,14 +8421,16 @@
     <string name="automatic_storage_manager_freed_bytes"><xliff:g id="size" example="3.25MB">%1$s</xliff:g> total made available\n\nLast ran on <xliff:g id="date" example="Jan 12">%2$s</xliff:g></string>
 
     <!-- Title text for enabling web actions. [CHAR_LIMIT=60] -->
-    <string name="web_action_enable_title">Open links in apps</string>
+    <string name="web_action_enable_title">Instant apps</string>
 
     <!-- Summary text for enabling web actions. [CHAR_LIMIT=250] -->
-    <string name="web_action_enable_summary">Open links in supported apps, even if the
-      apps aren’t installed on your device</string>
+    <string name="web_action_enable_summary">Open links in apps, even if they’re not installed</string>
 
     <!-- Section title for the Web Action preference [CHAR LIMIT=60] -->
-    <string name="web_action_section_title">Apps not installed</string>
+    <string name="web_action_section_title">Instant apps</string>
+
+    <!-- Preference label for an tappable preference that will open the account chooser for instant apps. [CHAR LIMIT=60] -->
+    <string name="instant_apps_account">Instant apps account</string>
 
     <!-- Section title for the Domain URL app preference list [CHAR LIMIT=60]-->
     <string name="domain_url_section_title">Installed apps</string>
diff --git a/src/com/android/settings/applications/AppHeaderController.java b/src/com/android/settings/applications/AppHeaderController.java
index b138ede..9e41679 100644
--- a/src/com/android/settings/applications/AppHeaderController.java
+++ b/src/com/android/settings/applications/AppHeaderController.java
@@ -24,6 +24,8 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.ResolveInfo;
 import android.content.res.Resources;
+import android.graphics.Outline;
+import android.graphics.drawable.AdaptiveIconDrawable;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.support.annotation.IntDef;
@@ -31,6 +33,7 @@
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.view.ViewOutlineProvider;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.TextView;
@@ -61,12 +64,23 @@
 
     public static final String PREF_KEY_APP_HEADER = "pref_app_header";
 
+    public static final ViewOutlineProvider OUTLINE_PROVIDER = new ViewOutlineProvider() {
+        @Override
+        public void getOutline(View view, Outline outline) {
+            Drawable background = ((ImageView)view).getDrawable();
+            if (background != null) {
+                background.getOutline(outline);
+            }
+        }
+    };
+
     private static final String TAG = "AppDetailFeature";
 
     private final Context mContext;
     private final Fragment mFragment;
     private final int mMetricsCategory;
     private final View mAppHeader;
+    private final int mIconElevation;
 
     private Drawable mIcon;
     private CharSequence mLabel;
@@ -93,6 +107,8 @@
             mAppHeader = LayoutInflater.from(fragment.getContext())
                     .inflate(R.layout.app_details, null /* root */);
         }
+        mIconElevation = mContext.getResources()
+            .getDimensionPixelSize(R.dimen.launcher_icon_elevation);
     }
 
     public AppHeaderController setIcon(Drawable icon) {
@@ -212,6 +228,13 @@
         ImageView iconView = (ImageView) mAppHeader.findViewById(R.id.app_detail_icon);
         if (iconView != null) {
             iconView.setImageDrawable(mIcon);
+            if (mIcon instanceof AdaptiveIconDrawable) {
+                iconView.setElevation(mIconElevation);
+                iconView.setOutlineProvider(OUTLINE_PROVIDER);
+            } else {
+                iconView.setElevation(0);
+                iconView.setOutlineProvider(null);
+            }
             ImageView badgeView = mAppHeader.findViewById(R.id.app_icon_instant_apps_badge);
             if (badgeView != null) {
                 badgeView.setVisibility(mIsInstantApp ? View.VISIBLE : View.GONE);
diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java
index 229e294..0c28461 100644
--- a/src/com/android/settings/applications/ManageApplications.java
+++ b/src/com/android/settings/applications/ManageApplications.java
@@ -23,6 +23,7 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageItemInfo;
 import android.content.pm.PackageManager;
+import android.graphics.drawable.AdaptiveIconDrawable;
 import android.icu.text.AlphabeticIndex;
 import android.os.Bundle;
 import android.os.Environment;
@@ -34,6 +35,7 @@
 import android.support.annotation.VisibleForTesting;
 import android.text.TextUtils;
 import android.util.ArraySet;
+import android.util.LauncherIcons;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -90,7 +92,6 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
@@ -812,6 +813,8 @@
         private final AppStateBaseBridge mExtraInfoBridge;
         private final Handler mBgHandler;
         private final Handler mFgHandler;
+        private final LauncherIcons mLauncherIcons;
+
         private int mFilterMode;
         private ArrayList<ApplicationsState.AppEntry> mBaseEntries;
         private ArrayList<ApplicationsState.AppEntry> mEntries;
@@ -866,6 +869,7 @@
             mContext = manageApplications.getActivity();
             mPm = mContext.getPackageManager();
             mFilterMode = filterMode;
+            mLauncherIcons = new LauncherIcons(mContext);
             if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
                 mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this,
                         manageApplications.mNotifBackend);
@@ -1300,6 +1304,9 @@
                     }
                     mState.ensureIcon(entry);
                     if (entry.icon != null) {
+                        if (entry.icon instanceof AdaptiveIconDrawable) {
+                            entry.icon = mLauncherIcons.wrapIconDrawableWithShadow(entry.icon);
+                        }
                         holder.appIcon.setImageDrawable(entry.icon);
                     }
                     updateSummary(holder);
diff --git a/src/com/android/settings/applications/ManageDomainUrls.java b/src/com/android/settings/applications/ManageDomainUrls.java
index b09a089..bdc9932 100644
--- a/src/com/android/settings/applications/ManageDomainUrls.java
+++ b/src/com/android/settings/applications/ManageDomainUrls.java
@@ -15,7 +15,9 @@
 package com.android.settings.applications;
 
 import android.app.Application;
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.Intent;
 import android.content.pm.PackageManager;
 import android.os.Bundle;
 import android.os.UserHandle;
@@ -55,6 +57,7 @@
     private ApplicationsState.Session mSession;
     private PreferenceGroup mDomainAppList;
     private SwitchPreference mWebAction;
+    private Preference mInstantAppAccountPreference;
 
     @Override
     public void onCreate(Bundle icicle) {
@@ -126,6 +129,26 @@
                 mWebAction.setOnPreferenceChangeListener(this);
                 webActionCategory.addPreference(mWebAction);
 
+                // Determine whether we should show the instant apps account chooser setting
+                ComponentName instantAppSettingsComponent = getActivity().getPackageManager()
+                        .getInstantAppResolverSettingsComponent();
+                Intent instantAppSettingsIntent = null;
+                if (instantAppSettingsComponent != null) {
+                    instantAppSettingsIntent =
+                            new Intent().setComponent(instantAppSettingsComponent);
+                }
+                if (instantAppSettingsIntent != null) {
+                    final Intent launchIntent = instantAppSettingsIntent;
+                    // TODO: Make this button actually launch the account chooser.
+                    mInstantAppAccountPreference = new Preference(getPrefContext());
+                    mInstantAppAccountPreference.setTitle(R.string.instant_apps_account);
+                    mInstantAppAccountPreference.setOnPreferenceClickListener(pref -> {
+                        startActivity(launchIntent);
+                        return true;
+                    });
+                    webActionCategory.addPreference(mInstantAppAccountPreference);
+                }
+
                 // list to manage link handling per app
                 mDomainAppList = new PreferenceCategory(getPrefContext());
                 mDomainAppList.setTitle(R.string.domain_url_section_title);
@@ -138,9 +161,11 @@
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mWebAction) {
-            final int enabled = (boolean) newValue ? 1 : 0;
+            boolean checked = (boolean) newValue;
             Settings.Secure.putInt(
-                    getContentResolver(), Settings.Secure.WEB_ACTION_ENABLED, enabled);
+                    getContentResolver(),
+                    Settings.Secure.WEB_ACTION_ENABLED, checked ? 1 : 0);
+            mWebAction.setChecked(checked);
             return true;
         }
         return false;
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index c38b89d..78b9b1e 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -269,11 +269,6 @@
             if (left.isDeleted() != right.isDeleted()) {
                 return Boolean.compare(left.isDeleted(), right.isDeleted());
             }
-            CharSequence leftName = left.getName();
-            CharSequence rightName = right.getName();
-            if (!Objects.equals(leftName, rightName)) {
-                return sCollator.compare(leftName.toString(), rightName.toString());
-            }
             return left.getId().compareTo(right.getId());
         }
     };
@@ -290,12 +285,6 @@
                     } else if (right.getId() == null && left.getId() != null) {
                         return -1;
                     }
-                    CharSequence leftName = left.getName();
-                    CharSequence rightName = right.getName();
-                    // sort rest of the groups by name
-                    if (!Objects.equals(leftName, rightName)) {
-                        return sCollator.compare(leftName.toString(), rightName.toString());
-                    }
                     return left.getId().compareTo(right.getId());
                 }
             };
diff --git a/tests/robotests/src/android/util/LauncherIcons.java b/tests/robotests/src/android/util/LauncherIcons.java
new file mode 100644
index 0000000..a18cfae
--- /dev/null
+++ b/tests/robotests/src/android/util/LauncherIcons.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+package android.util;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+
+/**
+ * This class is only needed to get around RoboElectric issue.
+ */
+public final class LauncherIcons {
+
+    public LauncherIcons(Context context) {
+    }
+
+    public Drawable wrapIconDrawableWithShadow(Drawable drawable) {
+        return drawable;
+    }
+}