Merge "[Settings] Fix inconsistent ringtone keyword search" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
8ff5f0cfc5
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
import android.media.audio.Flags;
|
||||||
|
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
|
|
||||||
@@ -36,6 +37,9 @@ public class PhoneRingtonePreferenceController extends RingtonePreferenceControl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
|
if (isRingtoneVibrationEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return Utils.isVoiceCapable(mContext);
|
return Utils.isVoiceCapable(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,4 +47,9 @@ public class PhoneRingtonePreferenceController extends RingtonePreferenceControl
|
|||||||
public int getRingtoneType() {
|
public int getRingtoneType() {
|
||||||
return RingtoneManager.TYPE_RINGTONE;
|
return RingtoneManager.TYPE_RINGTONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isRingtoneVibrationEnabled() {
|
||||||
|
return Flags.enableRingtoneHapticsCustomization() && mContext.getResources().getBoolean(
|
||||||
|
com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,17 +21,22 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
import android.media.audio.Flags;
|
||||||
|
import android.platform.test.annotations.DisableFlags;
|
||||||
|
import android.platform.test.annotations.EnableFlags;
|
||||||
|
import android.platform.test.flag.junit.SetFlagsRule;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class PhoneRingtonePreferenceControllerTest {
|
public class PhoneRingtonePreferenceControllerTest {
|
||||||
@@ -39,32 +44,59 @@ public class PhoneRingtonePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private Context mContext;
|
@Mock
|
||||||
|
private Context mMockContext;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Resources mMockResources;
|
||||||
|
|
||||||
private PhoneRingtonePreferenceController mController;
|
private PhoneRingtonePreferenceController mController;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
ShadowApplication shadowContext = ShadowApplication.getInstance();
|
when(mMockContext.getResources()).thenReturn(mMockResources);
|
||||||
shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
|
when(mMockContext.getSystemService(
|
||||||
mContext = RuntimeEnvironment.application;
|
Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
mController = new PhoneRingtonePreferenceController(mContext);
|
mController = new PhoneRingtonePreferenceController(mMockContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
|
||||||
public void isAvailable_notVoiceCapable_shouldReturnFalse() {
|
public void isAvailable_notVoiceCapable_shouldReturnFalse() {
|
||||||
|
when(mMockResources
|
||||||
|
.getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
|
||||||
|
.thenReturn(false);
|
||||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isFalse();
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DisableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
|
||||||
public void isAvailable_VoiceCapable_shouldReturnTrue() {
|
public void isAvailable_VoiceCapable_shouldReturnTrue() {
|
||||||
|
when(mMockResources
|
||||||
|
.getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
|
||||||
|
.thenReturn(false);
|
||||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@EnableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
|
||||||
|
public void isAvailable_vibrationSupported_shouldReturnFalse() {
|
||||||
|
when(mMockResources
|
||||||
|
.getBoolean(com.android.internal.R.bool.config_ringtoneVibrationSettingsSupported))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.isAvailable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRingtoneType_shouldReturnRingtone() {
|
public void getRingtoneType_shouldReturnRingtone() {
|
||||||
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE);
|
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE);
|
||||||
|
Reference in New Issue
Block a user