Change ringtone behavior based on version.

Bug: 12800232
Change-Id: I9e05d737a847392c277d50a353e4d65ecd70f9a2
diff --git a/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java b/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java
index 58e6f26..4a180ef 100644
--- a/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java
+++ b/tests/src/com/android/contacts/editor/EditorUiUtilsTest.java
@@ -21,6 +21,10 @@
 import com.android.contacts.common.model.account.GoogleAccountType;
 
 import android.content.Context;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Build;
+import android.provider.Settings;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
 import android.util.Pair;
@@ -37,6 +41,8 @@
     private static final String GOOGLE_ACCOUNT_NAME = "somebody@gmail.com";
     private static final String GOOGLE_DISPLAY_LABEL = "Google";
 
+    private static final String RINGTONE = "content://media/external/audio/media/31";
+
     private static final class MockAccountType extends AccountType {
 
         private final String mDisplayLabel;
@@ -140,4 +146,41 @@
                         getContext().getString(R.string.account_phone)),
                 pair.second); // "Phone-only, unsynced contact"
     }
+
+    public void testGetRingtongStrFromUri_lessThanOrEqualsToM() {
+        final int currentVersion = Build.VERSION_CODES.M;
+        assertNull(EditorUiUtils.getRingtoneStringFromUri(null, currentVersion));
+        assertNull(EditorUiUtils.getRingtoneStringFromUri(Settings.System.DEFAULT_RINGTONE_URI,
+                currentVersion));
+        assertEquals(RINGTONE, EditorUiUtils.getRingtoneStringFromUri(Uri.parse(RINGTONE),
+                        currentVersion));
+    }
+
+    public void testGetRingtongStrFromUri_nOrGreater() {
+        final int currentVersion = Build.VERSION_CODES.M + 1;
+        assertEquals("", EditorUiUtils.getRingtoneStringFromUri(null, currentVersion));
+        assertNull(EditorUiUtils.getRingtoneStringFromUri(Settings.System.DEFAULT_RINGTONE_URI,
+                currentVersion));
+        assertEquals(RINGTONE, EditorUiUtils.getRingtoneStringFromUri(Uri.parse(RINGTONE),
+                        currentVersion));
+    }
+
+    public void testGetRingtongUriFromStr_lessThanOrEqualsToM() {
+        final int currentVersion = Build.VERSION_CODES.M;
+        assertEquals(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), EditorUiUtils
+                        .getRingtoneUriFromString(null, currentVersion));
+        assertEquals(Uri.parse(""), EditorUiUtils.getRingtoneUriFromString("", currentVersion));
+        assertEquals(Uri.parse(RINGTONE), EditorUiUtils.getRingtoneUriFromString(RINGTONE,
+                currentVersion));
+    }
+
+    public void testGetRingtongUriFromStr_nOrGreater() {
+        final int currentVersion = Build.VERSION_CODES.M + 1;
+        assertEquals(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE), EditorUiUtils
+                        .getRingtoneUriFromString(null, currentVersion));
+        assertNull(EditorUiUtils.getRingtoneUriFromString("", currentVersion));
+        assertEquals(Uri.parse(RINGTONE), EditorUiUtils.getRingtoneUriFromString(RINGTONE,
+                currentVersion));
+    }
+
 }