OSDN Git Service

Fix a crash when resuming sound setting with AfW on Ryu
authorFan Zhang <zhfan@google.com>
Thu, 16 Mar 2017 18:08:59 +0000 (11:08 -0700)
committerFan Zhang <zhfan@google.com>
Thu, 16 Mar 2017 18:26:33 +0000 (11:26 -0700)
Also renamed a few xmls

Change-Id: I8ff5a778a39ea45471a27048be4ea2f21075872a
Fix: 36357493
Test: make RunSettingsRoboTests

res/xml/display_settings.xml [moved from res/xml/ia_display_settings.xml with 100% similarity]
res/xml/sound_settings.xml [moved from res/xml/ia_sound_settings.xml with 100% similarity]
src/com/android/settings/DisplaySettings.java
src/com/android/settings/notification/SoundSettings.java
src/com/android/settings/notification/WorkSoundPreferenceController.java
tests/robotests/src/com/android/settings/notification/WorkSoundPreferenceControllerTest.java
tests/robotests/src/com/android/settings/search/XmlParserUtilTest.java
tests/robotests/src/com/android/settings/search2/DatabaseIndexingManagerTest.java

index 6fbffe8..dd4c9a4 100644 (file)
@@ -36,7 +36,6 @@ import com.android.settings.display.ThemePreferenceController;
 import com.android.settings.display.TimeoutPreferenceController;
 import com.android.settings.display.VrDisplayPreferenceController;
 import com.android.settings.display.WallpaperPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 
