Merge "Draw preference divider based on preference group."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d496046..44d4c19 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3123,6 +3123,19 @@
                        android:value="true" />
         </activity-alias>
 
+        <activity-alias android:name="SecurityDashboardAlias"
+                android:targetActivity="Settings$SecuritySettingsActivity">
+            <intent-filter android:priority="3">
+                <action android:name="com.android.settings.action.SETTINGS" />
+            </intent-filter>
+            <meta-data android:name="com.android.settings.category"
+                       android:value="com.android.settings.category.ia.homepage" />
+            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+                       android:value="com.android.settings.SecuritySettings" />
+            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+                       android:value="true" />
+        </activity-alias>
+
         <activity android:name=".Settings$SystemDashboardActivity"
                   android:label="@string/header_category_system"
                   android:icon="@drawable/ic_settings_about">
diff --git a/res/drawable-nodpi/gesture_ambient_lift b/res/drawable-nodpi/gesture_ambient_lift
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_ambient_lift
diff --git a/res/drawable-nodpi/gesture_ambient_tap b/res/drawable-nodpi/gesture_ambient_tap
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_ambient_tap
diff --git a/res/drawable-nodpi/gesture_double_tap b/res/drawable-nodpi/gesture_double_tap
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_double_tap
diff --git a/res/drawable-nodpi/gesture_fingerprint_swipe b/res/drawable-nodpi/gesture_fingerprint_swipe
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_fingerprint_swipe
diff --git a/res/drawable-nodpi/gesture_twist b/res/drawable-nodpi/gesture_twist
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/drawable-nodpi/gesture_twist
diff --git a/res/layout/gesture_preference.xml b/res/layout/gesture_preference.xml
index d5685ea..ccbc42a 100644
--- a/res/layout/gesture_preference.xml
+++ b/res/layout/gesture_preference.xml
@@ -74,6 +74,7 @@
                 android:id="@+id/gesture_image"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
+                android:scaleType="fitXY"
                 android:background="@color/gestures_setting_background_color"/>
 
             <ImageView
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 218d7f2..6df41d2 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -139,6 +139,7 @@
     <!-- For GesturePreference -->
     <declare-styleable name="GesturePreference">
         <attr name="animation" format="reference" />
+        <attr name="preview" format="reference" />
     </declare-styleable>
 
     <!-- For AspectRatioFrameLayout -->
diff --git a/res/xml/gesture_settings.xml b/res/xml/gesture_settings.xml
index af365bf..8954916 100644
--- a/res/xml/gesture_settings.xml
+++ b/res/xml/gesture_settings.xml
@@ -23,30 +23,35 @@
         android:key="gesture_swipe_down_fingerprint"
         android:title="@string/fingerprint_swipe_for_notifications_title"
         android:summary="@string/fingerprint_swipe_for_notifications_summary"
-        settings:animation="@raw/gesture_fingerprint_swipe"/>
+        settings:animation="@raw/gesture_fingerprint_swipe"
+        settings:preview="@drawable/gesture_fingerprint_swipe"/>
 
     <com.android.settings.gestures.GesturePreference
         android:key="gesture_double_tap_power"
         android:title="@string/double_tap_power_for_camera_title"
         android:summary="@string/double_tap_power_for_camera_summary"
-        settings:animation="@raw/gesture_double_tap"/>
+        settings:animation="@raw/gesture_double_tap"
+        settings:preview="@drawable/gesture_double_tap"/>
 
     <com.android.settings.gestures.GesturePreference
         android:key="gesture_double_twist"
         android:title="@string/double_twist_for_camera_mode_title"
         android:summary="@string/double_twist_for_camera_mode_summary"
-        settings:animation="@raw/gesture_twist"/>
+        settings:animation="@raw/gesture_twist"
+        settings:preview="@drawable/gesture_twist"/>
 
     <com.android.settings.gestures.GesturePreference
         android:key="gesture_double_tap_screen"
         android:title="@string/ambient_display_title"
         android:summary="@string/ambient_display_summary"
-        settings:animation="@raw/gesture_ambient_tap"/>
+        settings:animation="@raw/gesture_ambient_tap"
+        settings:preview="@drawable/gesture_ambient_tap"/>
 
     <com.android.settings.gestures.GesturePreference
         android:key="gesture_pick_up"
         android:title="@string/ambient_display_pickup_title"
         android:summary="@string/ambient_display_pickup_summary"
-        settings:animation="@raw/gesture_ambient_lift"/>
+        settings:animation="@raw/gesture_ambient_lift"
+        settings:preview="@drawable/gesture_ambient_lift"/>
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 7e013e4..07f6ebf 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -274,6 +274,7 @@
             Settings.NetworkDashboardActivity.class.getName(),
             "com.android.settings.Settings.BatteryDashboardAlias",
             "com.android.settings.Settings.DisplayDashboardAlias",
+            "com.android.settings.Settings.SecurityDashboardAlias",
             Settings.SystemDashboardActivity.class.getName(),
             Settings.SupportDashboardActivity.class.getName(),
             // Home page > Network & Internet
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index f2f4f77..b895974 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -242,10 +242,15 @@
             if (tile.icon != null) {
                 pref.setIcon(tile.icon.loadDrawable(context));
             }
