Merge "Add storage manager settings activity." into nyc-mr1-dev
diff --git a/res/layout/gesture_preference.xml b/res/layout/gesture_preference.xml
index 883b94e..d5685ea 100644
--- a/res/layout/gesture_preference.xml
+++ b/res/layout/gesture_preference.xml
@@ -51,6 +51,7 @@
     </LinearLayout>
 
     <LinearLayout
+        android:id="@+id/gesture_animation_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@color/gestures_setting_background_color"
@@ -58,7 +59,6 @@
         android:orientation="horizontal">
 
         <com.android.settings.widget.AspectRatioFrameLayout
-            android:id="@+id/gesture_animation_frame"
             android:layout_width="0dp"
             android:layout_height="match_parent"
             android:layout_weight="1"
diff --git a/res/raw/gesture_ambient_lift.mp4 b/res/raw/gesture_ambient_lift.mp4
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/res/raw/gesture_ambient_lift.mp4
diff --git a/res/values/config.xml b/res/values/config.xml
index c8ea171..75d8697 100755
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -55,4 +55,7 @@
     <!-- When true enable gesture setting. -->
     <bool name="config_gesture_settings_enabled">false</bool>
 
+    <!-- If the Storage Manager settings are enabled. -->
+    <bool name="config_storage_manager_settings_enabled">false</bool>
+
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 0be96bd..514bf66 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2154,7 +2154,7 @@
     <!-- Night display screen, setting option name to enable night display (renamed "Night Light" with title caps). [CHAR LIMIT=30] -->
     <string name="night_display_title">Night Light</string>
     <!-- Night display screen, description of night display feature (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
-    <string name="night_display_text">Night Light tints your screen red. This makes it easier to look at your screen or read in dim light, and may help you fall asleep more easily.</string>
+    <string name="night_display_text">Night Light tints your screen amber. This makes it easier to look at your screen or read in dim light, and may help you fall asleep more easily.</string>
     <!-- Night display screen, category title for settings to schedule when night display activates automatically. [CHAR LIMIT=30] -->
     <string name="night_display_category_schedule">Schedule</string>
     <!-- Night display screen, category title for settings to manually activate night display. [CHAR LIMIT=30] -->
@@ -2229,7 +2229,7 @@
     <!-- [CHAR LIMIT=30] Display settings screen, setting option name to change whether the ambient display feature is enabled. -->
     <string name="doze_title">Ambient display</string>
     <!-- [CHAR LIMIT=NONE] Display settings screen, setting description for the ambient display feature. -->
-    <string name="doze_summary">Wake screen when you double-tap it or get new notifications. See how</string>
+    <string name="doze_summary">Wake screen when you receive notifications</string>
     <!-- [CHAR LIMIT=30] Sound & display settings screen, setting option name to change font size -->
     <string name="title_font_size">Font size</string>
     <!-- Summary for Font size. Lets the user know that this will make text larger or smaller. Appears in the accessibility portion of setup wizard. [CHAR LIMIT=NONE] -->
@@ -7306,7 +7306,7 @@
     <string name="condition_night_display_title">Night Light is on</string>
 
     <!-- Summary of condition that night display is on (renamed "Night Light" with title caps) [CHAR LIMIT=NONE] -->
-    <string name="condition_night_display_summary">Screen is tinted red. This may help you fall asleep.</string>
+    <string name="condition_night_display_summary">Screen is tinted amber. This may help you fall asleep.</string>
 
     <!-- Title for the suggestions section on the dashboard [CHAR LIMIT=30] -->
     <string name="suggestions_title">Suggestions</string>
@@ -7762,11 +7762,25 @@
     <!-- Summary text for double twist for camera mode  [CHAR LIMIT=160]-->
     <string name="double_twist_for_camera_mode_summary"></string>
 
-    <!-- Title text for ambient display [CHAR LIMIT=60]-->
-    <string name="ambient_display_title">Quick screen check</string>
+    <!-- Title text for ambient display double tap [CHAR LIMIT=60]-->
+    <string name="ambient_display_title">Quick screen check - Double Tap</string>
 
-    <!-- Summary text for ambient display [CHAR LIMIT=160]-->
-    <string name="ambient_display_summary">To check your phone without waking it up fully, double-tap it or pick it up</string>
+    <!-- Summary text for ambient display double tap (phone) [CHAR LIMIT=160]-->
+    <string name="ambient_display_summary" product="default">To check your phone without waking it up fully, double-tap it</string>
+    <!-- Summary text for ambient display double tap (tablet) [CHAR LIMIT=160]-->
+    <string name="ambient_display_summary" product="tablet">To check your tablet without waking it up fully, double-tap it</string>
+    <!-- Summary text for ambient display double tap (device) [CHAR LIMIT=160]-->
+    <string name="ambient_display_summary" product="device">To check your device without waking it up fully, double-tap it</string>
+
+    <!-- Title text for ambient display pick up [CHAR LIMIT=60]-->
+    <string name="ambient_display_pickup_title">Quick screen check - Pickup notifications</string>
+
+    <!-- Summary text for ambient display (phone) [CHAR LIMIT=160]-->
+    <string name="ambient_display_pickup_summary" product="default">To check your phone without waking it up fully, pick it up</string>
+    <!-- Summary text for ambient display (tablet) [CHAR LIMIT=160]-->
+    <string name="ambient_display_pickup_summary" product="tablet">To check your tablet without waking it up fully, pick it up</string>
+    <!-- Summary text for ambient display (device) [CHAR LIMIT=160]-->
+    <string name="ambient_display_pickup_summary" product="device">To check your device without waking it up fully, pick it up</string>
 
     <!-- Title text for fingerprint swipe for notifications [CHAR LIMIT=60]-->
     <string name="fingerprint_swipe_for_notifications_title">Swipe for notifications</string>
diff --git a/res/xml/device_info_settings.xml b/res/xml/device_info_settings.xml
index b8fee49..66cf8f4 100644
--- a/res/xml/device_info_settings.xml
+++ b/res/xml/device_info_settings.xml
@@ -15,6 +15,7 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:settings="http://schemas.android.com/apk/res-auto"
         android:title="@string/about_settings">
 
         <!-- System update settings - launches activity -->
@@ -70,11 +71,15 @@
         </PreferenceScreen>
 
         <!-- Device hardware model -->
-        <Preference android:key="device_model"
+        <com.android.settings.DividerPreference
+                android:key="device_model"
                 android:enabled="false"
                 android:shouldDisableView="false"
+                android:selectable="false"
                 android:title="@string/model_info"
-                android:summary="@string/device_info_default"/>
+                android:summary="@string/device_info_default"
+                settings:allowDividerAbove="true"
+                settings:allowDividerBelow="true"/>
 
         <!-- Device firmware version -->
         <Preference android:key="firmware_version"
@@ -92,25 +97,37 @@
         </PreferenceScreen>
 
         <!-- Device FCC equipment id -->
-        <Preference android:key="fcc_equipment_id"
+        <com.android.settings.DividerPreference
+                android:key="fcc_equipment_id"
                 android:enabled="false"
                 android:shouldDisableView="false"
+                android:selectable="false"
                 android:title="@string/fcc_equipment_id"
-                android:summary="@string/device_info_default"/>
+                android:summary="@string/device_info_default"
+                settings:allowDividerAbove="true"
+                settings:allowDividerBelow="true"/>
 
         <!-- Device Baseband version -->
-        <Preference android:key="baseband_version"
+        <com.android.settings.DividerPreference
+                android:key="baseband_version"
                 android:enabled="false"
                 android:shouldDisableView="false"
+                android:selectable="false"
                 android:title="@string/baseband_version"
-                android:summary="@string/device_info_default"/>
+                android:summary="@string/device_info_default"
+                settings:allowDividerAbove="true"
+                settings:allowDividerBelow="true"/>
 
         <!-- Device Kernel version -->
-        <Preference android:key="kernel_version"
+        <com.android.settings.DividerPreference
+                android:key="kernel_version"
                 android:enabled="false"
                 android:shouldDisableView="false"
+                android:selectable="false"
                 android:title="@string/kernel_version"
-                android:summary="@string/device_info_default"/>
+                android:summary="@string/device_info_default"
+                settings:allowDividerAbove="true"
+                settings:allowDividerBelow="true"/>
 
         <!-- Detailed build version -->
         <Preference android:key="build_number"
@@ -120,10 +137,14 @@
                 android:summary="@string/device_info_default"/>
 
         <!-- SELinux status information -->
-        <Preference android:key="selinux_status"
+        <com.android.settings.DividerPreference
+                android:key="selinux_status"
                 android:enabled="false"
                 android:shouldDisableView="false"
+                android:selectable="false"
                 android:title="@string/selinux_status"
-                android:summary="@string/selinux_status_enforcing"/>
+                android:summary="@string/selinux_status_enforcing"
+                settings:allowDividerAbove="true"
+                settings:allowDividerBelow="true"/>
 
 </PreferenceScreen>
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index e797b4f..b5e2848 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -79,19 +79,10 @@
                 android:key="lift_to_wake"
                 android:title="@string/lift_to_wake_title" />
 
-        <PreferenceScreen
+        <SwitchPreference
                 android:key="doze"
-                android:title="@string/ambient_display_title"
-                android:summary="@string/doze_summary" >
-                <intent
-                    android:targetPackage="com.android.settings"
-                    android:targetClass="com.android.settings.Settings$GestureSettingsActivity" >
-                    <extra android:name="show_drawer_menu"
-                           android:value="true" />
-                    <extra android:name="gesture_scroll_to_preference"
-                           android:value="gesture_pick_up_and_nudge" />
-                </intent>
-        </PreferenceScreen>
+                android:title="@string/doze_title"
+                android:summary="@string/doze_summary" />
 
         <SwitchPreference
                 android:key="tap_to_wake"
diff --git a/res/xml/gesture_settings.xml b/res/xml/gesture_settings.xml
index c5d4ab4..af365bf 100644
--- a/res/xml/gesture_settings.xml
+++ b/res/xml/gesture_settings.xml
@@ -20,10 +20,10 @@
     settings:keywords="@string/keywords_gesture">
 
     <com.android.settings.gestures.GesturePreference
-            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"/>
+        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"/>
 
     <com.android.settings.gestures.GesturePreference
         android:key="gesture_double_tap_power"
@@ -38,9 +38,15 @@
         settings:animation="@raw/gesture_twist"/>
 
     <com.android.settings.gestures.GesturePreference
-        android:key="gesture_pick_up_and_nudge"
+        android:key="gesture_double_tap_screen"
         android:title="@string/ambient_display_title"
         android:summary="@string/ambient_display_summary"
         settings:animation="@raw/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"/>
+
 </PreferenceScreen>
\ No newline at end of file
diff --git a/src/com/android/settings/BackupSettingsActivity.java b/src/com/android/settings/BackupSettingsActivity.java
index 94e9691..a4cc4b7 100644
--- a/src/com/android/settings/BackupSettingsActivity.java
+++ b/src/com/android/settings/BackupSettingsActivity.java
@@ -17,8 +17,13 @@
 package com.android.settings;
 
 import android.app.Activity;
+import android.app.backup.BackupManager;
+import android.app.backup.IBackupManager;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.ServiceManager;
+import android.os.UserHandle;
 import android.text.TextUtils;
 import android.util.Log;
 
@@ -43,6 +48,17 @@
                 Intent intent = Intent.parseUri(backup, 0);
                 if (intent.resolveActivity(getPackageManager()) != null) {
                     // use startActivityForResult to let the activity check the caller signature
+                    IBackupManager bmgr = IBackupManager.Stub.asInterface(
+                            ServiceManager.getService(Context.BACKUP_SERVICE));
+                    boolean backupOkay;
+                    try {
+                        backupOkay = bmgr.isBackupServiceActive(UserHandle.myUserId());
+                    } catch (Exception e) {
+                        // things go wrong talking to the backup system => ignore and
+                        // pass the default 'false' as the "backup is a thing?" state.
+                        backupOkay = false;
+                    }
+                    intent.putExtra(BackupManager.EXTRA_BACKUP_SERVICES_AVAILABLE, backupOkay);
                     startActivityForResult(intent, -1);
                 } else {
                     Log.e(TAG, "Backup component not found!");
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 87634fc..f7b9443 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -41,7 +41,6 @@
 import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.Preference.OnPreferenceChangeListener;
-import android.support.v7.preference.PreferenceScreen;
 import android.text.TextUtils;
 import android.util.Log;
 
@@ -97,10 +96,10 @@
     private ListPreference mNightModePreference;
     private Preference mScreenSaverPreference;
     private SwitchPreference mLiftToWakePreference;
+    private SwitchPreference mDozePreference;
     private SwitchPreference mTapToWakePreference;
     private SwitchPreference mAutoBrightnessPreference;
     private SwitchPreference mCameraGesturePreference;
-    private PreferenceScreen mDozePreference;
 
     @Override
     protected int getMetricsCategory() {
@@ -144,10 +143,11 @@
             removePreference(KEY_LIFT_TO_WAKE);
         }
 
-        if (!isDozeAvailable(activity)) {
-            removePreference(KEY_DOZE);
+        if (isDozeAvailable(activity)) {
+            mDozePreference = (SwitchPreference) findPreference(KEY_DOZE);
+            mDozePreference.setOnPreferenceChangeListener(this);
         } else {
-            mDozePreference = (PreferenceScreen) findPreference(KEY_DOZE);
+            removePreference(KEY_DOZE);
         }
 
         if (isTapToWakeAvailable(getResources())) {
@@ -360,6 +360,12 @@
             mTapToWakePreference.setChecked(value != 0);
         }
 
+        // Update doze if it is available.
+        if (mDozePreference != null) {
+            int value = Settings.Secure.getInt(getContentResolver(), DOZE_ENABLED, 1);
+            mDozePreference.setChecked(value != 0);
+        }
+
         // Update camera gesture #1 if it is available.
         if (mCameraGesturePreference != null) {
             int value = Settings.Secure.getInt(getContentResolver(), CAMERA_GESTURE_DISABLED, 0);
@@ -407,6 +413,10 @@
             boolean value = (Boolean) objValue;
             Settings.Secure.putInt(getContentResolver(), WAKE_GESTURE_ENABLED, value ? 1 : 0);
         }
+        if (preference == mDozePreference) {
+            boolean value = (Boolean) objValue;
+            Settings.Secure.putInt(getContentResolver(), DOZE_ENABLED, value ? 1 : 0);
+        }
         if (preference == mTapToWakePreference) {
             boolean value = (Boolean) objValue;
             Settings.Secure.putInt(getContentResolver(), DOUBLE_TAP_TO_WAKE, value ? 1 : 0);
diff --git a/src/com/android/settings/dashboard/conditional/DndCondition.java b/src/com/android/settings/dashboard/conditional/DndCondition.java
index dcab279..49d67c2 100644
--- a/src/com/android/settings/dashboard/conditional/DndCondition.java
+++ b/src/com/android/settings/dashboard/conditional/DndCondition.java
@@ -139,8 +139,11 @@
         public void onReceive(Context context, Intent intent) {
             if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL
                     .equals(intent.getAction())) {
-                ConditionManager.get(context).getCondition(DndCondition.class)
-                        .refreshState();
+                final Condition condition =
+                        ConditionManager.get(context).getCondition(DndCondition.class);
+                if (condition != null) {
+                    condition.refreshState();
+                }
             }
         }
     }
diff --git a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
index efb1e0f..8edf16e 100644
--- a/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
+++ b/src/com/android/settings/deviceinfo/PrivateVolumeSettings.java
@@ -30,7 +30,6 @@
 import android.content.pm.UserInfo;
 import android.os.Bundle;
 import android.os.Environment;
-import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.os.storage.StorageEventListener;
@@ -93,8 +92,6 @@
 
     private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
 
-    private static final String STORAGE_MANAGER_PROPERTY = "ro.storage_manager.enabled";
-
     private static final int[] ITEMS_NO_SHOW_SHARED = new int[] {
             R.string.storage_detail_apps,
             R.string.storage_detail_system,
@@ -218,7 +215,7 @@
 
         screen.removeAll();
 
-        if (SystemProperties.getBoolean(STORAGE_MANAGER_PROPERTY, false)) {
+        if (getResources().getBoolean(R.bool.config_storage_manager_settings_enabled)) {
             addPreference(screen, mAutomaticStorageManagement);
         }
         addPreference(screen, mSummary);
@@ -410,7 +407,8 @@
             mount.setVisible(false);
             unmount.setVisible(false);
             format.setVisible(false);
-            manage.setVisible(SystemProperties.getBoolean(STORAGE_MANAGER_PROPERTY, false));
+            manage.setVisible(getResources().getBoolean(
+                    R.bool.config_storage_manager_settings_enabled));
         } else {
             rename.setVisible(mVolume.getType() == VolumeInfo.TYPE_PRIVATE);
             mount.setVisible(mVolume.getState() == VolumeInfo.STATE_UNMOUNTED);
diff --git a/src/com/android/settings/gestures/GesturePreference.java b/src/com/android/settings/gestures/GesturePreference.java
index 2d921bf..4536aa2 100644
--- a/src/com/android/settings/gestures/GesturePreference.java
+++ b/src/com/android/settings/gestures/GesturePreference.java
@@ -58,7 +58,6 @@
     public GesturePreference(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;
-        setLayoutResource(R.layout.gesture_preference);
         TypedArray attributes = context.getTheme().obtainStyledAttributes(
                 attrs,
                 R.styleable.GesturePreference,
@@ -70,7 +69,8 @@
                     .appendPath(String.valueOf(animation))
                     .build();
             mMediaPlayer = MediaPlayer.create(mContext, mVideoPath);
-            if (mMediaPlayer != null) {
+            if (mMediaPlayer != null && mMediaPlayer.getDuration() > 0) {
+                setLayoutResource(R.layout.gesture_preference);
                 mMediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                     @Override
                     public void onSeekComplete(MediaPlayer mp) {
@@ -84,9 +84,8 @@
                         mediaPlayer.setLooping(true);
                     }
                 });
+                mAnimationAvailable = true;
             }
-            mAnimationAvailable = true;
-
         } catch (Exception e) {
             Log.w(TAG, "Animation resource not found. Will not show animation.");
         } finally {
@@ -97,15 +96,14 @@
     @Override
     public void onBindViewHolder(PreferenceViewHolder holder) {
         super.onBindViewHolder(holder);
+
+        if (!mAnimationAvailable) {
+            return;
+        }
+
         final TextureView video = (TextureView) holder.findViewById(R.id.gesture_video);
         final ImageView imageView = (ImageView) holder.findViewById(R.id.gesture_image);
         final ImageView playButton = (ImageView) holder.findViewById(R.id.gesture_play_button);
-        final View animationFrame = holder.findViewById(R.id.gesture_animation_frame);
-
-        if (!mAnimationAvailable) {
-            animationFrame.setVisibility(View.GONE);
-            return;
-        }
 
         video.setOnClickListener(new View.OnClickListener() {
             @Override
@@ -182,7 +180,9 @@
     }
 
     void loadPreview(LoaderManager manager, int id) {
-        Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this);
+        if (mAnimationAvailable) {
+            Loader<Bitmap> loader = manager.initLoader(id, Bundle.EMPTY, this);
+        }
     }
 
     void onViewVisible() {
diff --git a/src/com/android/settings/gestures/GestureSettings.java b/src/com/android/settings/gestures/GestureSettings.java
index a44c781..88a7bb4 100644
--- a/src/com/android/settings/gestures/GestureSettings.java
+++ b/src/com/android/settings/gestures/GestureSettings.java
@@ -52,16 +52,16 @@
     private static final String TAG = "GestureSettings";
     private static final String PREF_KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
     private static final String PREF_KEY_DOUBLE_TWIST = "gesture_double_twist";
-    private static final String PREF_KEY_PICK_UP_AND_NUDGE = "gesture_pick_up_and_nudge";
+    private static final String PREF_KEY_PICK_UP = "gesture_pick_up";
     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 String ARG_SCROLL_TO_PREFERENCE = "gesture_scroll_to_preference";
     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_AND_NUDG = 2;
+    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 int mScrollPosition = -1;
     private List<GesturePreference> mPreferences;
 
     @Override
@@ -82,16 +82,19 @@
 
         // Ambient Display
         if (isDozeAvailable(context)) {
-            int dozeEnabled = Secure.getInt(getContentResolver(), Secure.DOZE_ENABLED, 1);
-            addPreference(PREF_KEY_PICK_UP_AND_NUDGE, dozeEnabled != 0, PREF_ID_DOUBLE_TWIST);
+            int pickup = Secure.getInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, 1);
+            addPreference(PREF_KEY_PICK_UP, pickup != 0, PREF_ID_PICK_UP);
+            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);
         } else {
-            removePreference(PREF_KEY_PICK_UP_AND_NUDGE);
+            removePreference(PREF_KEY_PICK_UP);
+            removePreference(PREF_KEY_DOUBLE_TAP_SCREEN);
         }
 
         // Fingerprint slide for notifications
         if (isSystemUINavigationAvailable(context)) {
             addPreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT, isSystemUINavigationEnabled(context),
-                    PREF_ID_PICK_UP_AND_NUDG);
+                    PREF_ID_SWIPE_DOWN_FINGERPRINT);
         } else {
             removePreference(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
         }
@@ -100,23 +103,11 @@
         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_SWIPE_DOWN_FINGERPRINT);
+            addPreference(PREF_KEY_DOUBLE_TWIST, doubleTwistEnabled != 0, PREF_ID_DOUBLE_TWIST);
         } else {
             removePreference(PREF_KEY_DOUBLE_TWIST);
         }
 
-        if (savedInstanceState == null) {
-            final Bundle args = getArguments();
-            if (args != null && args.containsKey(ARG_SCROLL_TO_PREFERENCE)) {
-                String prefKey = args.getString(ARG_SCROLL_TO_PREFERENCE);
-                GesturePreference pref = (GesturePreference) findPreference(prefKey);
-                if (pref != null) {
-                    mScrollPosition = pref.getOrder();
-                }
-            }
-        }
-
     }
 
     @Override
@@ -124,9 +115,6 @@
                              Bundle savedInstanceState) {
         View view = super.onCreateView(inflater, container, savedInstanceState);
         RecyclerView listview = getListView();
-        if (mScrollPosition >= 0) {
-            listview.scrollToPosition(mScrollPosition);
-        }
         listview.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
@@ -163,8 +151,10 @@
         if (PREF_KEY_DOUBLE_TAP_POWER.equals(key)) {
             Secure.putInt(getContentResolver(),
                     Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? 0 : 1);
-        } else if (PREF_KEY_PICK_UP_AND_NUDGE.equals(key)) {
-            Secure.putInt(getContentResolver(), Secure.DOZE_ENABLED, enabled ? 1 : 0);
+        } else if (PREF_KEY_PICK_UP.equals(key)) {
+            Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_PICK_UP, enabled ? 1 : 0);
+        } else if (PREF_KEY_DOUBLE_TAP_SCREEN.equals(key)) {
+            Secure.putInt(getContentResolver(), Secure.DOZE_PULSE_ON_DOUBLE_TAP, enabled ? 1 : 0);
         } else if (PREF_KEY_SWIPE_DOWN_FINGERPRINT.equals(key)) {
             Secure.putInt(getContentResolver(),
                     Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, enabled ? 1 : 0);
@@ -255,7 +245,8 @@
                     result.add(PREF_KEY_DOUBLE_TAP_POWER);
                 }
                 if (!isDozeAvailable(context)) {
-                    result.add(PREF_KEY_PICK_UP_AND_NUDGE);
+                    result.add(PREF_KEY_PICK_UP);
+                    result.add(PREF_KEY_DOUBLE_TAP_SCREEN);
                 }
                 if (!isSystemUINavigationAvailable(context)) {
                     result.add(PREF_KEY_SWIPE_DOWN_FINGERPRINT);
@@ -267,4 +258,4 @@
             }
         };
 
