Merge "Do not disable toggle when Wi-Fi is enabling and disabling." into oc-dev
diff --git a/res/layout-land/confirm_lock_password.xml b/res/layout-land/confirm_lock_password.xml
index dff4e4d..e9b2b0f 100644
--- a/res/layout-land/confirm_lock_password.xml
+++ b/res/layout-land/confirm_lock_password.xml
@@ -74,7 +74,7 @@
                 android:layout_gravity="center_horizontal|bottom"
                 android:layout_marginBottom="26dp"
                 android:inputType="textPassword"
-                android:imeOptions="actionNext|flagNoFullscreen"
+                android:imeOptions="actionNext|flagNoFullscreen|flagForceAscii"
                 android:gravity="center"
                 android:textSize="16sp"
                 style="@style/TextAppearance.PasswordEntry"/>
diff --git a/res/layout/choose_lock_password.xml b/res/layout/choose_lock_password.xml
index 15fb7db..260db7f 100644
--- a/res/layout/choose_lock_password.xml
+++ b/res/layout/choose_lock_password.xml
@@ -48,7 +48,7 @@
             android:layout_gravity="center"
             android:gravity="center"
             android:inputType="textPassword"
-            android:imeOptions="actionNext|flagNoExtractUi"
+            android:imeOptions="actionNext|flagNoExtractUi|flagForceAscii"
             android:textSize="24sp"
             style="@style/TextAppearance.PasswordEntry"/>
 
diff --git a/res/layout/confirm_lock_password_base.xml b/res/layout/confirm_lock_password_base.xml
index 8e9a87b..22726be 100644
--- a/res/layout/confirm_lock_password_base.xml
+++ b/res/layout/confirm_lock_password_base.xml
@@ -70,7 +70,7 @@
             android:layout_gravity="center_horizontal"
             android:layout_marginTop="-40dp"
             android:inputType="textPassword"
-            android:imeOptions="actionNext|flagNoFullscreen"
+            android:imeOptions="actionNext|flagNoFullscreen|flagForceAscii"
             android:gravity="center"
             android:textSize="16sp"
             style="@style/TextAppearance.PasswordEntry"/>
diff --git a/res/layout/confirm_lock_password_internal.xml b/res/layout/confirm_lock_password_internal.xml
index e22d764..4f22cfb 100644
--- a/res/layout/confirm_lock_password_internal.xml
+++ b/res/layout/confirm_lock_password_internal.xml
@@ -67,7 +67,7 @@
             android:layout_gravity="center_horizontal"
             android:layout_marginTop="-40dp"
             android:inputType="textPassword"
-            android:imeOptions="actionNext|flagNoFullscreen"
+            android:imeOptions="actionNext|flagNoFullscreen|flagForceAscii"
             android:gravity="center"
             android:textSize="16sp"
             style="@style/TextAppearance.PasswordEntry"/>
diff --git a/res/layout/crypt_keeper_password_field.xml b/res/layout/crypt_keeper_password_field.xml
index bf286c0..9a06fd3 100644
--- a/res/layout/crypt_keeper_password_field.xml
+++ b/res/layout/crypt_keeper_password_field.xml
@@ -27,6 +27,7 @@
         android:layout_width="0dip"
         android:layout_weight="1"
         android:inputType="textPassword"
+        android:imeOptions="flagForceAscii"
         android:textSize="16sp"
         android:padding="10sp"
         android:maxLength="500"
diff --git a/res/layout/preference_bluetooth.xml b/res/layout/preference_bluetooth.xml
new file mode 100644
index 0000000..c339e67
--- /dev/null
+++ b/res/layout/preference_bluetooth.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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:gravity="center_vertical">
+
+    <!-- Details button -->
+    <ImageView
+        android:id="@+id/deviceDetails"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center_vertical"
+        android:padding="8dip"
+        android:background="?android:attr/selectableItemBackground"
+        android:src="@drawable/ic_settings"
+        android:contentDescription="@string/bluetooth_device_details" />
+
+</LinearLayout>
diff --git a/res/layout/preference_progress_category.xml b/res/layout/preference_progress_category.xml
index 9f5a8b4..1380698 100644
--- a/res/layout/preference_progress_category.xml
+++ b/res/layout/preference_progress_category.xml
@@ -35,6 +35,7 @@
             android:id="@android:id/icon"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