@@ -64,7 +63,7 @@ public class DisplaySettings extends DashboardFragment {
 
     @Override
     protected int getPreferenceScreenResId() {
-        return R.xml.ia_display_settings;
+        return R.xml.display_settings;
     }
 
     @Override
@@ -104,7 +103,7 @@ public class DisplaySettings extends DashboardFragment {
                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
 
                     final SearchIndexableResource sir = new SearchIndexableResource(context);
-                    sir.xmlResId = R.xml.ia_display_settings;
+                    sir.xmlResId = R.xml.display_settings;
                     result.add(sir);
                     return result;
                 }
index df60573..79a8970 100644 (file)
@@ -98,7 +98,7 @@ public class SoundSettings extends DashboardFragment {
 
     @Override
     protected int getPreferenceScreenResId() {
-        return R.xml.ia_sound_settings;
+        return R.xml.sound_settings;
     }
 
     @Override
@@ -216,7 +216,7 @@ public class SoundSettings extends DashboardFragment {
                 public List<SearchIndexableResource> getXmlResourcesToIndex(
                         Context context, boolean enabled) {
                     final SearchIndexableResource sir = new SearchIndexableResource(context);
-                    sir.xmlResId = R.xml.ia_sound_settings;
+                    sir.xmlResId = R.xml.sound_settings;
                     return Arrays.asList(sir);
                 }
 
index a4d7b8d..a80f503 100644 (file)
@@ -222,7 +222,7 @@ public class WorkSoundPreferenceController extends PreferenceController implemen
                     KEY_WORK_ALARM_RINGTONE);
         }
         if (!mVoiceCapable) {
-            mWorkPreferenceCategory.removePreference(mWorkPhoneRingtonePreference);
+            mWorkPhoneRingtonePreference.setVisible(false);
             mWorkPhoneRingtonePreference = null;
         }
 
index 13abd97..d996750 100644 (file)
@@ -134,7 +134,6 @@ public class WorkSoundPreferenceControllerTest {
         mController.displayPreference(mScreen);
         verify(mWorkCategory).setVisible(false);
 
-
         // However, when a managed profile is added later, the category should appear.
         mController.onResume();
         when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
@@ -204,6 +203,27 @@ public class WorkSoundPreferenceControllerTest {
     }
 
     @Test
+    public void onResume_noVoiceCapability_shouldHidePhoneRingtone() {
+        when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
+        mController = new WorkSoundPreferenceController(mContext, mFragment, null, mAudioHelper);
+
+        when(mAudioHelper.getManagedProfileId(any(UserManager.class)))
+                .thenReturn(UserHandle.myUserId());
+        when(mAudioHelper.isUserUnlocked(any(UserManager.class), anyInt())).thenReturn(true);
+        when(mAudioHelper.isSingleVolume()).thenReturn(false);
+        when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
+        when(mAudioHelper.createPackageContextAsUser(anyInt())).thenReturn(mContext);
+
+        // Precondition: work profile is available.
+        assertThat(mController.isAvailable()).isTrue();
+
+        mController.displayPreference(mScreen);
+        mController.onResume();
+
+        verify(mWorkCategory.findPreference(KEY_WORK_PHONE_RINGTONE)).setVisible(false);
+    }
+
+    @Test
     public void onResume_availableButLocked_shouldRedactPreferences() {
         final String notAvailable = "(not available)";
         when(mContext.getString(R.string.managed_profile_not_available_label))
index 028cbb0..5b7efcd 100644 (file)
@@ -56,7 +56,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataTitleValid_ReturnsPreferenceTitle() {
-        XmlResourceParser parser = getChildByType(R.xml.ia_display_settings,
+        XmlResourceParser parser = getChildByType(R.xml.display_settings,
                 "com.android.settings.TimeoutListPreference");
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String title = XmlParserUtils.getDataTitle(mContext, attrs);
@@ -66,7 +66,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataKeywordsValid_ReturnsPreferenceKeywords() {
-        XmlResourceParser parser = getParentPrimedParser(R.xml.ia_display_settings);
+        XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String keywords = XmlParserUtils.getDataKeywords(mContext, attrs);
         String expKeywords = mContext.getString(R.string.keywords_display);
@@ -75,7 +75,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataKeyValid_ReturnsPreferenceKey() {
-        XmlResourceParser parser = getChildByType(R.xml.ia_display_settings,
+        XmlResourceParser parser = getChildByType(R.xml.display_settings,
                 "com.android.settings.TimeoutListPreference");
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String key = XmlParserUtils.getDataKey(mContext, attrs);
@@ -85,7 +85,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataSummaryValid_ReturnsPreferenceSummary() {
-        XmlResourceParser parser = getChildByType(R.xml.ia_display_settings,
+        XmlResourceParser parser = getChildByType(R.xml.display_settings,
                 "com.android.settings.TimeoutListPreference");
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String summary = XmlParserUtils.getDataSummary(mContext, attrs);
@@ -128,7 +128,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataKeyInvalid_ReturnsNull() {
-        XmlResourceParser parser = getParentPrimedParser(R.xml.ia_display_settings);
+        XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String key = XmlParserUtils.getDataKey(mContext, attrs);
         assertThat(key).isNull();
@@ -136,7 +136,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataSummaryInvalid_ReturnsNull() {
-        XmlResourceParser parser = getParentPrimedParser(R.xml.ia_display_settings);
+        XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String summary = XmlParserUtils.getDataSummary(mContext, attrs);
         assertThat(summary).isNull();
@@ -144,7 +144,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataSummaryOffInvalid_ReturnsNull() {
-        XmlResourceParser parser = getParentPrimedParser(R.xml.ia_display_settings);
+        XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String summaryOff = XmlParserUtils.getDataSummaryOff(mContext, attrs);
         assertThat(summaryOff).isNull();
@@ -152,7 +152,7 @@ public class XmlParserUtilTest {
 
     @Test
     public void testDataEntriesInvalid_ReturnsNull() {
-        XmlResourceParser parser = getParentPrimedParser(R.xml.ia_display_settings);
+        XmlResourceParser parser = getParentPrimedParser(R.xml.display_settings);
         final AttributeSet attrs = Xml.asAttributeSet(parser);
         String entries = XmlParserUtils.getDataEntries(mContext, attrs);
         assertThat(entries).isNull();
index d537bc9..7d611c6 100644 (file)
@@ -49,7 +49,6 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.robolectric.RuntimeEnvironment;
 import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
 import org.robolectric.shadows.ShadowContentResolver;
 
 import java.util.ArrayList;
@@ -248,7 +247,7 @@ public class DatabaseIndexingManagerTest {
 
     @Test
     public void testAddResource_RowsInserted() {
-        SearchIndexableResource resource = getFakeResource(R.xml.ia_display_settings);
+        SearchIndexableResource resource = getFakeResource(R.xml.display_settings);
         mManager.indexOneSearchIndexableData(mDb, localeStr, resource, new HashMap<>());
         Cursor cursor = mDb.rawQuery("SELECT * FROM prefs_index", null);
         assertThat(cursor.getCount()).isEqualTo(16);
@@ -256,7 +255,7 @@ public class DatabaseIndexingManagerTest {
 
     @Test
     public void testAddResource_withNIKs_rowsInsertedDisabled() {
-        SearchIndexableResource resource = getFakeResource(R.xml.ia_display_settings);
+        SearchIndexableResource resource = getFakeResource(R.xml.display_settings);
         // Only add 2 of 16 items to be disabled.
         String[] keys = {"brightness", "wallpaper"};
         Map<String, Set<String>> niks = getNonIndexableKeys(keys);