Settings: Phone ringtone setting for Multi SIM device [2/3]

Support displaying phone ringtone setting for each slot as follows:
"Phone ringtone - SIM 1"
"Phone ringtone - SIM 2"

The purpose is to distinguish incoming call from each slot by ringtone.

Depends-On: I9c6ccff938122332d222853d469ad9a623c7d193

Bug: 118735436
Test: Manual
Change-Id: I06c59016e9b6da51ed8a4678a66674fc48c20e40
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
Ting Yu
2018-10-18 16:56:22 +08:00
committed by Joey
parent 58864d1c1e
commit a89d02598f
12 changed files with 285 additions and 12 deletions

View File

@@ -240,4 +240,7 @@
<string name="incall_vibrate_connect_title">Vibrate on connect</string>
<string name="incall_vibrate_call_wait_title">Vibrate on call waiting</string>
<string name="incall_vibrate_disconnect_title">Vibrate on disconnect</string>
<!-- Label for a numbered SIM card. [CHAR LIMIT=40] -->
<string name="sim_card_number_title" translatable="false">SIM <xliff:g id="card_number">%1$d</xliff:g></string>
</resources>

View File

@@ -8417,6 +8417,12 @@ Data usage charges may apply.</string>
<!-- Sound: Title for the option defining the phone ringtone. [CHAR LIMIT=30] -->
<string name="ringtone_title">Phone ringtone</string>
<!-- Sound: Title for the option defining the phone ringtone for slot1 on Muilti SIM device. [CHAR LIMIT=50] -->
<string name="ringtone1_title">Phone ringtone - SIM 1</string>
<!-- Sound: Title for the option defining the phone ringtone for slot2 on Muilti SIM device. [CHAR LIMIT=50] -->
<string name="ringtone2_title">Phone ringtone - SIM 2</string>
<!-- Sound: Title for the option defining the default notification sound. [CHAR LIMIT=30] -->
<string name="notification_ringtone_title">Default notification sound</string>

View File

@@ -116,6 +116,16 @@
android:order="-120"
settings:keywords="@string/sound_settings"/>
<!-- Phone ringtone for Slot2 -->
<com.android.settings.DefaultRingtonePreference
android:key="ringtone2"
android:title="@string/ringtone2_title"
android:dialogTitle="@string/ringtone_title"
android:summary="@string/summary_placeholder"
android:ringtoneType="ringtone"
android:order="-119"
settings:keywords="@string/sound_settings"/>
<!-- Live Caption -110 and Now Playing -105-->
<!-- Spatial audio -->

View File

@@ -62,12 +62,14 @@ public class DefaultRingtonePreference extends RingtonePreference {
@VisibleForTesting
void setActualDefaultRingtoneUri(Uri ringtoneUri) {
RingtoneManager.setActualDefaultRingtoneUri(mUserContext, getRingtoneType(), ringtoneUri);
RingtoneManager.setActualDefaultRingtoneUriBySlot(mUserContext, getRingtoneType(),
ringtoneUri, getSlotId());
}
@Override
protected Uri onRestoreRingtone() {
return RingtoneManager.getActualDefaultRingtoneUri(mUserContext, getRingtoneType());
return RingtoneManager.getActualDefaultRingtoneUriBySlot(mUserContext, getRingtoneType(),
getSlotId());
}
}

View File