+            android:tint="?android:attr/textColorPrimary"
             android:maxWidth="18dp"
             android:maxHeight="18dp"/>
     </LinearLayout>
@@ -46,8 +47,7 @@
         android:layout_height="wrap_content"
         android:layout_weight="1"
         android:layout_gravity="start|center"
-        android:textAppearance="@android:style/TextAppearance.Material.Body2"
-        android:textColor="?android:attr/colorAccent"/>
+        android:textAppearance="@android:style/TextAppearance.Material.Body2"/>
 
     <ProgressBar
         android:id="@+id/scanning_progress"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9f77998..475c60e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -222,6 +222,8 @@
     <string name="bluetooth_devices">Bluetooth devices</string>
     <!-- Bluetooth settings screen, title for the current bluetooth name setting -->
     <string name="bluetooth_device_name">Device name</string>
+    <!-- Bluetooth settings screen, image description for device details button. This opens the screen to rename, unpair, etc. a single device. -->
+    <string name="bluetooth_device_details">Device settings</string>
     <!-- Bluetooth settings screen, image description for profile of a device details button. -->
     <string name="bluetooth_profile_details">Profile settings</string>
     <!-- Bluetooth settings screen, summary text when there isn't a name set (for the name setting) -->
diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
index 7be6dd7..5bddffa 100644
--- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
+++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java
@@ -30,13 +30,14 @@
 import android.util.Log;
 import android.util.Pair;
 import android.util.TypedValue;
+import android.view.View;
+import android.view.View.OnClickListener;
 import android.widget.ImageView;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
 import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.GearPreference;
 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
 import com.android.settingslib.bluetooth.HidProfile;
 import com.android.settingslib.bluetooth.LocalBluetoothProfile;
@@ -49,14 +50,15 @@
  * BluetoothDevicePreference is the preference type used to display each remote
  * Bluetooth device in the Bluetooth Settings screen.
  */
-public final class BluetoothDevicePreference extends GearPreference implements
-        CachedBluetoothDevice.Callback {
-    private static final String TAG = "BluetoothDevicePref";
+public final class BluetoothDevicePreference extends Preference implements
+        CachedBluetoothDevice.Callback, OnClickListener {
+    private static final String TAG = "BluetoothDevicePreference";
 
     private static int sDimAlpha = Integer.MIN_VALUE;
 
     private final CachedBluetoothDevice mCachedDevice;
-    private final UserManager mUserManager;
+
+    private OnClickListener mOnSettingsClickListener;
 
     private AlertDialog mDisconnectDialog;
 
@@ -74,8 +76,7 @@
     public final String BLUETOOTH = r.getString(R.string.bluetooth_talkback_bluetooth);
 
     public BluetoothDevicePreference(Context context, CachedBluetoothDevice cachedDevice) {
-        super(context, null);
-        mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+        super(context);
 
         if (sDimAlpha == Integer.MIN_VALUE) {
             TypedValue outValue = new TypedValue();
@@ -84,6 +85,14 @@
         }
 
         mCachedDevice = cachedDevice;
+
+        if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
+            UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+            if (!um.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH)) {
+                setWidgetLayoutResource(R.layout.preference_bluetooth);
+            }
+        }
+
         mCachedDevice.registerCallback(this);
 
         onDeviceAttributesChanged();
@@ -93,22 +102,14 @@
         notifyChanged();
     }
 
-    @Override
-    protected boolean shouldHideSecondTarget() {
-        return mCachedDevice == null
-                || mCachedDevice.getBondState() != BluetoothDevice.BOND_BONDED
-                || mUserManager.hasUserRestriction(DISALLOW_CONFIG_BLUETOOTH);
-    }
-
-    @Override
-    protected int getSecondTargetResId() {
-        return R.layout.preference_widget_gear;
-    }
-
     CachedBluetoothDevice getCachedDevice() {
         return mCachedDevice;
     }
 
