Merge "Make SeekBarPreference to be selectable" into qt-dev am: dd59f1193f
am: 574893b860

Change-Id: I7761ee743a356507feff41c5554927c3ad61a815
diff --git a/src/com/android/settings/widget/SeekBarPreference.java b/src/com/android/settings/widget/SeekBarPreference.java
index 44def11..bdd1ba9 100644
--- a/src/com/android/settings/widget/SeekBarPreference.java
+++ b/src/com/android/settings/widget/SeekBarPreference.java
@@ -69,6 +69,13 @@
                 com.android.internal.R.layout.preference_widget_seekbar);
         a.recycle();
 
+        a = context.obtainStyledAttributes(
+                attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes);
+        final boolean isSelectable = a.getBoolean(
+                com.android.settings.R.styleable.Preference_android_selectable, false);
+        setSelectable(isSelectable);
+        a.recycle();
+
         setLayoutResource(layoutResId);
     }
 
@@ -93,7 +100,11 @@
 
     @Override
     public boolean isSelectable() {
-        return isDisabledByAdmin();
+        if(isDisabledByAdmin()) {
+            return true;
+        } else {
+            return super.isSelectable();
+        }
     }
 
     @Override
diff --git a/tests/robotests/res/xml-mcc998/seekbar_preference.xml b/tests/robotests/res/xml-mcc998/seekbar_preference.xml
new file mode 100644
index 0000000..e474c1e
--- /dev/null
+++ b/tests/robotests/res/xml-mcc998/seekbar_preference.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2019 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.
+  -->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <com.android.settings.widget.SeekBarPreference
+        android:key="seek_bar"
+        android:title="seek_bar_title"/>
+</PreferenceScreen >
diff --git a/tests/robotests/res/xml-mcc999/seekbar_preference.xml b/tests/robotests/res/xml-mcc999/seekbar_preference.xml
new file mode 100644
index 0000000..77435e8
--- /dev/null
+++ b/tests/robotests/res/xml-mcc999/seekbar_preference.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Copyright (C) 2019 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.
+  -->
+
+<PreferenceScreen
+    xmlns:android="http://schemas.android.com/apk/res/android">
+    <com.android.settings.widget.SeekBarPreference
+        android:key="seek_bar"
+        android:selectable="true"
+        android:title="seek_bar_title"/>
+</PreferenceScreen >
diff --git a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
index 0a1d5d8..f7dea22 100644
--- a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
@@ -22,16 +22,24 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
+import android.os.Bundle;
 import android.os.Parcelable;
 
+import androidx.preference.PreferenceFragmentCompat;
+
+import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.androidx.fragment.FragmentController;
 
 @RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
 public class SeekBarPreferenceTest {
 
     private static final int MAX = 75;
@@ -73,9 +81,39 @@
     }
 
     @Test
-    public void isSelectable_notDisabledByAdmin_returnFalse() {
-        when(mSeekBarPreference.isDisabledByAdmin()).thenReturn(false);
+    @Config(qualifiers = "mcc998")
+    public void isSelectable_default_returnFalse() {
+        final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(),
+                new Bundle())
+                .create()
+                .start()
+                .resume()
+                .get();
 
-        assertThat(mSeekBarPreference.isSelectable()).isFalse();
+        final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar");
+
+        assertThat(seekBarPreference.isSelectable()).isFalse();
+    }
+
+    @Test
+    @Config(qualifiers = "mcc999")
+    public void isSelectable_selectableInXml_returnTrue() {
+        final PreferenceFragmentCompat fragment = FragmentController.of(new TestFragment(),
+                new Bundle())
+                .create()
+                .start()
+                .resume()
+                .get();
+
+        final SeekBarPreference seekBarPreference = fragment.findPreference("seek_bar");
+
+        assertThat(seekBarPreference.isSelectable()).isTrue();
+    }
+
+    public static class TestFragment extends PreferenceFragmentCompat {
+        @Override
+        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+            addPreferencesFromResource(com.android.settings.R.xml.seekbar_preference);
+        }
     }
 }