Merge "Add a feature flag for controller loading enhancement"
diff --git a/res/layout/screen_pinning_instructions.xml b/res/layout/screen_pinning_instructions.xml
deleted file mode 100644
index fea5ed8..0000000
--- a/res/layout/screen_pinning_instructions.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-** Copyright 2014, 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.
-*/
--->
-
-<ScrollView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/instructions_area"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <TextView
-        android:id="@+id/screen_pinning_description"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_alignParentTop="true"
-        android:paddingTop="@dimen/screen_pinning_textview_padding"
-        android:text="@string/screen_pinning_description"
-        android:textAppearance="@style/TextAppearance.Medium"
-        android:paddingStart="@dimen/screen_pinning_padding_start"
-        android:paddingEnd="@dimen/screen_pinning_padding_end"
-        />
-
-</ScrollView>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f97da1f..242b690 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -158,9 +158,6 @@
     <!-- CryptKeeper pattern size for tablet -->
     <dimen name="crypt_keeper_pattern_size">354dip</dimen>
 
-    <!-- Screen pinning textview paddings -->
-    <dimen name="screen_pinning_textview_padding">40dp</dimen>
-
     <!-- SIM Dialog Margin top -->
     <dimen name="sim_dialog_margin_top">8dip</dimen>
     <!-- SIM Dialog Margin bottom -->
@@ -329,10 +326,6 @@
     <dimen name="reset_master_clear_margin_start">32dp</dimen>
     <dimen name="reset_master_clear_margin_end">12dp</dimen>
 
-    <!-- Padding for screen pinning -->
-    <dimen name="screen_pinning_padding_start">64dp</dimen>
-    <dimen name="screen_pinning_padding_end">64dp</dimen>
-
     <!-- Padding for the reset screens -->
     <dimen name="reset_checkbox_padding_end">8dp</dimen>
     <dimen name="reset_checkbox_title_padding_top">12dp</dimen>
diff --git a/res/xml/screen_pinning_settings.xml b/res/xml/screen_pinning_settings.xml
index f27e4aa..7ff7f1d 100644
--- a/res/xml/screen_pinning_settings.xml
+++ b/res/xml/screen_pinning_settings.xml
@@ -16,6 +16,7 @@
 
 <PreferenceScreen
     xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:settings="http://schemas.android.com/apk/res-auto"
     android:key="screen_pinning_settings_screen"
     android:title="@string/screen_pinning_title">
 
@@ -23,4 +24,10 @@
         android:key="use_screen_lock"
         android:title="@string/screen_pinning_unlock_none" />
 
+    <com.android.settingslib.widget.FooterPreference
+        android:key="screen_pinning_settings_screen_footer"
+        android:title="@string/screen_pinning_description"
+        android:selectable="false"
+        settings:searchable="false" />
+
 </PreferenceScreen>
diff --git a/src/com/android/settings/media/MediaOutputSlice.java b/src/com/android/settings/media/MediaOutputSlice.java
index 8086c41..2b70caf 100644
--- a/src/com/android/settings/media/MediaOutputSlice.java
+++ b/src/com/android/settings/media/MediaOutputSlice.java
@@ -164,7 +164,7 @@
         intent.putExtra(MEDIA_DEVICE_ID, id);
         intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
         return PendingIntent.getBroadcast(context, requestCode /* requestCode */, intent,
-                PendingIntent.FLAG_CANCEL_CURRENT);
+                PendingIntent.FLAG_UPDATE_CURRENT);
     }
 
     @Override
diff --git a/src/com/android/settings/security/ScreenPinningSettings.java b/src/com/android/settings/security/ScreenPinningSettings.java
index 849db40..aa3e862 100644
--- a/src/com/android/settings/security/ScreenPinningSettings.java
+++ b/src/com/android/settings/security/ScreenPinningSettings.java
@@ -23,9 +23,6 @@
 import android.os.UserHandle;
 import android.provider.SearchIndexableResource;
 import android.provider.Settings;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
 import android.widget.Switch;
 
 import androidx.preference.Preference;
@@ -41,6 +38,7 @@
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.widget.SwitchBar;
 import com.android.settingslib.search.SearchIndexable;
+import com.android.settingslib.widget.FooterPreference;
 
 import java.util.Arrays;
 import java.util.List;
@@ -52,11 +50,13 @@
 public class ScreenPinningSettings extends SettingsPreferenceFragment
         implements SwitchBar.OnSwitchChangeListener {
 
-    private static final CharSequence KEY_USE_SCREEN_LOCK = "use_screen_lock";
+    private static final String KEY_USE_SCREEN_LOCK = "use_screen_lock";
+    private static final String KEY_FOOTER = "screen_pinning_settings_screen_footer";
     private static final int CHANGE_LOCK_METHOD_REQUEST = 43;
 
     private SwitchBar mSwitchBar;
     private SwitchPreference mUseScreenLock;
+    private FooterPreference mFooterPreference;
     private LockPatternUtils mLockPatternUtils;
 
     @Override
@@ -77,6 +77,13 @@
         mSwitchBar.addOnSwitchChangeListener(this);
         mSwitchBar.show();
         mSwitchBar.setChecked(isLockToAppEnabled(getActivity()));
+
+        addPreferencesFromResource(R.xml.screen_pinning_settings);
+
+        final PreferenceScreen root = getPreferenceScreen();
+        mUseScreenLock = root.findPreference(KEY_USE_SCREEN_LOCK);
+        mFooterPreference = root.findPreference(KEY_FOOTER);
+        updateDisplay();
     }
 
     @Override
@@ -85,16 +92,6 @@
     }
 
     @Override
-    public void onViewCreated(View view, Bundle savedInstanceState) {
-        super.onViewCreated(view, savedInstanceState);
-        ViewGroup parent = (ViewGroup) view.findViewById(android.R.id.list_container);
-        View emptyView = LayoutInflater.from(getContext())
-                .inflate(R.layout.screen_pinning_instructions, parent, false);
-        parent.addView(emptyView);
-        setEmptyView(emptyView);
-    }
-
-    @Override
     public void onDestroyView() {
         super.onDestroyView();
 
@@ -192,16 +189,10 @@
         updateDisplay();
     }
 
-    public void updateDisplay() {
-        PreferenceScreen root = getPreferenceScreen();
-        if (root != null) {
-            root.removeAll();
-        }
+    private void updateDisplay() {
         if (isLockToAppEnabled(getActivity())) {
-            addPreferencesFromResource(R.xml.screen_pinning_settings);
-            root = getPreferenceScreen();
-
-            mUseScreenLock = (SwitchPreference) root.findPreference(KEY_USE_SCREEN_LOCK);
+            mFooterPreference.setVisible(false);
+            mUseScreenLock.setVisible(true);
             mUseScreenLock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
                 @Override
                 public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -210,6 +201,9 @@
             });
             mUseScreenLock.setChecked(isScreenLockUsed());
             mUseScreenLock.setTitle(getCurrentSecurityTitle());
+        } else {
+            mFooterPreference.setVisible(true);
+            mUseScreenLock.setVisible(false);
         }
     }