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

Commit a7cea593 authored by kaiyiz's avatar kaiyiz Committed by Adnan
Browse files

DeskClock: The alarm ringtone name display error

Select the downloaded music,there is no operation to get the name
from the uri.If restart Alarm,there is no permission to get the
title from the uri.

No matter in which database,the music has the same id.We can only
get the info of the music from other database by id in uri.
Then set the name to the alarm.

CRs-Fixed: 671742

Change-Id: I33611023e52ee6192e0949b2a17883bf66b747c0
parent 75f24865
Loading
Loading
Loading
Loading
+47 −24
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.LoaderManager;
import android.app.Profile;
import android.app.ProfileManager;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -48,6 +49,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.format.DateFormat;
@@ -114,6 +116,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
    private static final String KEY_SELECT_SOURCE = "selectedSource";

    private static final String DOC_AUTHORITY = "com.android.providers.media.documents";
    private static final String DOC_DOWNLOAD = "com.android.providers.downloads.documents";

    private static final int REQUEST_CODE_RINGTONE = 1;
    private static final int REQUEST_CODE_PROFILE = 2;
@@ -1637,9 +1640,9 @@ public class AlarmClockFragment extends DeskClockFragment implements
                    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.
                        if (uri.getAuthority().equals(DOC_AUTHORITY)) {
                            title = mDisplayName;
                        if (uri.getAuthority().equals(DOC_AUTHORITY)
                                || uri.getAuthority().equals(DOC_DOWNLOAD)) {
                            title = getDisplayNameFromDatabase(mContext,uri);
                        } else {
                            Ringtone ringTone = RingtoneManager.getRingtone(mContext, uri);
                            if (ringTone != null) {
@@ -1662,19 +1665,41 @@ public class AlarmClockFragment extends DeskClockFragment implements
                    return true;
                }
            } else if (uri.getScheme().contentEquals("content")) {
                return true;
            }

            return false;
        }

        private String getDisplayNameFromDatabase(Context context,Uri uri) {
            String selection = null;
            String[] selectionArgs = null;
            String title = mContext.getString(R.string.ringtone_default);
            // If restart Alarm,there is no permission to get the title from the uri.
            // No matter in which database,the music has the same id.
            // So we can only get the info of the music from other database by id in uri.
            if (uri.getAuthority().equals(DOC_DOWNLOAD)) {
                final String id = DocumentsContract.getDocumentId(uri);
                uri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
            } else if (uri.getAuthority().equals(DOC_AUTHORITY)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                selection = "_id=?";
                selectionArgs = new String[] {
                    split[1]
                };
            }
            Cursor cursor = null;
            try {
                    cursor = mContext.getContentResolver().query(uri,
                cursor = context.getContentResolver().query(uri,
                        new String[] {
                                MediaStore.Audio.Media.TITLE,
                                MediaStore.Audio.Media.DISPLAY_NAME
                            }, null, null, null);
                        }, selection, selectionArgs, null);
                if (cursor != null && cursor.getCount() > 0) {
                        if (uri.getAuthority().equals(DOC_AUTHORITY)) {
                        cursor.moveToFirst();
                            mDisplayName = cursor.getString(1);
                        }
                        return true;
                    title = cursor.getString(0);
                }
            } catch (Exception e) {
                Log.e("Get ringtone uri Exception: e.toString=" + e.toString());
@@ -1683,9 +1708,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
                    cursor.close();
                }
            }
            }

            return false;
            return title;
        }

        public void setNewAlarm(long alarmId) {