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

Commit a8ad2258 authored by linus_lee's avatar linus_lee Committed by Gerrit Code Review
Browse files

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
parent 6eeeab62
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -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;
+11 −0
Original line number Diff line number Diff line
@@ -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;
+12 −12
Original line number Diff line number Diff line
@@ -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));
        }
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -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";