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

Commit ea4c9231 authored by kaiyiz's avatar kaiyiz Committed by Brint E. Kriebel
Browse files

DeskClock: Fixed the ringtone name display incorrect when delete music file

It only displays FALLBACKRING when set alarm ringtone by file explorer,
is caused by that it not handle the file uri which from file explorer
in getRingToneTitle method.

Add the judgement to get the file uri and get the right title of alarm
ringtone.

CRs-Fixed: 546747

Change-Id: I50ac325c1a636fb2a2985fbc15839fab9e31e0cc
parent ceb41470
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -57,4 +57,5 @@
  <string name="alarm_select_external">音乐</string>
  <string name="alarm_select_ok">确定</string>
  <string name="alarm_select_cancel">取消</string>
  <string name="ringtone_default">"默认铃声"</string>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -93,4 +93,7 @@
    <string name="alarm_select_ok">OK</string>
    <!-- Cancel for selection -->
    <string name="alarm_select_cancel">Cancel</string>

    <!-- Ringtone selection default" -->
    <string name="ringtone_default">"Default ringtone"</string>
</resources>
+34 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.view.Gravity;
@@ -82,6 +83,7 @@ import com.android.deskclock.provider.DaysOfWeek;
import com.android.deskclock.widget.ActionableToastBar;
import com.android.deskclock.widget.TextTime;

import java.io.File;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.HashSet;
@@ -1627,12 +1629,14 @@ public class AlarmClockFragment extends DeskClockFragment implements
                if (uri.equals(MultiPlayer.RANDOM_URI)) {
                    title = mContext.getResources().getString(R.string.alarm_type_random);
                } else {
                    if (isRingToneUriValid(uri)) {
                        // This is slow because a media player is created during Ringtone object creation.
                        Ringtone ringTone = RingtoneManager.getRingtone(mContext, uri);
                        if (ringTone != null) {
                            title = ringTone.getTitle(mContext);
                        }
                    }
                }
                if (title != null) {
                    mRingtoneTitleCache.putString(uri.toString(), title);
                }
@@ -1640,6 +1644,32 @@ public class AlarmClockFragment extends DeskClockFragment implements
            return title;
        }

        private boolean isRingToneUriValid(Uri uri) {
            if (uri.getScheme().contentEquals("file")) {
                File f = new File(uri.getPath());
                if (f.exists()) {
                    return true;
                }
            } else if (uri.getScheme().contentEquals("content")) {
                Cursor cursor = null;
                try {
                    cursor = mContext.getContentResolver().query(uri,
                            new String[] {MediaStore.Audio.Media.TITLE}, null, null, null);
                    if (cursor != null && cursor.getCount() > 0) {
                        return true;
                    }
                } catch (Exception e) {
                    Log.e("Get ringtone uri Exception: e.toString=" + e.toString());
                } finally {
                    if (cursor != null) {
                        cursor.close();
                    }
                }
            }

            return false;
        }

        public void setNewAlarm(long alarmId) {
            mExpanded.add(alarmId);
        }