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

Commit cc21c7a4 authored by Hall Liu's avatar Hall Liu Committed by Android (Google) Code Review
Browse files

Merge "Move ringtone lookup to background" into nyc-dev

parents e74af084 8c89b20b
Loading
Loading
Loading
Loading
+20 −11
Original line number Original line Diff line number Diff line
@@ -17,11 +17,13 @@
package com.android.server.telecom;
package com.android.server.telecom;


import android.media.Ringtone;
import android.media.Ringtone;
import android.net.Uri;
import android.os.Handler;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.HandlerThread;
import android.os.Message;
import android.os.Message;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;


/**
/**
@@ -45,13 +47,12 @@ public class AsyncRingtonePlayer {
    private Ringtone mRingtone;
    private Ringtone mRingtone;


    /** Plays the ringtone. */
    /** Plays the ringtone. */
    public void play(Ringtone ringtone) {
    public void play(RingtoneFactory factory, Uri ringtoneUri) {
        Log.d(this, "Posting play.");
        Log.d(this, "Posting play.");
        if (ringtone == null) {
        SomeArgs args = SomeArgs.obtain();
            Log.i(this, "null (silence -- not playing anything)");
        args.arg1 = factory;
            return;
        args.arg2 = ringtoneUri;
        }
        postMessage(EVENT_PLAY, true /* shouldCreateHandler */, args);
        postMessage(EVENT_PLAY, true /* shouldCreateHandler */, ringtone);
    }
    }


    /** Stops playing the ringtone. */
    /** Stops playing the ringtone. */
@@ -67,7 +68,7 @@ public class AsyncRingtonePlayer {
     * @param messageCode The message to post.
     * @param messageCode The message to post.
     * @param shouldCreateHandler True when a handler should be created to handle this message.
     * @param shouldCreateHandler True when a handler should be created to handle this message.
     */
     */
    private void postMessage(int messageCode, boolean shouldCreateHandler, Ringtone ringtone) {
    private void postMessage(int messageCode, boolean shouldCreateHandler, SomeArgs args) {
        synchronized(this) {
        synchronized(this) {
            if (mHandler == null && shouldCreateHandler) {
            if (mHandler == null && shouldCreateHandler) {
                mHandler = getNewHandler();
                mHandler = getNewHandler();
@@ -76,7 +77,7 @@ public class AsyncRingtonePlayer {
            if (mHandler == null) {
            if (mHandler == null) {
                Log.d(this, "Message %d skipped because there is no handler.", messageCode);
                Log.d(this, "Message %d skipped because there is no handler.", messageCode);
            } else {
            } else {
                mHandler.obtainMessage(messageCode, ringtone).sendToTarget();
                mHandler.obtainMessage(messageCode, args).sendToTarget();
            }
            }
        }
        }
    }
    }
@@ -95,7 +96,7 @@ public class AsyncRingtonePlayer {
            public void handleMessage(Message msg) {
            public void handleMessage(Message msg) {
                switch(msg.what) {
                switch(msg.what) {
                    case EVENT_PLAY:
                    case EVENT_PLAY:
                        handlePlay((Ringtone) msg.obj);
                        handlePlay((SomeArgs) msg.obj);
                        break;
                        break;
                    case EVENT_REPEAT:
                    case EVENT_REPEAT:
                        handleRepeat();
                        handleRepeat();
@@ -111,7 +112,10 @@ public class AsyncRingtonePlayer {
    /**
    /**
     * Starts the actual playback of the ringtone. Executes on ringtone-thread.
     * Starts the actual playback of the ringtone. Executes on ringtone-thread.
     */
     */
    private void handlePlay(Ringtone ringtone) {
    private void handlePlay(SomeArgs args) {
        RingtoneFactory factory = (RingtoneFactory) args.arg1;
        Uri ringtoneUri = (Uri) args.arg2;
        args.recycle();
        // don't bother with any of this if there is an EVENT_STOP waiting.
        // don't bother with any of this if there is an EVENT_STOP waiting.
        if (mHandler.hasMessages(EVENT_STOP)) {
        if (mHandler.hasMessages(EVENT_STOP)) {
            return;
            return;
@@ -121,7 +125,12 @@ public class AsyncRingtonePlayer {
        Log.i(this, "Play ringtone.");
        Log.i(this, "Play ringtone.");


        if (mRingtone == null) {
        if (mRingtone == null) {
            mRingtone = ringtone;
            mRingtone = factory.getRingtone(ringtoneUri);
            if (mRingtone == null) {
                Log.event(null, Log.Events.ERROR_LOG, "Failed to get ringtone from factory. " +
                        "Skipping ringing. Uri was: " + ringtoneUri.toSafeString());
                return;
            }
        }
        }


        handleRepeat();
        handleRepeat();
+1 −2
Original line number Original line Diff line number Diff line
@@ -121,8 +121,7 @@ public final class Ringer {
            // call (for the purposes of direct-to-voicemail), the information about custom
            // call (for the purposes of direct-to-voicemail), the information about custom
            // ringtones should be available by the time this code executes. We can safely
            // ringtones should be available by the time this code executes. We can safely
            // request the custom ringtone from the call and expect it to be current.
            // request the custom ringtone from the call and expect it to be current.
            mRingtonePlayer.play(
            mRingtonePlayer.play(mRingtoneFactory, foregroundCall.getRingtone());
                    mRingtoneFactory.getRingtone(foregroundCall.getRingtone()));
        } else {
        } else {
            Log.v(this, "startRingingOrCallWaiting, skipping because volume is 0");
            Log.v(this, "startRingingOrCallWaiting, skipping because volume is 0");
        }
        }