@@ -40,6 +40,7 @@ import androidx.preference.PreferenceManager;
* <p>
* If the user chooses the "Default" item, the saved string will be one of
* {@link System#DEFAULT_RINGTONE_URI},
* {@link System#DEFAULT_RINGTONE2_URI},
* {@link System#DEFAULT_NOTIFICATION_URI}, or
* {@link System#DEFAULT_ALARM_ALERT_URI}. If the user chooses the "Silent"
* item, the saved string will be an empty string.
@@ -56,6 +57,9 @@ public class RingtonePreference extends Preference {
private static final String TAG = "RingtonePreference";
private static final String GOOGLE_SP_PKG_NAME = "com.google.android.soundpicker";
// Default is slot0
private int mSlotId = 0;
private int mRingtoneType;
private boolean mShowDefault;
private boolean mShowSilent;
@@ -97,6 +101,25 @@ public class RingtonePreference extends Preference {
return mUserId;
}
/**
* Sets the slot id that this preference belongs to.
*
* @param slotId The slot id that this preference belongs to.
*/
public void setSlotId(int slotId) {
mSlotId = slotId;
}
/**
* Returns the slot id that this preference belongs to.
*
* @return The slot id that this preference belongs to.
* @see #setSlotId(int)
*/
public int getSlotId() {
return mSlotId;
}
/**
* Returns the sound type(s) that are shown in the picker.
*
@@ -175,7 +198,7 @@ public class RingtonePreference extends Preference {
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
if (mShowDefault) {
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
RingtoneManager.getDefaultUri(getRingtoneType()));
RingtoneManager.getDefaultUriBySlot(getRingtoneType(), getSlotId()));
}
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2018 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.Context;
import android.media.RingtoneManager;
import android.telephony.TelephonyManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.Utils;
public class PhoneRingtone2PreferenceController extends RingtonePreferenceControllerBase {
private static final int SLOT_ID = 1;
private static final String KEY_PHONE_RINGTONE2 = "ringtone2";
public PhoneRingtone2PreferenceController(Context context) {
super(context);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
DefaultRingtonePreference ringtonePreference =
(DefaultRingtonePreference) screen.findPreference(KEY_PHONE_RINGTONE2);
ringtonePreference.setSlotId(SLOT_ID);
}
@Override
public String getPreferenceKey() {
return KEY_PHONE_RINGTONE2;
}
@Override
public boolean isAvailable() {
TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
return Utils.isVoiceCapable(mContext) && telephonyManager.isMultiSimEnabled();
}
@Override
public int getRingtoneType() {
return RingtoneManager.TYPE_RINGTONE;
}
}

View File

@@ -20,6 +20,13 @@ import android.content.Context;
import android.media.RingtoneManager;
import android.media.audio.Flags;
import android.telephony.TelephonyManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.R;
import com.android.settings.Utils;
public class PhoneRingtonePreferenceController extends RingtonePreferenceControllerBase {
@@ -30,6 +37,20 @@ public class PhoneRingtonePreferenceController extends RingtonePreferenceControl
super(context);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.isMultiSimEnabled()) {
// For Multi SIM device, shoud show "Phone ringtone - SIM 1" for slot1 ringtone setting.
DefaultRingtonePreference ringtonePreference =
(DefaultRingtonePreference) screen.findPreference(KEY_PHONE_RINGTONE);
ringtonePreference.setTitle(mContext.getString(R.string.ringtone1_title));
}
}
@Override
public String getPreferenceKey() {
return KEY_PHONE_RINGTONE;

View File

@@ -24,6 +24,7 @@ import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.RingtonePreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.utils.ThreadUtils;
@@ -51,8 +52,8 @@ public abstract class RingtonePreferenceControllerBase extends AbstractPreferenc
}
private void updateSummary(Preference preference) {
final Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(
mContext, getRingtoneType());
final Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUriBySlot(mContext,
getRingtoneType(), ((RingtonePreference)preference).getSlotId());
final CharSequence summary;
try {

View File

@@ -273,6 +273,7 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
// === Phone & notification ringtone ===
controllers.add(new PhoneRingtonePreferenceController(context));
controllers.add(new PhoneRingtone2PreferenceController(context));
controllers.add(new AlarmRingtonePreferenceController(context));
controllers.add(new NotificationRingtonePreferenceController(context));

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2018 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 static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.media.RingtoneManager;
import android.telephony.TelephonyManager;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
public class PhoneRingtone2PreferenceControllerTest {
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private DefaultRingtonePreference mPreference;
private Context mContext;
private PhoneRingtone2PreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowContext = ShadowApplication.getInstance();
shadowContext.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
mContext = RuntimeEnvironment.application;
mController = new PhoneRingtone2PreferenceController(mContext);
}
@Test
public void displayPreference_shouldSetSlotId() {
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
verify(mPreference).setSlotId(1);
}
@Test
public void isAvailable_notVoiceCapable_shouldReturnFalse() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_notMultiSimEnabled_shouldReturnFalse() {
when(mTelephonyManager.isMultiSimEnabled()).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_VoiceCapable_and_MultiSimEnabled_shouldReturnTrue() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
when(mTelephonyManager.isMultiSimEnabled()).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void getRingtoneType_shouldReturnRingtone() {
assertThat(mController.getRingtoneType()).isEqualTo(RingtoneManager.TYPE_RINGTONE);
}
}

View File

@@ -18,6 +18,7 @@ package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -29,6 +30,10 @@ import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.telephony.TelephonyManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.DefaultRingtonePreference;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Rule;
@@ -43,6 +48,10 @@ public class PhoneRingtonePreferenceControllerTest {
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private PreferenceScreen mPreferenceScreen;
@Mock
private DefaultRingtonePreference mPreference;
@Mock
private Context mMockContext;
@@ -64,6 +73,16 @@ public class PhoneRingtonePreferenceControllerTest {
mController = new PhoneRingtonePreferenceController(mMockContext);
}
@Test
public void displayPreference_shouldUpdateTitle_for_MultiSimDevice() {
when(mTelephonyManager.isMultiSimEnabled()).thenReturn(true);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
.thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
verify(mPreference).setTitle(mContext.getString(R.string.ringtone1_title));
}
@Test
@DisableFlags(Flags.FLAG_ENABLE_RINGTONE_HAPTICS_CUSTOMIZATION)
public void isAvailable_notVoiceCapable_shouldReturnFalse() {

View File

@@ -21,6 +21,7 @@ import android.os.SystemClock;
import android.provider.Settings;
import android.system.helpers.SettingsHelper;
import android.system.helpers.SettingsHelper.SettingsType;
import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
import androidx.test.filters.MediumTest;
@@ -42,6 +43,7 @@ public class SoundSettingsTest extends InstrumentationTestCase {
private UiDevice mDevice;
private ContentResolver mResolver;
private SettingsHelper mHelper;
private TelephonyManager mTelephonyManager;
private final Map<String, String> ringtoneSounds = Map.of(
@@ -100,6 +102,8 @@ public class SoundSettingsTest extends InstrumentationTestCase {
mDevice.setOrientationNatural();
mResolver = getInstrumentation().getContext().getContentResolver();
mHelper = new SettingsHelper();
mTelephonyManager = (TelephonyManager) getInstrumentation().getContext()
.getSystemService(Context.TELEPHONY_SERVICE);
}
@Override
@@ -174,26 +178,49 @@ public class SoundSettingsTest extends InstrumentationTestCase {
public void testPhoneRingtoneNone() throws Exception {
launchSoundSettings();
mHelper.clickSetting("Phone ringtone");
verifyRingtone(new RingtoneSetting("None", "null"),
Settings.System.RINGTONE);
if (mTelephonyManager.isMultiSimEnabled()) {
mHelper.clickSetting("Phone ringtone - SIM 1");
verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE);
mHelper.clickSetting("Phone ringtone - SIM 2");
verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE2);
} else {
mHelper.clickSetting("Phone ringtone");
verifyRingtone(new RingtoneSetting("None", "null"), Settings.System.RINGTONE);
}
}
@MediumTest
@Suppress
public void testPhoneRingtoneHangouts() throws Exception {
launchSoundSettings();
mHelper.clickSetting("Phone ringtone");
verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE);
if (mTelephonyManager.isMultiSimEnabled()) {
mHelper.clickSetting("Phone ringtone - SIM 1");
verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE);
mHelper.clickSetting("Phone ringtone - SIM 2");
verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE2);
} else {
mHelper.clickSetting("Phone ringtone");
verifyRingtone(new RingtoneSetting("Hangouts Call", "31"), Settings.System.RINGTONE);
}
}
@MediumTest
public void testPhoneRingtone() throws Exception {
launchSoundSettings();
mHelper.clickSetting("Phone ringtone");
String ringtone = ringtoneSounds.get(mDevice.getProductName()).toString();
String ringtoneSettingValue = ringtoneCodes.get(mDevice.getProductName()).toString();
verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue),
Settings.System.RINGTONE);
if (mTelephonyManager.isMultiSimEnabled()) {
mHelper.clickSetting("Phone ringtone - SIM 1");
verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue),
Settings.System.RINGTONE);
mHelper.clickSetting("Phone ringtone - SIM 2");
verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue),
Settings.System.RINGTONE2);
} else {
mHelper.clickSetting("Phone ringtone");
verifyRingtone(new RingtoneSetting(ringtone, ringtoneSettingValue),
Settings.System.RINGTONE);
}
}
@MediumTest