buildPreferenceControllers(
controllers.add(new AccentPickerPreferenceController(context, lifecycle, fragment));
controllers.add(new CameraGesturePreferenceController(context));
controllers.add(new DarkUIPreferenceController(context));
+ controllers.add(mFontPickerPreference = new FontPickerPreferenceController(context, lifecycle, fragment));
controllers.add(new LiftToWakePreferenceController(context));
controllers.add(new NightDisplayPreferenceController(context));
controllers.add(new NightModePreferenceController(context));
diff --git a/src/com/android/settings/RingtonePreference.java b/src/com/android/settings/RingtonePreference.java
index 52ab65bd44..0a29a6dc90 100644
--- a/src/com/android/settings/RingtonePreference.java
+++ b/src/com/android/settings/RingtonePreference.java
@@ -35,6 +35,7 @@
*
* 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.
@@ -50,6 +51,9 @@ public class RingtonePreference extends Preference {
private static final String TAG = "RingtonePreference";
+ // Default is slot0
+ private int mSlotId = 0;
+
private int mRingtoneType;
private boolean mShowDefault;
private boolean mShowSilent;
@@ -83,6 +87,25 @@ public int getUserId() {
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.
*
@@ -161,7 +184,7 @@ public void onPrepareRingtonePickerIntent(Intent ringtonePickerIntent) {
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);
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 991e94432c..208ca6205d 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -184,7 +184,6 @@ public static class AmbientDisplayActivity extends SettingsActivity { /* empty *
public static class AmbientPlayActivity extends SettingsActivity { /* empty */ }
public static class NavigationActivity extends SettingsActivity { /* empty */ }
public static class SmartPixelsActivity extends SettingsActivity { /* empty */ }
- public static class WeatherActivity extends SettingsActivity { /* empty */ }
public static class ScreenActivity extends SettingsActivity { /* empty */ }
public static class ExpandedDesktopActivity extends SettingsActivity { /* empty */ }
public static class RotationActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index cbf37a1c9a..67f6b569e9 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -149,7 +149,6 @@
import com.liquid.liquidlounge.fragments.HeadsUpSettings;
import com.liquid.liquidlounge.fragments.NavigationSettings;
import com.liquid.liquidlounge.fragments.SmartPixels;
-import com.liquid.liquidlounge.fragments.WeatherSettings;
import com.liquid.liquidlounge.fragments.PieSettings;
public class SettingsGateway {
@@ -285,7 +284,6 @@ public class SettingsGateway {
AmbientPlaySettings.class.getName(),
NavigationSettings.class.getName(),
SmartPixels.class.getName(),
- WeatherSettings.class.getName(),
ExpandedDesktopPreferenceFragment.class.getName(),
DisplayRotation.class.getName(),
AmbientPlayHistory.class.getName(),
diff --git a/src/com/android/settings/display/FontDialogPreference.java b/src/com/android/settings/display/FontDialogPreference.java
new file mode 100644
index 0000000000..f3c53d6533
--- /dev/null
+++ b/src/com/android/settings/display/FontDialogPreference.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 The Dirty Unicorns 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.
+ *
+ * preference for managing custom fonts
+ */
+package com.android.settings.display;
+
+import android.app.AlertDialog.Builder;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.FontInfo;
+import android.content.IFontService;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.util.AttributeSet;
+
+import com.android.settings.R;
+import com.android.settingslib.CustomDialogPreference;
+
+public class FontDialogPreference extends CustomDialogPreference {
+ private static final String TAG = "FontDialogPreference";
+ private Context mContext;
+ private IFontService mFontService;
+ private ProgressDialog mProgressDialog;
+ public FontDialogPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mContext = context;
+ mFontService = IFontService.Stub.asInterface(
+ ServiceManager.getService("liquidfont"));
+ }
+ @Override
+ protected void onPrepareDialogBuilder(Builder builder,
+ DialogInterface.OnClickListener listener) {
+ super.onPrepareDialogBuilder(builder, listener);
+ FontListAdapter adapter = new FontListAdapter(mContext);
+ DialogInterface.OnClickListener l = new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ FontInfo info = adapter.getItem(which);
+ try {
+ startProgress();
+ mFontService.applyFont(info);
+ } catch (RemoteException e) {
+ startProgress();
+ }
+ }
+ };
+ builder.setIcon(R.drawable.font_dialog_icon);
+ builder.setAdapter(adapter, l);
+ builder.setCancelable(false);
+ builder.setNegativeButton(mContext.getString(com.android.internal.R.string.cancel),
+ listener);
+ }
+ @Override
+ protected void onClick(DialogInterface dialog, int which) {
+ if (which == DialogInterface.BUTTON_NEGATIVE) {
+ dialog.dismiss();
+ }
+ }
+ private void startProgress() {
+ if(mProgressDialog != null) {
+ stopProgress();
+ }
+ mProgressDialog = new ProgressDialog(mContext);
+ mProgressDialog.setIndeterminate(true);
+ mProgressDialog.setTitle(mContext.getString(R.string.font_picker_title));
+ mProgressDialog.setMessage(mContext.getString(R.string.font_picker_progress));
+ mProgressDialog.setCancelable(false);
+ mProgressDialog.setCanceledOnTouchOutside(false);
+ mProgressDialog.show();
+ }
+ public void stopProgress() {
+ if (mProgressDialog != null) {
+ mProgressDialog.dismiss();
+ mProgressDialog = null;
+ }
+ }
+}
diff --git a/src/com/android/settings/display/FontListAdapter.java b/src/com/android/settings/display/FontListAdapter.java
new file mode 100644
index 0000000000..ddf10a9427
--- /dev/null
+++ b/src/com/android/settings/display/FontListAdapter.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2018 The Dirty Unicorns 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.
+ *
+ * Adapter for displaying a list of custom fonts with font Typeface
+ */
+package com.android.settings.display;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import com.android.settings.R;
+import android.content.Context;
+import android.content.FontInfo;
+import android.content.IFontService;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+public class FontListAdapter extends BaseAdapter {
+ private static final String TAG = "FontListAdapter";
+ private IFontService mFontService;
+ private List mFontInfo = new ArrayList();
+ private Context mContext;
+ private LayoutInflater mInflater;
+ private PackageManager mPm;
+ public FontListAdapter(Context context) {
+ mContext = context;
+ mInflater = LayoutInflater.from(context);
+ mFontService = IFontService.Stub.asInterface(
+ ServiceManager.getService("liquidfont"));
+ mPm = context.getPackageManager();
+ loadFontList();
+ }
+ public void loadFontList() {
+ mFontInfo.clear();
+ try {
+ Map> fontMap = mFontService.getAllFonts();
+ for (Map.Entry> entry : fontMap.entrySet()) {
+ String packageName = entry.getKey();
+ List fonts = entry.getValue();
+ // manually add system font after we sort
+ if (TextUtils.equals(packageName, FontInfo.DEFAULT_FONT_PACKAGE)) {
+ continue;
+ }
+ for (FontInfo font : fonts) {
+ mFontInfo.add(new FontInfo(font));
+ }
+ }
+ Collections.sort(mFontInfo);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error in populating list");
+ }
+ mFontInfo.add(0, FontInfo.getDefaultFontInfo());
+ notifyDataSetChanged();
+ }
+ @Override
+ public int getCount() {
+ return mFontInfo.size();
+ }
+ @Override
+ public FontInfo getItem(int position) {
+ return mFontInfo.get(position);
+ }
+ @Override
+ public long getItemId(int position) {
+ return 0;
+ }
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ final Context ctx = mContext;
+ if (convertView != null) {
+ holder = (ViewHolder) convertView.getTag();
+ } else {
+ convertView = mInflater.inflate(R.layout.font_item, null, false);
+ holder = new ViewHolder();
+ convertView.setTag(holder);
+ holder.title = (TextView) convertView.findViewById(com.android.internal.R.id.title);
+ holder.summary = (TextView) convertView
+ .findViewById(com.android.internal.R.id.summary);
+ holder.icon = (ImageView) convertView.findViewById(R.id.icon);
+ }
+ FontInfo info = getItem(position);
+ Typeface.Builder builder = new Typeface.Builder(info.previewPath);
+ Typeface tf = builder.build();
+ holder.title.setTypeface(tf);
+ holder.title.setText(info.fontName.replace("_", " "));
+ holder.summary.setTypeface(tf);
+ holder.summary.setText(getPackageLabel(info.packageName).replace("_", " "));
+ holder.icon.setImageDrawable(getPackageDrawable(info.packageName));
+ return convertView;
+ }
+ private String getPackageLabel(String packageName) {
+ String label = null;
+ if (packageName.equals("android")) {
+ return "Android";
+ }
+ try {
+ ApplicationInfo info = mPm.getApplicationInfo(packageName, 0);
+ label = (String) info.loadLabel(mPm);
+ } finally {
+ return label;
+ }
+ }
+ private Drawable getPackageDrawable(String packageName) {
+ Drawable icon = null;
+ try {
+ ApplicationInfo info = mPm.getApplicationInfo(packageName, 0);
+ icon = info.loadIcon(mPm);
+ } finally {
+ return icon;
+ }
+ }
+ private static class ViewHolder {
+ TextView title;
+ TextView summary;
+ ImageView icon;
+ }
+}
diff --git a/src/com/android/settings/display/FontPickerPreferenceController.java b/src/com/android/settings/display/FontPickerPreferenceController.java
new file mode 100644
index 0000000000..43780255f4
--- /dev/null
+++ b/src/com/android/settings/display/FontPickerPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2017 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.display;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.content.FontInfo;
+import android.content.IFontService;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class FontPickerPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, LifecycleObserver, OnResume {
+ private static final String TAG = "FontPickerPreferenceController";
+ private static final String KEY_FONT_PICKER_FRAGMENT_PREF = "custom_font";
+ private FontDialogPreference mFontPreference;
+ private IFontService mFontService;
+ public FontPickerPreferenceController(Context context, Lifecycle lifecycle, Fragment parent) {
+ super(context);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ mFontService = IFontService.Stub.asInterface(
+ ServiceManager.getService("liquidfont"));
+ }
+ @Override
+ public void onResume() {
+ if (mFontPreference == null) {
+ return;
+ }
+ mFontPreference.setSummary(getCurrentFontInfo().fontName.replace("_", " "));
+ }
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ mFontPreference = (FontDialogPreference) screen.findPreference(KEY_FONT_PICKER_FRAGMENT_PREF);
+ mFontPreference.setEnabled(true);
+ }
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+ @Override
+ public String getPreferenceKey() {
+ return KEY_FONT_PICKER_FRAGMENT_PREF;
+ }
+ private FontInfo getCurrentFontInfo() {
+ try {
+ return mFontService.getFontInfo();
+ } catch (RemoteException e) {
+ return FontInfo.getDefaultFontInfo();
+ }
+ }
+ public void stopProgress() {
+ mFontPreference.stopProgress();
+ }
+}
diff --git a/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java b/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java
new file mode 100644
index 0000000000..a48590b6cf
--- /dev/null
+++ b/src/com/android/settings/notification/PhoneRingtone2PreferenceController.java
@@ -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 android.support.v7.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;
+ }
+}
diff --git a/src/com/android/settings/notification/PhoneRingtonePreferenceController.java b/src/com/android/settings/notification/PhoneRingtonePreferenceController.java
index cb1115165f..6c7a8f0e39 100644
--- a/src/com/android/settings/notification/PhoneRingtonePreferenceController.java
+++ b/src/com/android/settings/notification/PhoneRingtonePreferenceController.java
@@ -18,6 +18,12 @@
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.R;
import com.android.settings.Utils;
public class PhoneRingtonePreferenceController extends RingtonePreferenceControllerBase {
@@ -28,6 +34,20 @@ public PhoneRingtonePreferenceController(Context context) {
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;
diff --git a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
index 09a47b7d30..d02273862a 100644
--- a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
+++ b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
@@ -22,6 +22,7 @@
import android.net.Uri;
import android.support.v7.preference.Preference;
+import com.android.settings.RingtonePreference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -44,7 +45,8 @@ public boolean isAvailable() {
@Override
public void updateState(Preference preference) {
- Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, getRingtoneType());
+ Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUriBySlot(mContext,
+ getRingtoneType(), ((RingtonePreference)preference).getSlotId());
final CharSequence summary = Ringtone.getTitle(
mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
if (summary != null) {
diff --git a/src/com/android/settings/notification/SoundSettings.java b/src/com/android/settings/notification/SoundSettings.java
index 4e68b7e957..49325a13c8 100644
--- a/src/com/android/settings/notification/SoundSettings.java
+++ b/src/com/android/settings/notification/SoundSettings.java
@@ -269,6 +269,7 @@ private static List buildPreferenceControllers(Con
// === Phone & notification ringtone ===
controllers.add(new PhoneRingtonePreferenceController(context));
+ controllers.add(new PhoneRingtone2PreferenceController(context));
controllers.add(new AlarmRingtonePreferenceController(context));
controllers.add(new NotificationRingtonePreferenceController(context));
controllers.add(new IncreasingRingPreferenceController(context));
diff --git a/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java
new file mode 100644
index 0000000000..87fa6a5038
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/PhoneRingtone2PreferenceControllerTest.java
@@ -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);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
index 98cbc76dc5..425ace3e46 100644
--- a/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/PhoneRingtonePreferenceControllerTest.java
@@ -17,12 +17,18 @@
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.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -38,6 +44,10 @@ public class PhoneRingtonePreferenceControllerTest {
@Mock
private TelephonyManager mTelephonyManager;
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+ @Mock
+ private DefaultRingtonePreference mPreference;
private Context mContext;
private PhoneRingtonePreferenceController mController;
@@ -51,6 +61,16 @@ public void setUp() {
mController = new PhoneRingtonePreferenceController(mContext);
}
+ @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
public void isAvailable_notVoiceCapable_shouldReturnFalse() {
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
diff --git a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
index 0aec505185..742ea4952b 100644
--- a/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
+++ b/tests/uitests/src/com/android/settings/ui/SoundSettingsTest.java
@@ -29,6 +29,7 @@
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.Until;
+import android.telephony.TelephonyManager;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.Suppress;
@@ -42,6 +43,7 @@ public class SoundSettingsTest extends InstrumentationTestCase {
private UiDevice mDevice;
private ContentResolver mResolver;
private SettingsHelper mHelper;
+ private TelephonyManager mTelephonyManager;
private HashMap ringtoneSounds = new HashMap() {{
@@ -106,6 +108,8 @@ public void setUp() throws Exception {
mDevice.setOrientationNatural();
mResolver = getInstrumentation().getContext().getContentResolver();
mHelper = new SettingsHelper();
+ mTelephonyManager = (TelephonyManager) getInstrumentation().getContext()
+ .getSystemService(Context.TELEPHONY_SERVICE);
}
@Override
@@ -187,27 +191,49 @@ private void launchSoundSettings() throws Exception {
@MediumTest
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