diff options
author | Danny Baumann <dannybaumann@web.de> | 2014-11-11 14:51:11 +0100 |
---|---|---|
committer | Bruno Martins <bgcngm@gmail.com> | 2017-12-11 13:12:46 +0000 |
commit | 78776779c8fedede8e672ac2bf2391c4b3a001ba (patch) | |
tree | 0650c58ad6ee0ae634c04f643187a6ca20c7d3e6 | |
parent | fe46f32a309ddcf11ffdae9b0323df2aee235b00 (diff) | |
download | android_packages_services_Telecomm-78776779c8fedede8e672ac2bf2391c4b3a001ba.tar.gz android_packages_services_Telecomm-78776779c8fedede8e672ac2bf2391c4b3a001ba.tar.bz2 android_packages_services_Telecomm-78776779c8fedede8e672ac2bf2391c4b3a001ba.zip |
Add back increasing ring feature (3/3).
Change-Id: I6c0582ff92fea06ee18df6d084790b420b1b58f6
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | src/com/android/server/telecom/AsyncRingtonePlayer.java | 32 | ||||
-rw-r--r-- | src/com/android/server/telecom/Ringer.java | 17 |
3 files changed, 48 insertions, 2 deletions
@@ -7,6 +7,7 @@ LOCAL_JAVA_LIBRARIES := telephony-common LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-proto-files-under, proto) LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res +LOCAL_STATIC_JAVA_LIBRARIES := org.lineageos.platform.sdk LOCAL_PROTOC_OPTIMIZE_TYPE := nano LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)/proto/ diff --git a/src/com/android/server/telecom/AsyncRingtonePlayer.java b/src/com/android/server/telecom/AsyncRingtonePlayer.java index 7ed1c859..b4c8947b 100644 --- a/src/com/android/server/telecom/AsyncRingtonePlayer.java +++ b/src/com/android/server/telecom/AsyncRingtonePlayer.java @@ -37,6 +37,7 @@ public 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; @@ -46,13 +47,18 @@ public class AsyncRingtonePlayer { /** The current ringtone. Only used by the ringtone thread. */ private Ringtone mRingtone; + private float mIncrementAmount; + private float mCurrentIncrementVolume; /** Plays the ringtone. */ - public void play(RingtoneFactory factory, Call incomingCall) { + public void play(RingtoneFactory factory, Call incomingCall, + float incStartVolume, int incRampUpTime) { Log.d(this, "Posting play."); SomeArgs args = SomeArgs.obtain(); args.arg1 = factory; args.arg2 = incomingCall; + args.argi1 = Math.round(incStartVolume * 100F); + args.argi2 = incRampUpTime; postMessage(EVENT_PLAY, true /* shouldCreateHandler */, args); } @@ -105,6 +111,15 @@ public 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; } } }; @@ -116,6 +131,8 @@ public class AsyncRingtonePlayer { private void handlePlay(SomeArgs args) { RingtoneFactory factory = (RingtoneFactory) args.arg1; Call incomingCall = (Call) args.arg2; + float incStartVolume = (float) args.argi1 / 100F; + int incRampUpTime = args.argi2; args.recycle(); // don't bother with any of this if there is an EVENT_STOP waiting. if (mHandler.hasMessages(EVENT_STOP)) { @@ -144,6 +161,18 @@ public 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(); } @@ -184,6 +213,7 @@ public 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."); diff --git a/src/com/android/server/telecom/Ringer.java b/src/com/android/server/telecom/Ringer.java index 36bb4ed8..8b0dcd84 100644 --- a/src/com/android/server/telecom/Ringer.java +++ b/src/com/android/server/telecom/Ringer.java @@ -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.os.VibrationEffect; import android.telecom.Log; @@ -28,6 +29,7 @@ import android.os.Bundle; import android.os.Vibrator; import com.android.internal.annotations.VisibleForTesting; +import lineageos.providers.LineageSettings; /** * Controls the ringtone player. @@ -152,11 +154,24 @@ public class Ringer { if (isRingerAudible) { mRingingCall = foregroundCall; Log.addEvent(foregroundCall, LogUtils.Events.START_RINGER); + + float startVolume = 0; + int rampUpTime = 0; + + final ContentResolver cr = mContext.getContentResolver(); + if (LineageSettings.System.getInt(cr, + LineageSettings.System.INCREASING_RING, 0) != 0) { + startVolume = LineageSettings.System.getFloat(cr, + LineageSettings.System.INCREASING_RING_START_VOLUME, 0.1f); + rampUpTime = LineageSettings.System.getInt(cr, + LineageSettings.System.INCREASING_RING_RAMP_UP_TIME, 20); + } + // 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(mRingtoneFactory, foregroundCall); + mRingtonePlayer.play(mRingtoneFactory, foregroundCall, startVolume, rampUpTime); } else { Log.i(this, "startRinging: skipping because ringer would not be audible. " + "isVolumeOverZero=%s, shouldRingForContact=%s, isRingtonePresent=%s", |