Loading src/com/android/server/telecom/AsyncRingtonePlayer.java +36 −7 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ class AsyncRingtonePlayer { private static final int EVENT_PLAY = 1; private static final int EVENT_STOP = 2; private static final int EVENT_REPEAT = 3; private static final int EVENT_INCREASE_VOLUME = 4; // The interval in which to restart the ringer. private static final int RESTART_RINGER_MILLIS = 3000; Loading @@ -47,6 +48,9 @@ class AsyncRingtonePlayer { /** The current ringtone. Only used by the ringtone thread. */ private Ringtone mRingtone; private float mIncrementAmount; private float mCurrentIncrementVolume; /** * The context. */ Loading @@ -57,15 +61,17 @@ class AsyncRingtonePlayer { } /** Plays the ringtone. */ void play(Uri ringtone) { void play(Uri ringtone, float incStartVolume, int incRampUpTime) { Log.d(this, "Posting play."); postMessage(EVENT_PLAY, true /* shouldCreateHandler */, ringtone); postMessage(EVENT_PLAY, true /* shouldCreateHandler */, ringtone, Math.round(incStartVolume * 100F), incRampUpTime); } /** Stops playing the ringtone. */ void stop() { Log.d(this, "Posting stop."); postMessage(EVENT_STOP, false /* shouldCreateHandler */, null); postMessage(EVENT_STOP, false /* shouldCreateHandler */, null, 0, 0); } /** Loading @@ -75,7 +81,8 @@ class AsyncRingtonePlayer { * @param messageCode The message to post. * @param shouldCreateHandler True when a handler should be created to handle this message. */ private void postMessage(int messageCode, boolean shouldCreateHandler, Uri ringtone) { private void postMessage(int messageCode, boolean shouldCreateHandler, Uri ringtone, int arg1, int arg2) { synchronized(this) { if (mHandler == null && shouldCreateHandler) { mHandler = getNewHandler(); Loading @@ -84,7 +91,7 @@ class AsyncRingtonePlayer { if (mHandler == null) { Log.d(this, "Message %d skipped because there is no handler.", messageCode); } else { mHandler.obtainMessage(messageCode, ringtone).sendToTarget(); mHandler.obtainMessage(messageCode, arg1, arg2, ringtone).sendToTarget(); } } } Loading @@ -103,7 +110,7 @@ class AsyncRingtonePlayer { public void handleMessage(Message msg) { switch(msg.what) { case EVENT_PLAY: handlePlay((Uri) msg.obj); handlePlay((Uri) msg.obj, (float) msg.arg1 / 100F, msg.arg2); break; case EVENT_REPEAT: handleRepeat(); Loading @@ -111,6 +118,15 @@ class AsyncRingtonePlayer { case EVENT_STOP: handleStop(); break; case EVENT_INCREASE_VOLUME: mCurrentIncrementVolume += mIncrementAmount; Log.d(AsyncRingtonePlayer.this, "Increasing ringtone volume to " + Math.round(mCurrentIncrementVolume * 100F) + "%"); mRingtone.setVolume(mCurrentIncrementVolume); if (mCurrentIncrementVolume < 1F) { sendEmptyMessageDelayed(EVENT_INCREASE_VOLUME, 1000); } break; } } }; Loading @@ -119,7 +135,7 @@ class AsyncRingtonePlayer { /** * Starts the actual playback of the ringtone. Executes on ringtone-thread. */ private void handlePlay(Uri ringtoneUri) { private void handlePlay(Uri ringtoneUri, float incStartVolume, int incRampUpTime) { // don't bother with any of this if there is an EVENT_STOP waiting. if (mHandler.hasMessages(EVENT_STOP)) { return; Loading @@ -138,6 +154,18 @@ class AsyncRingtonePlayer { } } if (incRampUpTime > 0) { Log.d(this, "Starting ringtone volume at " + Math.round(incStartVolume * 100F) + "%"); mRingtone.setVolume(incStartVolume); mIncrementAmount = (1F - incStartVolume) / (float) incRampUpTime; mCurrentIncrementVolume = incStartVolume; mHandler.sendEmptyMessageDelayed(EVENT_INCREASE_VOLUME, 1000); } else { mRingtone.setVolume(1F); } handleRepeat(); } Loading Loading @@ -178,6 +206,7 @@ class AsyncRingtonePlayer { // At the time that STOP is handled, there should be no need for repeat messages in the // queue. mHandler.removeMessages(EVENT_REPEAT); mHandler.removeMessages(EVENT_INCREASE_VOLUME); if (mHandler.hasMessages(EVENT_PLAY)) { Log.v(this, "Keeping alive ringtone thread for subsequent play request."); Loading src/com/android/server/telecom/Ringer.java +14 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.telecom; import android.app.Notification; import android.app.NotificationManager; import android.content.ContentResolver; import android.content.Context; import android.media.AudioAttributes; import android.media.AudioManager; Loading Loading @@ -183,13 +184,25 @@ final class Ringer extends CallsManagerListenerBase { (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_RING) >= 0) { Log.v(this, "startRingingOrCallWaiting"); float startVolume = 0; int rampUpTime = 0; final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.INCREASING_RING, 0) != 0) { startVolume = Settings.System.getFloat(cr, Settings.System.INCREASING_RING_START_VOLUME, 0.1f); rampUpTime = Settings.System.getInt(cr, Settings.System.INCREASING_RING_RAMP_UP_TIME, 20); } mCallAudioManager.setIsRinging(true); // Because we wait until a contact info query to complete before processing a // 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 // request the custom ringtone from the call and expect it to be current. mRingtonePlayer.play(foregroundCall.getRingtone()); mRingtonePlayer.play(foregroundCall.getRingtone(), startVolume, rampUpTime); } else { Log.v(this, "startRingingOrCallWaiting, skipping because volume is 0"); } Loading Loading
src/com/android/server/telecom/AsyncRingtonePlayer.java +36 −7 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ class AsyncRingtonePlayer { private static final int EVENT_PLAY = 1; private static final int EVENT_STOP = 2; private static final int EVENT_REPEAT = 3; private static final int EVENT_INCREASE_VOLUME = 4; // The interval in which to restart the ringer. private static final int RESTART_RINGER_MILLIS = 3000; Loading @@ -47,6 +48,9 @@ class AsyncRingtonePlayer { /** The current ringtone. Only used by the ringtone thread. */ private Ringtone mRingtone; private float mIncrementAmount; private float mCurrentIncrementVolume; /** * The context. */ Loading @@ -57,15 +61,17 @@ class AsyncRingtonePlayer { } /** Plays the ringtone. */ void play(Uri ringtone) { void play(Uri ringtone, float incStartVolume, int incRampUpTime) { Log.d(this, "Posting play."); postMessage(EVENT_PLAY, true /* shouldCreateHandler */, ringtone); postMessage(EVENT_PLAY, true /* shouldCreateHandler */, ringtone, Math.round(incStartVolume * 100F), incRampUpTime); } /** Stops playing the ringtone. */ void stop() { Log.d(this, "Posting stop."); postMessage(EVENT_STOP, false /* shouldCreateHandler */, null); postMessage(EVENT_STOP, false /* shouldCreateHandler */, null, 0, 0); } /** Loading @@ -75,7 +81,8 @@ class AsyncRingtonePlayer { * @param messageCode The message to post. * @param shouldCreateHandler True when a handler should be created to handle this message. */ private void postMessage(int messageCode, boolean shouldCreateHandler, Uri ringtone) { private void postMessage(int messageCode, boolean shouldCreateHandler, Uri ringtone, int arg1, int arg2) { synchronized(this) { if (mHandler == null && shouldCreateHandler) { mHandler = getNewHandler(); Loading @@ -84,7 +91,7 @@ class AsyncRingtonePlayer { if (mHandler == null) { Log.d(this, "Message %d skipped because there is no handler.", messageCode); } else { mHandler.obtainMessage(messageCode, ringtone).sendToTarget(); mHandler.obtainMessage(messageCode, arg1, arg2, ringtone).sendToTarget(); } } } Loading @@ -103,7 +110,7 @@ class AsyncRingtonePlayer { public void handleMessage(Message msg) { switch(msg.what) { case EVENT_PLAY: handlePlay((Uri) msg.obj); handlePlay((Uri) msg.obj, (float) msg.arg1 / 100F, msg.arg2); break; case EVENT_REPEAT: handleRepeat(); Loading @@ -111,6 +118,15 @@ class AsyncRingtonePlayer { case EVENT_STOP: handleStop(); break; case EVENT_INCREASE_VOLUME: mCurrentIncrementVolume += mIncrementAmount; Log.d(AsyncRingtonePlayer.this, "Increasing ringtone volume to " + Math.round(mCurrentIncrementVolume * 100F) + "%"); mRingtone.setVolume(mCurrentIncrementVolume); if (mCurrentIncrementVolume < 1F) { sendEmptyMessageDelayed(EVENT_INCREASE_VOLUME, 1000); } break; } } }; Loading @@ -119,7 +135,7 @@ class AsyncRingtonePlayer { /** * Starts the actual playback of the ringtone. Executes on ringtone-thread. */ private void handlePlay(Uri ringtoneUri) { private void handlePlay(Uri ringtoneUri, float incStartVolume, int incRampUpTime) { // don't bother with any of this if there is an EVENT_STOP waiting. if (mHandler.hasMessages(EVENT_STOP)) { return; Loading @@ -138,6 +154,18 @@ class AsyncRingtonePlayer { } } if (incRampUpTime > 0) { Log.d(this, "Starting ringtone volume at " + Math.round(incStartVolume * 100F) + "%"); mRingtone.setVolume(incStartVolume); mIncrementAmount = (1F - incStartVolume) / (float) incRampUpTime; mCurrentIncrementVolume = incStartVolume; mHandler.sendEmptyMessageDelayed(EVENT_INCREASE_VOLUME, 1000); } else { mRingtone.setVolume(1F); } handleRepeat(); } Loading Loading @@ -178,6 +206,7 @@ class AsyncRingtonePlayer { // At the time that STOP is handled, there should be no need for repeat messages in the // queue. mHandler.removeMessages(EVENT_REPEAT); mHandler.removeMessages(EVENT_INCREASE_VOLUME); if (mHandler.hasMessages(EVENT_PLAY)) { Log.v(this, "Keeping alive ringtone thread for subsequent play request."); Loading
src/com/android/server/telecom/Ringer.java +14 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.telecom; import android.app.Notification; import android.app.NotificationManager; import android.content.ContentResolver; import android.content.Context; import android.media.AudioAttributes; import android.media.AudioManager; Loading Loading @@ -183,13 +184,25 @@ final class Ringer extends CallsManagerListenerBase { (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_RING) >= 0) { Log.v(this, "startRingingOrCallWaiting"); float startVolume = 0; int rampUpTime = 0; final ContentResolver cr = mContext.getContentResolver(); if (Settings.System.getInt(cr, Settings.System.INCREASING_RING, 0) != 0) { startVolume = Settings.System.getFloat(cr, Settings.System.INCREASING_RING_START_VOLUME, 0.1f); rampUpTime = Settings.System.getInt(cr, Settings.System.INCREASING_RING_RAMP_UP_TIME, 20); } mCallAudioManager.setIsRinging(true); // Because we wait until a contact info query to complete before processing a // 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 // request the custom ringtone from the call and expect it to be current. mRingtonePlayer.play(foregroundCall.getRingtone()); mRingtonePlayer.play(foregroundCall.getRingtone(), startVolume, rampUpTime); } else { Log.v(this, "startRingingOrCallWaiting, skipping because volume is 0"); } Loading