summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlinus_lee <llee@cyngn.com>2015-01-13 15:17:45 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2015-01-14 00:15:18 +0000
commita8ad22583aa0e15b6f42eb2a47f47df5f346780c (patch)
tree19885350fa15ab6c4076170d8de2d73d9d438541
parent6eeeab624db8305fd849f6d175d1062338a93c28 (diff)
downloadandroid_packages_apps_DeskClock-a8ad22583aa0e15b6f42eb2a47f47df5f346780c.tar.gz
android_packages_apps_DeskClock-a8ad22583aa0e15b6f42eb2a47f47df5f346780c.tar.bz2
android_packages_apps_DeskClock-a8ad22583aa0e15b6f42eb2a47f47df5f346780c.zip
Fix picking music for alarms not working
1) documentsui gives us a document contentprovider link so support that 2) if the same uri is picked, don't revoke the permissions 3) fix a different crash where if no args are passed the log crashes Change-Id: Ie67b252ebe5b81589199ab4502b11b62300c236c
-rw-r--r--src/com/android/deskclock/AlarmClockFragment.java23
-rw-r--r--src/com/android/deskclock/AlarmMultiPlayer.java11
-rw-r--r--src/com/android/deskclock/LogUtils.java24
-rwxr-xr-xsrc/com/android/deskclock/Utils.java4
4 files changed, 41 insertions, 21 deletions
diff --git a/src/com/android/deskclock/AlarmClockFragment.java b/src/com/android/deskclock/AlarmClockFragment.java
index 70d441434..42a78e114 100644
--- a/src/com/android/deskclock/AlarmClockFragment.java
+++ b/src/com/android/deskclock/AlarmClockFragment.java
@@ -131,9 +131,6 @@ public class AlarmClockFragment extends DeskClockFragment implements
private static final String KEY_DELETE_CONFIRMATION = "deleteConfirmation";
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;
private static final int REQUEST_CODE_PROFILE = 3;
@@ -718,8 +715,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
}
private Uri getRingtoneUri(Intent intent) {
- // Release the current ringtone uri
- releaseRingtoneUri(mSelectedAlarm.alert);
+ boolean releaseRingtoneUri = true;
Uri uri;
if (mSelectSource == SEL_SRC_RINGTONE) {
@@ -727,6 +723,9 @@ public class AlarmClockFragment extends DeskClockFragment implements
} else {
uri = intent.getData();
if (uri != null) {
+ // if the alarms are the same, don't revoke the permissions
+ releaseRingtoneUri = !uri.equals(mSelectedAlarm.alert);
+
try {
getActivity().getContentResolver().takePersistableUriPermission(
uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
@@ -741,6 +740,12 @@ public class AlarmClockFragment extends DeskClockFragment implements
if (uri == null) {
uri = Alarm.NO_RINGTONE_URI;
}
+
+ if (releaseRingtoneUri) {
+ // Release the current ringtone uri
+ releaseRingtoneUri(mSelectedAlarm.alert);
+ }
+
return uri;
}
@@ -1427,8 +1432,8 @@ public class AlarmClockFragment extends DeskClockFragment implements
title = mContext.getResources().getString(R.string.alarm_type_random);
} else {
if (Utils.isRingToneUriValid(mContext, uri)) {
- if (uri.getAuthority().equals(DOC_AUTHORITY)
- || uri.getAuthority().equals(DOC_DOWNLOAD)) {
+ if (uri.getAuthority().equals(Utils.DOC_AUTHORITY)
+ || uri.getAuthority().equals(Utils.DOC_DOWNLOAD)) {
title = getDisplayNameFromDatabase(mContext,uri);
} else if (uri.isPathPrefixMatch(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI)) {
Cursor c = getActivity().getContentResolver().query(uri, new String[] {MediaStore.Audio.Playlists.NAME}, null, null, null);
@@ -1457,11 +1462,11 @@ public class AlarmClockFragment extends DeskClockFragment implements
// 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)) {
+ if (uri.getAuthority().equals(Utils.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)) {
+ } else if (uri.getAuthority().equals(Utils.DOC_AUTHORITY)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
diff --git a/src/com/android/deskclock/AlarmMultiPlayer.java b/src/com/android/deskclock/AlarmMultiPlayer.java
index d8a4733f1..940184b1b 100644
--- a/src/com/android/deskclock/AlarmMultiPlayer.java
+++ b/src/com/android/deskclock/AlarmMultiPlayer.java
@@ -32,6 +32,8 @@ public class AlarmMultiPlayer implements MediaPlayer.OnCompletionListener {
private boolean mLooping;
private boolean mIsExternal;
private boolean mRandom;
+ // used for audio tracks that could potentially be outside the media store
+ private Uri mUriTrack;
private Cursor mCursor;
@@ -239,6 +241,8 @@ public class AlarmMultiPlayer implements MediaPlayer.OnCompletionListener {
c.close();
}
return null;
+ } else if (mUriTrack != null) {
+ return mUriTrack;
}
if (mCursor == null) {
@@ -251,6 +255,7 @@ public class AlarmMultiPlayer implements MediaPlayer.OnCompletionListener {
// Cycle through the playlist
mCursor.moveToFirst();
}
+
if(mIsExternal) {
return ContentUris.withAppendedId(Audio.Media.EXTERNAL_CONTENT_URI, id);
} else {
@@ -259,10 +264,16 @@ public class AlarmMultiPlayer implements MediaPlayer.OnCompletionListener {
}
private void handleSetDataSourceUri(Uri uri) {
+ mUriTrack = null;
mSingle = false;
if (uri.equals(RANDOM_URI)) {
mRandom = true;
return;
+ } else if (uri.getAuthority().equals(Utils.DOC_DOWNLOAD)
+ || uri.getAuthority().equals(Utils.DOC_AUTHORITY)) {
+ mUriTrack = uri;
+ mSingle = true;
+ return;
}
String columnName = null;
diff --git a/src/com/android/deskclock/LogUtils.java b/src/com/android/deskclock/LogUtils.java
index 516e00b2d..1a2d9c7d4 100644
--- a/src/com/android/deskclock/LogUtils.java
+++ b/src/com/android/deskclock/LogUtils.java
@@ -30,61 +30,61 @@ public class LogUtils {
public static void v(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.VERBOSE)) {
- Log.v(LOGTAG, args == null ? message : String.format(message, args));
+ Log.v(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void v(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.VERBOSE)) {
- Log.v(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.v(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
public static void d(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.DEBUG)) {
- Log.d(LOGTAG, args == null ? message : String.format(message, args));
+ Log.d(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void d(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.DEBUG)) {
- Log.d(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.d(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
public static void i(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.INFO)) {
- Log.i(LOGTAG, args == null ? message : String.format(message, args));
+ Log.i(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void i(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.INFO)) {
- Log.i(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.i(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
public static void w(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.WARN)) {
- Log.w(LOGTAG, args == null ? message : String.format(message, args));
+ Log.w(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void w(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.WARN)) {
- Log.w(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.w(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
public static void e(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
- Log.e(LOGTAG, args == null ? message : String.format(message, args));
+ Log.e(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void e(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.ERROR)) {
- Log.e(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.e(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
@@ -102,13 +102,13 @@ public class LogUtils {
public static void wtf(String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.ASSERT)) {
- Log.wtf(LOGTAG, args == null ? message : String.format(message, args));
+ Log.wtf(LOGTAG, args.length == 0 ? message : String.format(message, args));
}
}
public static void wtf(String tag, String message, Object... args) {
if (DEBUG || Log.isLoggable(LOGTAG, Log.ASSERT)) {
- Log.wtf(LOGTAG + "/" + tag, args == null ? message : String.format(message, args));
+ Log.wtf(LOGTAG + "/" + tag, args.length == 0 ? message : String.format(message, args));
}
}
}
diff --git a/src/com/android/deskclock/Utils.java b/src/com/android/deskclock/Utils.java
index 43f2d893b..5e4d48b9e 100755
--- a/src/com/android/deskclock/Utils.java
+++ b/src/com/android/deskclock/Utils.java
@@ -94,6 +94,10 @@ public class Utils {
*/
private static String[] sShortWeekdays = null;
+ /** Content provider paths that could be passed back from documents ui **/
+ public static final String DOC_AUTHORITY = "com.android.providers.media.documents";
+ public static final String DOC_DOWNLOAD = "com.android.providers.downloads.documents";
+
/** Types that may be used for clock displays. **/
public static final String CLOCK_TYPE_DIGITAL = "digital";
public static final String CLOCK_TYPE_ANALOG = "analog";