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

Commit cbba151c authored by Kevin Rocard's avatar Kevin Rocard Committed by Automerger Merge Worker
Browse files

Merge "Refactor Ringtone.playFallbackRingtone" am: 2f56b3ab

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1931765

Change-Id: I6f1336c981a74f1ecd9c6e9f6827319a96ba8e4c
parents 1ff62d05 2f56b3ab
Loading
Loading
Loading
Loading
+42 −40
Original line number Diff line number Diff line
@@ -504,16 +504,24 @@ public class Ringtone {
    }

    private boolean playFallbackRingtone() {
        if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes))
                != 0) {
        int streamType = AudioAttributes.toLegacyStreamType(mAudioAttributes);
        if (mAudioManager.getStreamVolume(streamType) == 0) {
            return false;
        }
        int ringtoneType = RingtoneManager.getDefaultType(mUri);
            if (ringtoneType == -1 ||
                    RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) {
        if (ringtoneType != -1 &&
                RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) == null) {
            Log.w(TAG, "not playing fallback for " + mUri);
            return false;
        }
        // Default ringtone, try fallback ringtone.
        try {
            AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(
                    com.android.internal.R.raw.fallbackring);
                    if (afd != null) {
            if (afd == null) {
                Log.e(TAG, "Could not load fallback ringtone");
                return false;
            }
            mLocalPlayer = new MediaPlayer();
            if (afd.getDeclaredLength() < 0) {
                mLocalPlayer.setDataSource(afd.getFileDescriptor());
@@ -532,22 +540,16 @@ public class Ringtone {
            mLocalPlayer.prepare();
            startLocalPlayer();
            afd.close();
                        return true;
                    } else {
                        Log.e(TAG, "Could not load fallback ringtone");
                    }
        } catch (IOException ioe) {
            destroyLocalPlayer();
            Log.e(TAG, "Failed to open fallback ringtone");
            return false;
        } catch (NotFoundException nfe) {
            Log.e(TAG, "Fallback ringtone does not exist");
                }
            } else {
                Log.w(TAG, "not playing fallback for " + mUri);
            }
        }
            return false;
        }
        return true;
    }

    void setTitle(String title) {
        mTitle = title;