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

Commit 7376e3b6 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Ringtone: return default ringtone if actual one doesn't exsit"

parents 6faad0d5 d942b3a7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1990,6 +1990,14 @@ public final class Settings {
         */
        public static final String APPEND_FOR_LAST_AUDIBLE = "_last_audible";

        /**
         * Persistent store for the static default system ringtone URI.
         * This setting is initialized within media scanner and read only afterwards.
         * It provides the persistent URI of default system ringtone.
         * @hide
         */
        public static final String DEFAULT_RINGTONE = "ringtone_default";

        /**
         * Persistent store for the system-wide default ringtone URI.
         * <p>
+3 −0
Original line number Diff line number Diff line
@@ -1005,6 +1005,9 @@ public class MediaScanner
                    setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND, tableUri, rowId);
                    mDefaultNotificationSet = true;
                } else if (ringtones) {
                    // memorize default system ringtone persistently
                    setSettingIfNotSet(Settings.System.DEFAULT_RINGTONE, tableUri, rowId);

                    setSettingIfNotSet(Settings.System.RINGTONE, tableUri, rowId);
                    if (MSimTelephonyManager.getDefault().isMultiSimEnabled()) {
                        int phoneCount = MSimTelephonyManager.getDefault().getPhoneCount();
+55 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.ContentUris;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
@@ -615,9 +616,27 @@ public class RingtoneManager {
        String setting = getSettingForType(type);
        if (setting == null) return null;
        final String uriString = Settings.System.getString(context.getContentResolver(), setting);
        if ((uriString == null) || (type & TYPE_RINGTONE) == 0) {
            return uriString != null ? Uri.parse(uriString) : null;
        }

        Uri ringToneUri = getStaticDefaultRingtoneUri(context);
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(Uri.parse(uriString),
                    null, null, null, null);
            if ((cursor != null) && (cursor.getCount() > 0)) {
                ringToneUri = Uri.parse(uriString);
            }
        } catch (SQLiteException ex) {
            Log.e(TAG, "ex " + ex);
        } finally {
            if (cursor != null) cursor.close();
        }

        return ringToneUri;
    }
    
    /**
     * Sets the {@link Uri} of the default sound for a given sound type.
     * 
@@ -703,6 +722,21 @@ public class RingtoneManager {
        }
    }

    /**
     * Returns the {@link Uri} for the static default ringtone.
     * Rather than returning the actual ringtone's sound {@link Uri}, this will
     * return the default system ringtone. When actual ringtone is not valid
     * in media provider, default system ringtone is the one to rollback to.
     *
     * @return The {@link Uri} of the default system ringtone.
     * @hide
     */
    public static Uri getStaticDefaultRingtoneUri(Context context) {
        final String uriString = Settings.System.getString(
                context.getContentResolver(), Settings.System.DEFAULT_RINGTONE.toString());
        return uriString != null ? Uri.parse(uriString) : null;
    }

    /**
     * Returns the subscription ID of {@link Uri}.
     *
@@ -779,8 +813,27 @@ public class RingtoneManager {
        } else {
            setting = Settings.System.RINGTONE + "_" + (subId + 1);
        }

        final String uriString = Settings.System.getString(context.getContentResolver(), setting);
        return uriString != null ? Uri.parse(uriString) : null;
        if (uriString == null) {
            return null;
        }

        Uri ringToneUri = getStaticDefaultRingtoneUri(context);
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(Uri.parse(uriString),
                    null, null, null, null);
            if ((cursor != null) && (cursor.getCount() > 0)) {
                ringToneUri = Uri.parse(uriString);
            }
        } catch (SQLiteException ex) {
            Log.e(TAG, "ex " + ex);
        } finally {
            if (cursor != null) cursor.close();
        }

        return ringToneUri;
    }

    /**