+    public void setOnSettingsClickListener(OnClickListener listener) {
+        mOnSettingsClickListener = listener;
+    }
+
     @Override
     protected void onPrepareForRemoval() {
         super.onPrepareForRemoval();
@@ -119,10 +120,6 @@
         }
     }
 
-    public CachedBluetoothDevice getBluetoothDevice() {
-        return mCachedDevice;
-    }
-
     public void onDeviceAttributesChanged() {
         /*
          * The preference framework takes care of making sure the value has
@@ -160,10 +157,11 @@
         }
 
         if (mCachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
-            ImageView deviceDetails = (ImageView) view.findViewById(R.id.settings_button);
+            ImageView deviceDetails = (ImageView) view.findViewById(R.id.deviceDetails);
 
             if (deviceDetails != null) {
                 deviceDetails.setOnClickListener(this);
+                deviceDetails.setTag(mCachedDevice);
             }
         }
         final ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
@@ -173,6 +171,13 @@
         super.onBindViewHolder(view);
     }
 
+    public void onClick(View v) {
+        // Should never be null by construction
+        if (mOnSettingsClickListener != null) {
+            mOnSettingsClickListener.onClick(v);
+        }
+    }
+
     @Override
     public boolean equals(Object o) {
         if ((o == null) || !(o instanceof BluetoothDevicePreference)) {
@@ -202,19 +207,19 @@
         int bondState = mCachedDevice.getBondState();
 
         final MetricsFeatureProvider metricsFeatureProvider =
-                FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
+            FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider();
 
         if (mCachedDevice.isConnected()) {
             metricsFeatureProvider.action(getContext(),
-                    MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
+                MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
             askDisconnect();
         } else if (bondState == BluetoothDevice.BOND_BONDED) {
             metricsFeatureProvider.action(getContext(),
-                    MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
+                MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
             mCachedDevice.connect(true);
         } else if (bondState == BluetoothDevice.BOND_NONE) {
             metricsFeatureProvider.action(getContext(),
-                    MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
+                MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
             pair();
         }
     }
@@ -278,10 +283,10 @@
             }
         }
         if (btClass != null) {
-            if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
+          if (btClass.doesClassMatch(BluetoothClass.PROFILE_HEADSET)) {
                 return new Pair<Integer, String>(R.drawable.ic_bt_headset_hfp, HEADSET);
             }
-            if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
+          if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) {
                 return new Pair<Integer, String>(R.drawable.ic_bt_headphones_a2dp, HEADPHONE);
             }
         }
diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java
index 317a350..5679f90 100644
--- a/src/com/android/settings/bluetooth/BluetoothSettings.java
+++ b/src/com/android/settings/bluetooth/BluetoothSettings.java
@@ -45,14 +45,13 @@
 import com.android.settings.LinkifyUtils;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
+import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
 import com.android.settings.dashboard.SummaryLoader;
 import com.android.settings.location.ScanningSettings;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 import com.android.settings.search.SearchIndexableRaw;
 import com.android.settings.widget.FooterPreference;
-import com.android.settings.widget.GearPreference;
-import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener;
 import com.android.settings.widget.SwitchBar;
 import com.android.settings.widget.SwitchBarController;
 import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
@@ -477,25 +476,24 @@
         }
     }
 
-    private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> {
-        // User clicked on advanced options icon for a device in the list
-        if (!(pref instanceof BluetoothDevicePreference)) {
-            Log.w(TAG, "onClick() called for other View: " + pref);
-            return;
+    private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            // User clicked on advanced options icon for a device in the list
+            if (!(v.getTag() instanceof CachedBluetoothDevice)) {
+                Log.w(TAG, "onClick() called for other View: " + v);
+                return;
+            }
+
+            final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag();
+            Bundle args = new Bundle();
+            args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS,
+                    device.getDevice().getAddress());
+            DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
+            profileSettings.setArguments(args);
+            profileSettings.show(getFragmentManager(),
+                    DeviceProfilesSettings.class.getSimpleName());
         }
-        final CachedBluetoothDevice device =
-                ((BluetoothDevicePreference) pref).getBluetoothDevice();
-        if (device == null) {
-            Log.w(TAG, "No BT device attached with this pref: " + pref);
-            return;
-        }
-        final Bundle args = new Bundle();
-        args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS,
-                device.getDevice().getAddress());
-        final DeviceProfilesSettings profileSettings = new DeviceProfilesSettings();
-        profileSettings.setArguments(args);
-        profileSettings.show(getFragmentManager(),
-                DeviceProfilesSettings.class.getSimpleName());
     };
 
     /**
@@ -508,7 +506,7 @@
         CachedBluetoothDevice cachedDevice = preference.getCachedDevice();
         if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) {
             // Only paired device have an associated advanced settings screen
-            preference.setOnGearClickListener(mDeviceProfilesListener);
+            preference.setOnSettingsClickListener(mDeviceProfilesListener);
         }
     }
 
diff --git a/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoView.java b/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoView.java
index 9f12286..ab3ea37 100644
--- a/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoView.java
+++ b/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoView.java
@@ -24,6 +24,7 @@
 import android.media.MediaPlayer.OnInfoListener;
 import android.media.MediaPlayer.OnPreparedListener;
 import android.net.Uri;
+import android.support.annotation.VisibleForTesting;
 import android.util.AttributeSet;
 import android.view.Surface;
 import android.view.TextureView;
@@ -73,7 +74,11 @@
                     mTextureToDestroy.release();
                     mTextureToDestroy = null;
                 }
-                mMediaPlayer = MediaPlayer.create(mContext, videoUri);
+                mMediaPlayer = createMediaPlayer(mContext, videoUri);
+                if (mMediaPlayer == null) {
+                    // MediaPlayer.create() method can return null
+                    return;
+                }
                 mMediaPlayer.setSurface(new Surface(surfaceTexture));
                 mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                     @Override
@@ -113,6 +118,11 @@
         });
     }
 
+    @VisibleForTesting
+    MediaPlayer createMediaPlayer(Context context, Uri videoUri) {
+        return MediaPlayer.create(mContext, videoUri);
+    }
+
     protected static Uri resourceEntryToUri (Context context, int id) {
         Resources res = context.getResources();
         return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index e9204f9..af4d8f8 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -115,6 +115,13 @@
     private static final String PREF_KEY_CONFIGURE_WIFI_SETTINGS = "configure_settings";
     private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
 
+    private final Runnable mUpdateAccessPointsRunnable = () -> {
+        updateAccessPointPreferences();
+    };
+    private final Runnable mHideProgressBarRunnable = () -> {
+        setProgressBarVisible(false);
+    };
+
     protected WifiManager mWifiManager;
     private WifiManager.ActionListener mConnectListener;
     private WifiManager.ActionListener mSaveListener;
@@ -360,8 +367,10 @@
 
     @Override
     public void onStop() {
-        super.onStop();
         mWifiTracker.stopTracking();
+        getView().removeCallbacks(mUpdateAccessPointsRunnable);
+        getView().removeCallbacks(mHideProgressBarRunnable);
+        super.onStop();
     }
 
     @Override
@@ -625,9 +634,7 @@
             case WifiManager.WIFI_STATE_ENABLED:
                 setProgressBarVisible(true);
                 // Have the progress bar displayed before starting to modify APs
-                getView().postDelayed(() -> {
-                        updateAccessPointPreferences();
-                    }, 300 /* delay milliseconds */);
+                getView().postDelayed(mUpdateAccessPointsRunnable, 300 /* delay milliseconds */);
                 break;
 
             case WifiManager.WIFI_STATE_ENABLING:
