diff options
author | kaiyiz <kaiyiz@codeaurora.org> | 2014-11-12 12:35:59 -0800 |
---|---|---|
committer | Matt Garnes <matt@cyngn.com> | 2014-11-12 12:35:59 -0800 |
commit | 18a92e743e31783b52acca5df1d339551eeef1aa (patch) | |
tree | 79c731b6f622a611af076f3dfbaac81a70150d55 | |
parent | e8674e6e2b4d0352b366dfb6e3db9714181d2459 (diff) | |
download | android_packages_apps_DeskClock-18a92e743e31783b52acca5df1d339551eeef1aa.tar.gz android_packages_apps_DeskClock-18a92e743e31783b52acca5df1d339551eeef1aa.tar.bz2 android_packages_apps_DeskClock-18a92e743e31783b52acca5df1d339551eeef1aa.zip |
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
-rwxr-xr-x | src/com/android/deskclock/AlarmClockFragment.java | 50 | ||||
-rwxr-xr-x | src/com/android/deskclock/alarms/AlarmStateManager.java | 2 |
2 files changed, 48 insertions, 4 deletions
diff --git a/src/com/android/deskclock/AlarmClockFragment.java b/src/com/android/deskclock/AlarmClockFragment.java index 3a7ad73c9..75cad7e0d 100755 --- a/src/com/android/deskclock/AlarmClockFragment.java +++ b/src/com/android/deskclock/AlarmClockFragment.java @@ -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; } diff --git a/src/com/android/deskclock/alarms/AlarmStateManager.java b/src/com/android/deskclock/alarms/AlarmStateManager.java index f2edb2935..ba35faabd 100755 --- a/src/com/android/deskclock/alarms/AlarmStateManager.java +++ b/src/com/android/deskclock/alarms/AlarmStateManager.java @@ -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; |