Loading src/com/android/settings/notification/RingVolumePreferenceController.java +1 −22 Original line number Diff line number Diff line Loading @@ -119,9 +119,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr if (Objects.equals(suppressor, mSuppressor)) return; mSuppressor = suppressor; if (mPreference != null) { final String text = suppressor != null ? mContext.getString(com.android.internal.R.string.muted_by, getSuppressorCaption(suppressor)) : null; final String text = SuppressorHelper.getSuppressionText(mContext, suppressor); mPreference.setSuppressionText(text); } updatePreferenceIcon(); Loading @@ -137,25 +135,6 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr } } private String getSuppressorCaption(ComponentName suppressor) { final PackageManager pm = mContext.getPackageManager(); try { final ServiceInfo info = pm.getServiceInfo(suppressor, 0); if (info != null) { final CharSequence seq = info.loadLabel(pm); if (seq != null) { final String str = seq.toString().trim(); if (str.length() > 0) { return str; } } } } catch (Throwable e) { Log.w(TAG, "Error loading suppressor caption", e); } return suppressor.getPackageName(); } private final class H extends Handler { private static final int UPDATE_EFFECTS_SUPPRESSOR = 1; private static final int UPDATE_RINGER_MODE = 2; Loading src/com/android/settings/notification/SoundSettings.java +11 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.settings.notification; import android.app.Activity; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading @@ -40,7 +42,6 @@ import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.drawer.CategoryKey; import java.text.NumberFormat; import java.util.ArrayList; Loading Loading @@ -251,9 +252,17 @@ public class SoundSettings extends DashboardFragment { AudioManager.STREAM_RING) / maxVolume); resId = R.string.sound_settings_summary; } final ComponentName suppressor = NotificationManager.from(mContext) .getEffectsSuppressor(); if (suppressor != null) { String suppressText = SuppressorHelper.getSuppressionText(mContext, suppressor); mSummaryLoader.setSummary(this, suppressText); } else { mSummaryLoader.setSummary(this, mContext.getString(resId, percent)); } } } public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY = new SummaryLoader.SummaryProviderFactory() { Loading src/com/android/settings/notification/SuppressorHelper.java 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * 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.notification; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.support.annotation.VisibleForTesting; import android.util.Log; public class SuppressorHelper { private static final String TAG = "SuppressorHelper"; public static String getSuppressionText(Context context, ComponentName suppressor) { return suppressor != null ? context.getString(com.android.internal.R.string.muted_by, getSuppressorCaption(context, suppressor)) : null; } @VisibleForTesting static String getSuppressorCaption(Context context, ComponentName suppressor) { final PackageManager pm = context.getPackageManager(); try { final ServiceInfo info = pm.getServiceInfo(suppressor, 0); if (info != null) { final CharSequence seq = info.loadLabel(pm); if (seq != null) { final String str = seq.toString().trim(); if (str.length() > 0) { return str; } } } } catch (Throwable e) { Log.w(TAG, "Error loading suppressor caption", e); } return suppressor.getPackageName(); } } tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * 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.notification; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; public class SuppressorHelperTest { private static final String SUPPRESSOR_NAME = "wear"; private ComponentName mSuppressor; @Mock private Context mContext; @Mock private PackageManager mPackageManager; @Mock private ServiceInfo mServiceInfo; @Before public void setUp() { MockitoAnnotations.initMocks(this); mSuppressor = new ComponentName("", ""); try { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mPackageManager.getServiceInfo(mSuppressor, 0)).thenReturn(mServiceInfo); when(mServiceInfo.loadLabel(mPackageManager)).thenReturn(new String(SUPPRESSOR_NAME)); } catch (PackageManager.NameNotFoundException e) { // Do nothing. This exception will never happen in mock } } @Test public void testGetSuppressionText_SuppressorNull_ReturnNull() { String text = SuppressorHelper.getSuppressionText(mContext, null); assertThat(text).isNull(); } @Test public void testGetSuppressorCaption_SuppressorNotNull_ReturnSuppressorName() { String text = SuppressorHelper.getSuppressorCaption(mContext, mSuppressor); assertThat(text).isEqualTo(SUPPRESSOR_NAME); } } Loading
src/com/android/settings/notification/RingVolumePreferenceController.java +1 −22 Original line number Diff line number Diff line Loading @@ -119,9 +119,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr if (Objects.equals(suppressor, mSuppressor)) return; mSuppressor = suppressor; if (mPreference != null) { final String text = suppressor != null ? mContext.getString(com.android.internal.R.string.muted_by, getSuppressorCaption(suppressor)) : null; final String text = SuppressorHelper.getSuppressionText(mContext, suppressor); mPreference.setSuppressionText(text); } updatePreferenceIcon(); Loading @@ -137,25 +135,6 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr } } private String getSuppressorCaption(ComponentName suppressor) { final PackageManager pm = mContext.getPackageManager(); try { final ServiceInfo info = pm.getServiceInfo(suppressor, 0); if (info != null) { final CharSequence seq = info.loadLabel(pm); if (seq != null) { final String str = seq.toString().trim(); if (str.length() > 0) { return str; } } } } catch (Throwable e) { Log.w(TAG, "Error loading suppressor caption", e); } return suppressor.getPackageName(); } private final class H extends Handler { private static final int UPDATE_EFFECTS_SUPPRESSOR = 1; private static final int UPDATE_RINGER_MODE = 2; Loading
src/com/android/settings/notification/SoundSettings.java +11 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.settings.notification; import android.app.Activity; import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; Loading @@ -40,7 +42,6 @@ import com.android.settings.core.lifecycle.Lifecycle; import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.drawer.CategoryKey; import java.text.NumberFormat; import java.util.ArrayList; Loading Loading @@ -251,9 +252,17 @@ public class SoundSettings extends DashboardFragment { AudioManager.STREAM_RING) / maxVolume); resId = R.string.sound_settings_summary; } final ComponentName suppressor = NotificationManager.from(mContext) .getEffectsSuppressor(); if (suppressor != null) { String suppressText = SuppressorHelper.getSuppressionText(mContext, suppressor); mSummaryLoader.setSummary(this, suppressText); } else { mSummaryLoader.setSummary(this, mContext.getString(resId, percent)); } } } public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY = new SummaryLoader.SummaryProviderFactory() { Loading
src/com/android/settings/notification/SuppressorHelper.java 0 → 100644 +55 −0 Original line number Diff line number Diff line /* * 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.notification; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.support.annotation.VisibleForTesting; import android.util.Log; public class SuppressorHelper { private static final String TAG = "SuppressorHelper"; public static String getSuppressionText(Context context, ComponentName suppressor) { return suppressor != null ? context.getString(com.android.internal.R.string.muted_by, getSuppressorCaption(context, suppressor)) : null; } @VisibleForTesting static String getSuppressorCaption(Context context, ComponentName suppressor) { final PackageManager pm = context.getPackageManager(); try { final ServiceInfo info = pm.getServiceInfo(suppressor, 0); if (info != null) { final CharSequence seq = info.loadLabel(pm); if (seq != null) { final String str = seq.toString().trim(); if (str.length() > 0) { return str; } } } } catch (Throwable e) { Log.w(TAG, "Error loading suppressor caption", e); } return suppressor.getPackageName(); } }
tests/robotests/src/com/android/settings/notification/SuppressorHelperTest.java 0 → 100644 +66 −0 Original line number Diff line number Diff line /* * 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.notification; import android.content.ComponentName; import android.content.Context; import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; public class SuppressorHelperTest { private static final String SUPPRESSOR_NAME = "wear"; private ComponentName mSuppressor; @Mock private Context mContext; @Mock private PackageManager mPackageManager; @Mock private ServiceInfo mServiceInfo; @Before public void setUp() { MockitoAnnotations.initMocks(this); mSuppressor = new ComponentName("", ""); try { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mPackageManager.getServiceInfo(mSuppressor, 0)).thenReturn(mServiceInfo); when(mServiceInfo.loadLabel(mPackageManager)).thenReturn(new String(SUPPRESSOR_NAME)); } catch (PackageManager.NameNotFoundException e) { // Do nothing. This exception will never happen in mock } } @Test public void testGetSuppressionText_SuppressorNull_ReturnNull() { String text = SuppressorHelper.getSuppressionText(mContext, null); assertThat(text).isNull(); } @Test public void testGetSuppressorCaption_SuppressorNotNull_ReturnSuppressorName() { String text = SuppressorHelper.getSuppressorCaption(mContext, mSuppressor); assertThat(text).isEqualTo(SUPPRESSOR_NAME); } }