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

Commit 18a92e74 authored by kaiyiz's avatar kaiyiz Committed by Matt Garnes
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 e8674e6e
Loading
Loading
Loading
Loading
+47 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.app.Profile;
import android.app.ProfileManager;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -55,6 +56,7 @@ import android.transition.Fade;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.Settings;
import android.text.format.DateFormat;
@@ -127,6 +129,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_EXTERN_AUDIO = 2;
@@ -1326,9 +1329,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) {
@@ -1372,11 +1375,52 @@ public class AlarmClockFragment extends DeskClockFragment implements
                        cursor.close();
                    }
                }
                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 = context.getContentResolver().query(uri,
                        new String[] {
                                MediaStore.Audio.Media.TITLE,
                        }, selection, selectionArgs, null);
                if (cursor != null && cursor.getCount() > 0) {
                        cursor.moveToFirst();
                    title = cursor.getString(0);
                }
            } catch (Exception e) {
                LogUtils.e("Get ringtone uri Exception: e.toString=" + e.toString());
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
            return title;
        }

        public void setNewAlarm(long alarmId) {
            mExpandedId = alarmId;
        }
+1 −1
Original line number Diff line number Diff line
@@ -806,7 +806,7 @@ public final class AlarmStateManager extends BroadcastReceiver {
                    AlarmInstance.getId(uri));
            if (instance == null) {
                // Not a big deal, but it shouldn't happen
                Log.e("Can not show and dismiss alarm for unknown instance: " + uri);
                LogUtils.e("Can not show and dismiss alarm for unknown instance: " + uri);
                return;
            }
            long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;