Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c0ac4b6a authored by Karthik Reddy Katta's avatar Karthik Reddy Katta Committed by Ed Carrigan
Browse files

Ringtone: Add support for selection of phone ringtone for SIM-2.

-Issue: "The process android.process.media has stopped" pop up is
 displayed when ringtone for SIM-2 is selected.
-Rootcause: There is no type and URI defined for SIM-2 ringtone
 in the RingtoneManager. This is leading to SQl exception when
 executing a selection query.
-Fix: Add URIs for the SIM-2 and SIM-3 ringtones. Define
 interfaces to return them to app side based on subscription ID.

CRs-Fixed: 612945
Change-Id: If68c2d008dd86d2b55d3fb7f5667bbadc238d0b3
parent e00807af
Loading
Loading
Loading
Loading
+30 −2
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 The Android Open Source Project
 * Copyright (C) 2007, 2014 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.
@@ -50,6 +50,7 @@ public class RingtonePreference extends Preference implements
    private int mDialogStyle;
    
    private int mRequestCode;
    private int mSubscriptionID = 0; /* Sub-1 by default */

    public RingtonePreference(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
@@ -95,6 +96,28 @@ public class RingtonePreference extends Preference implements
        mRingtoneType = type;
    }

    /**
     * Returns the subscription ID.
     *
     * @return The current subscription ID.
     * @see #setSubId(int)
     * @hide
     */
    public int getSubId() {
        return mSubscriptionID;
    }

    /**
     * Sets the subscription ID.
     *
     * @param subId subscription ID.
     * @see #getSubId(int)
     * @hide
     */
    public void setSubId(int subId) {
        mSubscriptionID = subId;
    }

    /**
     * Returns whether to a show an item for the default sound/ringtone.
     * 
@@ -182,9 +205,14 @@ public class RingtonePreference extends Preference implements
        
        ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault);
        if (mShowDefault) {
            if (getRingtoneType() == RingtoneManager.TYPE_RINGTONE) {
                ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultRingtoneUriBySubId(getSubId()));
            } else {
                ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
                    RingtoneManager.getDefaultUri(getRingtoneType()));
            }
        }
        if (mDialogStyle != 0) {
            ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DIALOG_THEME,
                    mDialogStyle);
+58 −1
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013 The Linux Foundation. All rights reserved.
 * Copyright (c) 2013, 2014 The Linux Foundation. All rights reserved.
 * Not a Contribution.
 * Copyright (C) 2006 The Android Open Source Project
 *
@@ -2196,6 +2196,30 @@ public final class Settings {
         */
        public static final String RINGTONE = "ringtone";

        /**
         * Persistent store for the SIM-2 ringtone URI.
         * <p>
         * If you need to play SIM-2 ringtone at any given time, it is recommended
         * you give {@link #DEFAULT_RINGTONE_URI_2} to the media player.  It will resolve
         * to the set default ringtone at the time of playing.
         *
         * @see #DEFAULT_RINGTONE_URI_2
         * @hide
         */
        public static final String RINGTONE_2 = "ringtone_2";

        /**
         * Persistent store for the SIM-3 ringtone URI.
         * <p>
         * If you need to play SIM-3 ringtone at any given time, it is recommended
         * you give {@link #DEFAULT_RINGTONE_URI_3} to the media player.  It will resolve
         * to the set default ringtone at the time of playing.
         *
         * @see #DEFAULT_RINGTONE_URI_3
         * @hide
         */
        public static final String RINGTONE_3 = "ringtone_3";

        /**
         * A {@link Uri} that will point to the current default ringtone at any
         * given time.
@@ -2206,6 +2230,39 @@ public final class Settings {
         */
        public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE);

        /**
         * A {@link Uri} that will point to the current SIM-2 ringtone at any
         * given time.
         * <p>
         * If the current default ringtone is in the DRM provider and the caller
         * does not have permission, the exception will be a
         * FileNotFoundException.
         *
         * @hide
         */
        public static final Uri DEFAULT_RINGTONE_URI_2 = getUriFor(RINGTONE_2);

        /**
         * A {@link Uri} that will point to the current SIM-3 ringtone at any
         * given time.
         * <p>
         * If the current default ringtone is in the DRM provider and the caller
         * does not have permission, the exception will be a
         * FileNotFoundException.
         *
         * @hide
         */
        public static final Uri DEFAULT_RINGTONE_URI_3 = getUriFor(RINGTONE_3);

        /**
         * Maximum number of ringtones supported.
         * <p>
         * Maximum number of ringtones supported by settings. Increment this
         * if a new URI needs to be added for ringtone.
         * @hide
         */
        public static final int MAX_NUM_RINGTONES = 3;

        /**
         * Persistent store for the system-wide default notification sound.
         *
+12 −6
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 * Copyright (C) 2006, 2014 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.
@@ -115,8 +115,14 @@ public class Ringtone {

            if (Settings.AUTHORITY.equals(authority)) {
                if (followSettingsUri) {
                    Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context,
                    Uri actualUri;
                    if (RingtoneManager.getDefaultType(uri) == RingtoneManager.TYPE_RINGTONE) {
                        actualUri = RingtoneManager.getActualRingtoneUriBySubId(context,
                             RingtoneManager.getDefaultRingtoneSubIdByUri(uri));
                    } else {
                        actualUri = RingtoneManager.getActualDefaultRingtoneUri(context,
                             RingtoneManager.getDefaultType(uri));
                    }
                    String actualTitle = getTitle(context, actualUri, false);
                    title = context
                            .getString(com.android.internal.R.string.ringtone_default_with_actual,
@@ -279,9 +285,9 @@ public class Ringtone {

    private boolean playFallbackRingtone() {
        if (mAudioManager.getStreamVolume(mStreamType) != 0) {
            int ringtoneType = RingtoneManager.getDefaultType(mUri);
            if (ringtoneType == -1 ||
                    RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) {
            int subId = RingtoneManager.getDefaultRingtoneSubIdByUri(mUri);
            if (subId != -1 &&
                    RingtoneManager.getActualRingtoneUriBySubId(mContext, subId) != null) {
                // Default ringtone, try fallback ringtone.
                try {
                    AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(
+106 −3
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 The Android Open Source Project
 * Copyright (C) 2007, 2014 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.
@@ -696,7 +696,9 @@ public class RingtoneManager {
    public static int getDefaultType(Uri defaultRingtoneUri) {
        if (defaultRingtoneUri == null) {
            return -1;
        } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
        } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI) ||
            defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI_2) ||
            defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI_3)) {
            return TYPE_RINGTONE;
        } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) {
            return TYPE_NOTIFICATION;
@@ -728,4 +730,105 @@ public class RingtoneManager {
        }
    }

    /**
     * Returns the subscription ID of {@link Uri}.
     *
     * @param defaultRingtoneUri The default {@link Uri}. For example,
     *            {@link System#DEFAULT_RINGTONE_URI},
     *            {@link System#DEFAULT_RINGTONE_URI_2}, or
     *            {@link System#DEFAULT_RINGTONE_URI_3}.
     * @return The Subscription ID of the defaultRingtoneUri, or -1.
     * @hide
     */
    public static int getDefaultRingtoneSubIdByUri(Uri defaultRingtoneUri) {
        if (defaultRingtoneUri == null) {
            return -1;
        }
        /**
         * URI is encoded as below:
         * DEFAULT_RINGTONE_URI: content://settings/system/ringtone
         * DEFAULT_RINGTONE_URI_2: content://settings/system/ringtone_2
         * DEFAULT_RINGTONE_URI_3: content://settings/system/ringtone_3
         */
        if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI)) {
            return 0; /* Sub-1 */
        }
        final String uriString = defaultRingtoneUri.toString();
        int parsedSubId = -1;
        if (uriString.startsWith(Settings.System.DEFAULT_RINGTONE_URI.toString())) {
            parsedSubId = Integer.parseInt(uriString.substring(uriString.lastIndexOf("_") + 1));
            if ((parsedSubId > 0 &&  parsedSubId <= Settings.System.MAX_NUM_RINGTONES)) {
                return parsedSubId - 1;
            }
        }
        return -1;
    }

    /**
     * Gets the actual default sound's {@link Uri}. This will give the actual
     * sound {@link Uri}, instead of using this, most clients can use
     * {@link System#DEFAULT_RINGTONE_URI}.
     *
     * @param subId The Subscription ID.
     * @return A {@link Uri} pointing to the default sound for the sound type.
     * @hide
     */
    public static Uri getDefaultRingtoneUriBySubId(int subId) {
        if (!(subId >= 0 &&  subId < Settings.System.MAX_NUM_RINGTONES)) {
            return null;
        }
        if (subId == 0) {
            return Settings.System.DEFAULT_RINGTONE_URI;
        } else {
            final String uriString =
                    Settings.System.DEFAULT_RINGTONE_URI.toString() + "_" + (subId + 1);
            return Uri.parse(uriString);
        }
    }

    /**
     * Gets the current default sound's {@link Uri}. This will give the actual
     * sound {@link Uri}, instead of using this, most clients can use
     * {@link System#DEFAULT_RINGTONE_URI}.
     *
     * @param context A context used for querying.
     * @param subId The Subscription ID.
     * @return A {@link Uri} pointing to the default sound for the sound type.
     * @hide
     */
    public static Uri getActualRingtoneUriBySubId(Context context, int subId) {
        if (!(subId >= 0 &&  subId < Settings.System.MAX_NUM_RINGTONES)) {
            return null;
        }
        String setting;
        if (subId == 0) {
            setting = Settings.System.RINGTONE;
        } else {
            setting = Settings.System.RINGTONE + "_" + (subId + 1);
        }
        final String uriString = Settings.System.getString(context.getContentResolver(), setting);
        return uriString != null ? Uri.parse(uriString) : null;
    }

    /**
     * Sets the {@link Uri} of the default sound for a given sound type.
     *
     * @param context A context used for querying.
     * @param subId The Subscription ID.
     * @param ringtoneUri A {@link Uri} pointing to the default sound to set.
     * @hide
     */
    public static void setActualRingtoneUriBySubId(Context context, int subId, Uri ringtoneUri) {
        if (!(subId >= 0 &&  subId < Settings.System.MAX_NUM_RINGTONES)) {
            return;
        }
        String setting;
        if (subId == 0) {
            setting = Settings.System.RINGTONE;
        } else {
            setting = Settings.System.RINGTONE + "_" + (subId + 1);
        }
        Settings.System.putString(context.getContentResolver(), setting,
                ringtoneUri != null ? ringtoneUri.toString() : null);
    }
}