-}
\ No newline at end of file
+}
diff --git a/tests/app/Android.mk b/tests/app/Android.mk
index a641648..979c27d 100644
--- a/tests/app/Android.mk
+++ b/tests/app/Android.mk
@@ -7,15 +7,13 @@
 
 LOCAL_JAVA_LIBRARIES := android.test.runner bouncycastle
 
-LOCAL_STATIC_ANDROID_LIBRARIES := \
-    android-support-v4
-
 LOCAL_STATIC_JAVA_LIBRARIES := \
     android-support-test \
     mockito-target \
     espresso-core \
-    espresso-contrib \
-    espresso-intents
+    espresso-contrib-nodep \
+    espresso-intents-nodep \
+    ub-uiautomator
 
 # Include all test java files.
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
diff --git a/tests/app/src/com/android/settings/gesture/GestureSettingsTest.java b/tests/app/src/com/android/settings/gesture/GestureSettingsTest.java
new file mode 100644
index 0000000..4f3a524
--- /dev/null
+++ b/tests/app/src/com/android/settings/gesture/GestureSettingsTest.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2016 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 com.android.settings.gesture;
+
+import android.content.Context;
+import android.content.Intent;
+import android.provider.Settings.Secure;
+import android.support.test.filters.MediumTest;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject;
+import android.support.test.uiautomator.UiSelector;
+import android.support.test.uiautomator.UiScrollable;
+import android.test.InstrumentationTestCase;
+import android.util.Log;
+import android.widget.RelativeLayout;
+import android.widget.Switch;
+
+import com.android.settings.R;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.junit.Test;
+
+/**
+ * Test for Gesture preferences.
+ */
+@MediumTest
+public class GestureSettingsTest extends InstrumentationTestCase {
+
+    private static final String TAG = "GestureSettingsTest";
+
+    private UiDevice mDevice;
+    private Context mTargetContext;
+    private String mTargetPackage;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mDevice = UiDevice.getInstance(getInstrumentation());
+        mTargetContext = getInstrumentation().getTargetContext();
+        mTargetPackage = mTargetContext.getPackageName();
+    }
+
+    @Test
+    public void testAmbientDisplaySwitchPreference() throws Exception {
+        launchSettings();
+        UiObject dozeSwitch = getDozeSwitch();
+        assertNotNull(dozeSwitch);
+        assertTrue(dozeSwitch.exists());
+        assertToggleStateMatchesSettingValue(dozeSwitch, Secure.DOZE_ENABLED, 1, 1);
+    }
+
+    @Test
+    public void testGestureSettingsExists() throws Exception {
+        launchMoves();
+        UiObject titleObj = mDevice.findObject(new UiSelector().text(
+                mTargetContext.getResources().getString(R.string.gesture_preference_title)));
+        assertNotNull(titleObj);
+        assertTrue(titleObj.exists());
+    }
+
+    @Test
+    public void testCameraDoubleTapToggle() throws Exception {
+        assertSwitchToggle(mTargetContext.getResources().getString(
+                R.string.double_tap_power_for_camera_title),
+                Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0, 0);
+    }
+
+    @Test
+    public void testCameraDoubleTwistToggle() throws Exception {
+        assertSwitchToggle(mTargetContext.getResources().getString(
+                R.string.double_twist_for_camera_mode_title),
+                Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1, 1);
+    }
+
+    @Test
+    public void testFingerprintSwipeToggle() throws Exception {
+        assertSwitchToggle(mTargetContext.getResources().getString(
+                R.string.fingerprint_swipe_for_notifications_title),
+                Secure.SYSTEM_NAVIGATION_KEYS_ENABLED, 0, 1);
+    }
+
+    @Test
+    public void testDozeDoubleTapToggle() throws Exception {
+        assertSwitchToggle(mTargetContext.getResources().getString(
+                R.string.ambient_display_title),
+                Secure.DOZE_PULSE_ON_DOUBLE_TAP, 1, 1);
+    }
+
+    @Test
+    public void testDozePickupToggle() throws Exception {
+        assertSwitchToggle(mTargetContext.getResources().getString(
+                R.string.ambient_display_pickup_title),
+                Secure.DOZE_PULSE_ON_PICK_UP, 1, 1);
+    }
+
+    private void launchSettings() {
+        Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
+                .addCategory(Intent.CATEGORY_LAUNCHER)
+                .setPackage(mTargetPackage)
+                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        getInstrumentation().getContext().startActivity(settingsIntent);
+    }
+
+    private void launchMoves() throws Exception  {
+        launchSettings();
+        UiScrollable settings = new UiScrollable(
+                new UiSelector().packageName(mTargetPackage).scrollable(true));
+        String titleMoves =
+                mTargetContext.getResources().getString(R.string.gesture_preference_title);
+        settings.scrollTextIntoView(titleMoves);
+        mDevice.findObject(new UiSelector().text(titleMoves)).click();
+    }
+
+    private void navigateToMovesSetting(String title) throws Exception {
+        launchMoves();
+        UiScrollable moves = new UiScrollable(
+                new UiSelector().packageName(mTargetPackage).scrollable(true));
+        moves.scrollTextIntoView(title);
+    }
+
+    private UiScrollable navigateToAmbientDisplay() throws Exception {
+        UiScrollable settings = new UiScrollable(
+                new UiSelector().packageName(mTargetPackage).scrollable(true));
+        String titleDisplay =
+                mTargetContext.getResources().getString(R.string.display_settings_title);
+        settings.scrollTextIntoView(titleDisplay);
+        mDevice.findObject(new UiSelector().text(titleDisplay)).click();
+        settings.scrollTextIntoView(mTargetContext.getResources().getString(R.string.doze_title));
+        return settings;
+    }
+
+    private UiObject getGestureSwitch(String title) throws Exception {
+        UiObject titleView = mDevice.findObject(new UiSelector().text(title));
+        UiObject gestureSwitch =
+            titleView.getFromParent(new UiSelector().className(Switch.class.getName()));
+        assertNotNull(gestureSwitch);
+        assertTrue(gestureSwitch.exists());
+        return gestureSwitch;
+    }
+
+    private UiObject getDozeSwitch() throws Exception {
+        UiScrollable settings = navigateToAmbientDisplay();
+        UiObject dozeSwitch = null;
+        UiSelector relativeLayoutSelector =
+                new UiSelector().className(RelativeLayout.class.getName());
+        String titleDoze = mTargetContext.getResources().getString(R.string.doze_title);
+        for (int i = 0; i <= settings.getChildCount(relativeLayoutSelector); i++) {
+            UiObject relativeLayout = settings.getChild(relativeLayoutSelector.instance(i));
+            if (relativeLayout.getChildCount() != 2) {
+                continue;
+            }
+            UiObject obj1 = relativeLayout.getChild(new UiSelector().index(0));
+            if (obj1.getText() == titleDoze) {
+                return relativeLayout.getFromParent(
+                        new UiSelector().className(Switch.class.getName()));
+            }
+        }
+        return null;
+    }
+
+    private void assertSwitchToggle(String title, String key, int defaultVal, int enabledVal)
+            throws Exception {
+        navigateToMovesSetting(title);
+        assertToggleStateMatchesSettingValue(getGestureSwitch(title), key, defaultVal, enabledVal);
+    }
+
+    private void assertToggleStateMatchesSettingValue (
+            UiObject testSwitch, String key, int defaultVal, int enabledVal) throws Exception {
+        // check initial state
+        int currentValue = Secure.getInt(mTargetContext.getContentResolver(), key, defaultVal);
+        boolean enabled = currentValue == enabledVal;
+        assertEquals(enabled, testSwitch.isChecked());
+        // toggle the preference
+        testSwitch.click();
+        assertEquals(!enabled, testSwitch.isChecked());
+        int newValue = currentValue == 1 ? 0 : 1;
+        assertEquals(newValue, Secure.getInt(mTargetContext.getContentResolver(), key, defaultVal));
+    }
+
+}
diff --git a/tests/app/src/com/android/settings/tests/PrivateVolumeSettingsTest.java b/tests/app/src/com/android/settings/tests/PrivateVolumeSettingsTest.java
new file mode 100644
index 0000000..6289f1b
--- /dev/null
+++ b/tests/app/src/com/android/settings/tests/PrivateVolumeSettingsTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2016 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 com.android.settings.tests;
+
+import android.app.Instrumentation;
+import android.content.Intent;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import com.android.settings.Settings;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static android.support.test.espresso.Espresso.onView;
+import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static android.support.test.espresso.matcher.ViewMatchers.withText;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class PrivateVolumeSettingsTest {
+    @Test
+    public void test_ManageStorageNotShown() {
+        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+        instrumentation.startActivitySync(
+                new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS));
+        onView(withText(com.android.settings.R.string.storage_menu_manage)).check(doesNotExist());
+    }
+}
\ No newline at end of file