-            if (tile.intent != null) {
+            final Bundle metadata = tile.metaData;
+            if (metadata != null) {
+                String clsName = metadata.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
+                if (!TextUtils.isEmpty(clsName)) {
+                    pref.setFragment(clsName);
+                }
+            } else if (tile.intent != null) {
                 final Intent intent = new Intent(tile.intent);
                 pref.setOnPreferenceClickListener(preference -> {
-                    intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
                     getActivity().startActivityForResult(intent, 0);
                     return true;
                 });
diff --git a/src/com/android/settings/datausage/CellDataPreference.java b/src/com/android/settings/datausage/CellDataPreference.java
index aa4001d..daf72f3 100644
--- a/src/com/android/settings/datausage/CellDataPreference.java
+++ b/src/com/android/settings/datausage/CellDataPreference.java
@@ -114,11 +114,10 @@
         final Context context = getContext();
         FeatureFactory.getFactory(context).getMetricsFeatureProvider()
                 .action(context, MetricsEvent.ACTION_CELL_DATA_TOGGLE, !mChecked);
+        final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
+                mSubId);
+        final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
         if (mChecked) {
-            final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
-                    mSubId);
-            final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
-
             // If the device is single SIM or is enabling data on the active data SIM then forgo
             // the pop-up.
             if (!Utils.showSimCardTile(getContext()) ||
@@ -139,6 +138,12 @@
             // If we are showing the Sim Card tile then we are a Multi-Sim device.
             if (Utils.showSimCardTile(getContext())) {
                 mMultiSimDialog = true;
+                if (nextSir != null && currentSir != null &&
+                        currentSir.getSubscriptionId() == nextSir.getSubscriptionId()) {
+                    setMobileDataEnabled(true);
+                    disableDataForOtherSubscriptions(mSubId);
+                    return;
+                }
                 super.performClick(view);
             } else {
                 setMobileDataEnabled(true);
diff --git a/src/com/android/settings/gestures/GesturePreference.java b/src/com/android/settings/gestures/GesturePreference.java
index 4536aa2..1909dcd 100644
--- a/src/com/android/settings/gestures/GesturePreference.java
+++ b/src/com/android/settings/gestures/GesturePreference.java
@@ -14,18 +14,12 @@
 
 package com.android.settings.gestures;
 
-import android.app.LoaderManager;
 import android.content.ContentResolver;
 import android.content.Context;
-import android.content.Loader;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.SurfaceTexture;
-import android.media.MediaMetadataRetriever;
 import android.media.MediaPlayer;
 import android.net.Uri;
-import android.os.Bundle;
 import android.support.v14.preference.SwitchPreference;
 import android.support.v7.preference.PreferenceViewHolder;
 import android.view.View;
@@ -36,15 +30,13 @@
 import android.util.Log;
 
 import com.android.settings.R;
-import com.android.settings.utils.AsyncLoader;
 
 /**
  * Preference item for a gesture with a switch to signify if it should be enabled.
  * This shows the title and description of the gesture along with an animation showing how to do
  * the gesture
  */
-public final class GesturePreference extends SwitchPreference implements
-        LoaderManager.LoaderCallbacks<Bitmap> {
+public final class GesturePreference extends SwitchPreference {
     private static final String TAG = "GesturePreference";
     private final Context mContext;
 
@@ -53,7 +45,7 @@
     private boolean mAnimationAvailable;
     private boolean mVideoReady;
     private boolean mScrolling;
-    private BitmapDrawable mPreviewImage;
+    private int mPreviewResource;
 
     public GesturePreference(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -71,6 +63,10 @@
             mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
             if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
                 setLayoutResource(R.layout.gesture_preference);
+
+                mPreviewResource = attributes.getResourceId(
+                        R.styleable.GesturePreference_preview, 0);
+
                 mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                     @Override
                     public void onSeekComplete(MediaPlayer mp) {
@@ -103,6 +99,7 @@
 
         final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video);
         final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image);
+        imageView.setImageResource(mPreviewResource);
         final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button);
 
         video.setOnClickListener(new View.OnClickListener() {
@@ -138,9 +135,6 @@
 
             @Override
             public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
-                if (mPreviewImage != null && imageView.getDrawable() == null) {
-                    imageView.setImageDrawable(mPreviewImage);
-                }
                 imageView.setVisibility(View.VISIBLE);
                 return false;
             }
@@ -159,10 +153,6 @@
             }
         });
 
-        if (mPreviewImage != null) {
-            imageView.setImageDrawable(mPreviewImage);
-        }
-
     }
 
     @Override
@@ -179,63 +169,10 @@
         mScrolling = scrolling;
     }
 
-    void loadPreview(LoaderManager manager, int id) {
-        if (mAnimationAvailable) {
-            Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this);
-        }
-    }
-
     void onViewVisible() {
         if (mVideoReady && mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
             mMediaPlayer.seekTo(0);
         }
     }
 
