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:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user