@@ -705,9 +712,7 @@
             mAccessPointsPreferenceCategory.addPreference(pref);
         } else {
             // Continuing showing progress bar for an additional delay to overlap with animation
-            getView().postDelayed(() -> {
-                    setProgressBarVisible(false);
-                }, 1700 /* delay millis */);
+            getView().postDelayed(mHideProgressBarRunnable, 1700 /* delay millis */);
         }
     }
 
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
index c4c1f8a..5915118 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java
@@ -17,10 +17,8 @@
 
 import android.bluetooth.BluetoothDevice;
 import android.content.Context;
-import android.os.UserManager;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
 import com.android.settings.core.instrumentation.MetricsFeatureProvider;
@@ -34,10 +32,7 @@
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
-import org.robolectric.util.ReflectionHelpers;
 
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -71,7 +66,7 @@
         mPreference.onClicked();
 
         verify(mMetricsFeatureProvider).action(
-                mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
+            mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT);
     }
 
     @Test
@@ -82,7 +77,7 @@
         mPreference.onClicked();
 
         verify(mMetricsFeatureProvider).action(
-                mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
+            mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT);
     }
 
     @Test
@@ -94,46 +89,6 @@
         mPreference.onClicked();
 
         verify(mMetricsFeatureProvider).action(
-                mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
-    }
-
-    @Test
-    public void getSecondTargetResource_shouldBeGearIconLayout() {
-        assertThat(mPreference.getSecondTargetResId()).isEqualTo(R.layout.preference_widget_gear);
-    }
-
-    @Test
-    public void shouldHideSecondTarget_noDevice_shouldReturnTrue() {
-        ReflectionHelpers.setField(mPreference, "mCachedDevice", null);
-
-        assertThat(mPreference.shouldHideSecondTarget()).isTrue();
-    }
-
-    @Test
-    public void shouldHideSecondTarget_notBond_shouldReturnTrue() {
-        when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
-
-        assertThat(mPreference.shouldHideSecondTarget()).isTrue();
-    }
-
-    @Test
-    public void shouldHideSecondTarget_hasUserRestriction_shouldReturnTrue() {
-        final UserManager um = mock(UserManager.class);
-        ReflectionHelpers.setField(mPreference, "mUserManager", um);
-        when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
-                .thenReturn(true);
-
-        assertThat(mPreference.shouldHideSecondTarget()).isTrue();
-    }
-
-    @Test
-    public void shouldHideSecondTarget_hasBoundDeviceAndNoRestriction_shouldReturnFalse() {
-        when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
-        final UserManager um = mock(UserManager.class);
-        ReflectionHelpers.setField(mPreference, "mUserManager", um);
-        when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH))
-                .thenReturn(false);
-
-        assertThat(mPreference.shouldHideSecondTarget()).isFalse();
+            mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java
new file mode 100644
index 0000000..e8dc2b5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintLocationAnimationVideoViewTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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 com.android.settings.fingerprint;
+
+import android.content.Context;
+import android.graphics.SurfaceTexture;
+import android.net.Uri;
+import android.view.TextureView.SurfaceTextureListener;
+
+import com.android.settings.SettingsRobolectricTestRunner;
+import com.android.settings.TestConfig;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class FingerprintLocationAnimationVideoViewTest {
+
+    private Context mContext;
+    private FingerprintLocationAnimationVideoView mView;
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        mContext = ShadowApplication.getInstance().getApplicationContext();
+        mView = spy(new FingerprintLocationAnimationVideoView(mContext, null));
+    }
+
+    @Test
+    public void onSurfaceTextureAvailable_nullMediaPlayer_shouldNotCrash() {
+        mView.onFinishInflate();
+        final SurfaceTextureListener listener = mView.getSurfaceTextureListener();
+        when(mView.createMediaPlayer(any(Context.class), any(Uri.class))).thenReturn(null);
+
+        listener.onSurfaceTextureAvailable(mock(SurfaceTexture.class), 48, 48);
+        // should not crash
+    }
+}
\ No newline at end of file