-    private static final class PreviewRetriever extends AsyncLoader<Bitmap> {
-        private Uri mVideoPath;
-
-        public PreviewRetriever(Context context, Uri videoPath) {
-            super(context);
-            mVideoPath = videoPath;
-        }
-
-        @Override
-        public Bitmap loadInBackground() {
-            MediaMetadataRetriever mediaMetadata = new MediaMetadataRetriever();
-            try {
-                mediaMetadata.setDataSource(getContext(), mVideoPath);
-                return mediaMetadata.getFrameAtTime(0);
-            } catch (Exception e) {
-                Log.w(TAG, "Unable to get animation preview.");
-            } finally {
-                mediaMetadata.release();
-            }
-            return null;
-        }
-
-        @Override
-        public void onDiscardResult(final Bitmap result) {
-            if (result != null && !result.isRecycled()) {
-                result.recycle();
-            }
-        }
-
-    }
-
-    @Override
-    public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
-        return new PreviewRetriever(mContext, mVideoPath);
-    }
-
-    @Override
-    public void onLoadFinished(final Loader<Bitmap> loader, final Bitmap bitmap) {
-        if (bitmap != null) {
-            mPreviewImage = new BitmapDrawable(mContext.getResources(), bitmap);
-        }
-    }
-
-    @Override
-    public void onLoaderReset(Loader<Bitmap> loader) {
-    }
-
 }
diff --git a/src/com/android/settings/gestures/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index 22cc496..ad9955c 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -56,11 +56,6 @@
     private static final String PREF_KEY_SWIPE_DOWN_FINGERPRINT = "gesture_swipe_down_fingerprint";
     private static final String PREF_KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
     private static final String DEBUG_DOZE_COMPONENT = "debug.doze.component";
-    private static final int PREF_ID_DOUBLE_TAP_POWER = 0;
-    private static final int PREF_ID_DOUBLE_TWIST = 1;
-    private static final int PREF_ID_PICK_UP = 2;
-    private static final int PREF_ID_SWIPE_DOWN_FINGERPRINT = 3;
-    private static final int PREF_ID_DOUBLE_TAP_SCREEN = 4;
 
     private List<GesturePreference> mPreferences;
 
@@ -75,7 +70,7 @@
         if (isCameraDoubleTapPowerGestureAvailable(getResources())) {
             int cameraDisabled = Secure.getInt(
                     getContentResolver(), Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
-            addPreference(PREF_KEY_DOUBLE_TAP_POWER, cameraDisabled == 0, PREF_ID_DOUBLE_TAP_POWER);
+            addPreference(PREF_KEY_DOUBLE_TAP_POWER, cameraDisabled == 0);
         } else {
             removePreference(PREF_KEY_DOUBLE_TAP_POWER);
         }
@@ -84,21 +79,20 @@
         boolean dozeEnabled = isDozeAvailable(context);
         if (dozeEnabled && isPickupAvailable(context)) {
             int pickup = Secure.getInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, 1);
-            addPreference(PREF_KEY_PICK_UP, pickup != 0, PREF_ID_PICK_UP);
+            addPreference(PREF_KEY_PICK_UP, pickup != 0);
         } else {
             removePreference(PREF_KEY_PICK_UP);
         }
         if (dozeEnabled && isDoubleTapAvailable(context)) {
             int doubleTap = Secure.getInt(getContentResolver(), Secure.DOZE_PULSE_ON_DOUBLE_TAP, 1);
-            addPreference(PREF_KEY_DOUBLE_TAP_SCREEN, doubleTap != 0, PREF_ID_DOUBLE_TAP_SCREEN);
+            addPreference(PREF_KEY_DOUBLE_TAP_SCREEN, doubleTap != 0);
         } else {
             removePreference(PREF_KEY_DOUBLE_TAP_SCREEN);
         }
 
         // Fingerprint slide for notifications
         if (isSystemUINavigationAvailable(context)) {
-            addPreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT, isSystemUINavigationEnabled(context),
-                    PREF_ID_SWIPE_DOWN_FINGERPRINT);
+            addPreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT, isSystemUINavigationEnabled(context));
         } else {
             removePreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
         }
@@ -107,7 +101,7 @@
         if (isDoubleTwistAvailable(context)) {
             int doubleTwistEnabled = Secure.getInt(
                     getContentResolver(), Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
-            addPreference(PREF_KEY_DOUBLE_TWIST, doubleTwistEnabled != 0, PREF_ID_DOUBLE_TWIST);
+            addPreference(PREF_KEY_DOUBLE_TWIST, doubleTwistEnabled != 0);
         } else {
             removePreference(PREF_KEY_DOUBLE_TWIST);
         }
@@ -234,11 +228,10 @@
                 R.bool.config_gesture_double_tap_settings_enabled);
     }
 
-    private void addPreference(String key, boolean enabled, int id) {
+    private void addPreference(String key, boolean enabled) {
         GesturePreference preference = (GesturePreference) findPreference(key);
         preference.setChecked(enabled);
         preference.setOnPreferenceChangeListener(this);
-        preference.loadPreview(getLoaderManager(), id);
         mPreferences.add(preference);
     }