summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2016-09-09 08:01:27 (GMT)
committerBruno Martins <bgcngm@gmail.com>2017-10-27 10:20:04 (GMT)
commit4a8a7d872f5239f5070af4f9706a60178298208e (patch)
tree7d109d5c8e4d9e2e5a54a7386f03c0e95b839ccc
parent14755fe043a85206ab5e78f62f28a04e0de5ef11 (diff)
downloadandroid_packages_apps_Dialer-lineage-15.0.zip
android_packages_apps_Dialer-lineage-15.0.tar.gz
android_packages_apps_Dialer-lineage-15.0.tar.bz2
Add back in-call vibration featureslineage-15.0
Change-Id: Ia30a3c46e9c37d7d73288ec605af8efc3a46a323
-rw-r--r--java/com/android/dialer/app/res/values/cm_strings.xml25
-rw-r--r--java/com/android/dialer/app/res/xml/sound_settings.xml23
-rw-r--r--java/com/android/dialer/app/settings/SoundSettingsFragment.java6
-rw-r--r--java/com/android/incallui/InCallPresenter.java9
-rw-r--r--java/com/android/incallui/InCallVibrationHandler.java142
-rw-r--r--java/com/android/incallui/call/DialerCall.java7
6 files changed, 211 insertions, 1 deletions
diff --git a/java/com/android/dialer/app/res/values/cm_strings.xml b/java/com/android/dialer/app/res/values/cm_strings.xml
new file mode 100644
index 0000000..90e6480
--- /dev/null
+++ b/java/com/android/dialer/app/res/values/cm_strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013-2014 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="incall_vibration_category_key" translatable="false">dialer_general_incall_vibration_category_key</string>
+ <string name="incall_vibration_category_title">In-call vibration</string>
+ <string name="incall_vibrate_outgoing_title">Vibrate on answer</string>
+ <string name="incall_vibrate_call_waiting_title">Vibrate on call waiting</string>
+ <string name="incall_vibrate_hangup_title">Vibrate on hang up</string>
+ <string name="incall_vibrate_45_title">Vibrate every minute</string>
+ <string name="incall_vibrate_45_summary">Vibrates at the 45 second mark of every minute during outgoing calls</string>
+</resources>
diff --git a/java/com/android/dialer/app/res/xml/sound_settings.xml b/java/com/android/dialer/app/res/xml/sound_settings.xml
index 796ed2e..12cddb1 100644
--- a/java/com/android/dialer/app/res/xml/sound_settings.xml
+++ b/java/com/android/dialer/app/res/xml/sound_settings.xml
@@ -43,4 +43,27 @@
android:key="@string/dtmf_tone_length_preference_key"
android:title="@string/dtmf_tone_length_title"/>
+ <PreferenceCategory
+ android:key="@string/incall_vibration_category_key"
+ android:title="@string/incall_vibration_category_title">
+
+ <CheckBoxPreference
+ android:key="incall_vibrate_outgoing"
+ android:title="@string/incall_vibrate_outgoing_title" />
+
+ <CheckBoxPreference
+ android:key="incall_vibrate_call_waiting"
+ android:title="@string/incall_vibrate_call_waiting_title" />
+
+ <CheckBoxPreference
+ android:key="incall_vibrate_hangup"
+ android:title="@string/incall_vibrate_hangup_title" />
+
+ <CheckBoxPreference
+ android:key="incall_vibrate_45secs"
+ android:title="@string/incall_vibrate_45_title"
+ android:summary="@string/incall_vibrate_45_summary" />
+
+ </PreferenceCategory>
+
</PreferenceScreen>
diff --git a/java/com/android/dialer/app/settings/SoundSettingsFragment.java b/java/com/android/dialer/app/settings/SoundSettingsFragment.java
index 83ce453..8c0c0f6 100644
--- a/java/com/android/dialer/app/settings/SoundSettingsFragment.java
+++ b/java/com/android/dialer/app/settings/SoundSettingsFragment.java
@@ -97,7 +97,11 @@ public class SoundSettingsFragment extends PreferenceFragment
if (hasVibrator()) {
mVibrateWhenRinging.setOnPreferenceChangeListener(this);
} else {
- getPreferenceScreen().removePreference(mVibrateWhenRinging);
+ PreferenceScreen ps = getPreferenceScreen();
+ Preference inCallVibration = findPreference(
+ context.getString(R.string.incall_vibration_category_key));
+ ps.removePreference(mVibrateWhenRinging);
+ ps.removePreference(inCallVibration);
mVibrateWhenRinging = null;
}
diff --git a/java/com/android/incallui/InCallPresenter.java b/java/com/android/incallui/InCallPresenter.java
index 2d6d83c..510a407 100644
--- a/java/com/android/incallui/InCallPresenter.java
+++ b/java/com/android/incallui/InCallPresenter.java
@@ -109,6 +109,7 @@ public class InCallPresenter implements CallList.Listener {
private StatusBarNotifier mStatusBarNotifier;
private ExternalCallNotifier mExternalCallNotifier;
+ private InCallVibrationHandler mVibrationHandler;
private ContactInfoCache mContactInfoCache;
private Context mContext;
private final OnCheckBlockedListener mOnCheckBlockedListener =
@@ -333,6 +334,9 @@ public class InCallPresenter implements CallList.Listener {
.getEnrichedCallManager()
.registerStateChangedListener(mStatusBarNotifier);
+ mVibrationHandler = new InCallVibrationHandler(context);
+ addListener(mVibrationHandler);
+
mProximitySensor = proximitySensor;
addListener(mProximitySensor);
@@ -1403,6 +1407,11 @@ public class InCallPresenter implements CallList.Listener {
}
mStatusBarNotifier = null;
+ if (mVibrationHandler != null) {
+ removeListener(mVibrationHandler);
+ }
+ mVibrationHandler = null;
+
if (mCallList != null) {
mCallList.removeListener(this);
mCallList.removeListener(mSpamCallListListener);
diff --git a/java/com/android/incallui/InCallVibrationHandler.java b/java/com/android/incallui/InCallVibrationHandler.java
new file mode 100644
index 0000000..eb82ad5
--- /dev/null
+++ b/java/com/android/incallui/InCallVibrationHandler.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2014 The CyanogenMod Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.incallui;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Vibrator;
+import android.preference.PreferenceManager;
+import android.telecom.DisconnectCause;
+
+import com.android.incallui.call.CallList;
+import com.android.incallui.call.DialerCall;
+import com.android.incallui.InCallPresenter.InCallState;
+
+public class InCallVibrationHandler extends Handler implements
+ InCallPresenter.InCallStateListener {
+
+ private static final int MSG_VIBRATE_45_SEC = 1;
+
+ private static final String KEY_VIBRATE_CALL_WAITING = "incall_vibrate_call_waiting";
+ private static final String KEY_VIBRATE_OUTGOING = "incall_vibrate_outgoing";
+ private static final String KEY_VIBRATE_45SECS = "incall_vibrate_45secs";
+ private static final String KEY_VIBRATE_HANGUP = "incall_vibrate_hangup";
+
+ private SharedPreferences mPrefs;
+ private Vibrator mVibrator;
+ private DialerCall mActiveCall;
+
+ public InCallVibrationHandler(Context context) {
+ mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+ mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_VIBRATE_45_SEC:
+ vibrate(70, 0, 0);
+ sendEmptyMessageDelayed(MSG_VIBRATE_45_SEC, 60000);
+ break;
+ }
+ }
+
+ @Override
+ public void onStateChange(InCallState oldState, InCallState newState, CallList callList) {
+ DialerCall activeCall = callList.getActiveCall();
+
+ if (activeCall != null && mActiveCall == null) {
+ Log.d(this, "Transition to active call " + activeCall);
+ if (activeCall.isOutgoing()) {
+ handleOutgoingCallVibration(activeCall);
+ }
+ mActiveCall = activeCall;
+ } else if (activeCall != null && callList.getIncomingCall() != null
+ && !callList.getIncomingCall().equals(activeCall)) {
+ Log.d(this, "New incoming call" + callList.getIncomingCall());
+ handleCallWaitingVibration(activeCall);
+ } else if (activeCall == null && mActiveCall != null) {
+ Log.d(this, "Transition from active call " + mActiveCall);
+ handleCallEnd(mActiveCall);
+ mActiveCall = null;
+ }
+ }
+
+ private void handleOutgoingCallVibration(DialerCall call) {
+ long durationMillis = System.currentTimeMillis() - call.getConnectTimeMillis();
+ Log.d(this, "Start outgoing call: duration = " + durationMillis);
+
+ if (mPrefs.getBoolean(KEY_VIBRATE_OUTGOING, false) && durationMillis < 200) {
+ vibrate(100, 200, 0);
+ }
+ if (mPrefs.getBoolean(KEY_VIBRATE_45SECS, false)) {
+ start45SecondVibration(durationMillis);
+ }
+ }
+
+ private void handleCallWaitingVibration(DialerCall call) {
+ Log.d(this, "Start call waiting vibration");
+ if (mPrefs.getBoolean(KEY_VIBRATE_CALL_WAITING, false)) {
+ vibrate(200, 300, 500);
+ }
+ }
+
+ private void handleCallEnd(DialerCall call) {
+ long durationMillis = System.currentTimeMillis() - call.getConnectTimeMillis();
+ DisconnectCause cause = call.getDisconnectCause();
+ boolean localDisconnect =
+ // Disconnection not yet processed
+ call.getState() == DialerCall.State.DISCONNECTING ||
+ // Disconnection already processed
+ (cause != null && cause.getCode() == DisconnectCause.LOCAL);
+
+ Log.d(this, "Ending active call: duration = " + durationMillis
+ + ", locally disconnected = " + localDisconnect);
+
+ if (mPrefs.getBoolean(KEY_VIBRATE_HANGUP, false)
+ && !localDisconnect && durationMillis > 500) {
+ vibrate(50, 100, 50);
+ }
+ // Stop 45-second vibration
+ removeMessages(MSG_VIBRATE_45_SEC);
+ }
+
+ private void start45SecondVibration(long callDurationMillis) {
+ callDurationMillis = callDurationMillis % 60000;
+ Log.d(this, "vibrate start @" + callDurationMillis);
+ removeMessages(MSG_VIBRATE_45_SEC);
+
+ long timer;
+ if (callDurationMillis > 45000) {
+ // Schedule the alarm at the next minute + 45 secs
+ timer = 45000 + 60000 - callDurationMillis;
+ } else {
+ // Schedule the alarm at the first 45 second mark
+ timer = 45000 - callDurationMillis;
+ }
+ sendEmptyMessageDelayed(MSG_VIBRATE_45_SEC, timer);
+ }
+
+ private void vibrate(int v1, int p1, int v2) {
+ long[] pattern = new long[] {
+ 0, v1, p1, v2
+ };
+ mVibrator.vibrate(pattern, -1);
+ }
+}
diff --git a/java/com/android/incallui/call/DialerCall.java b/java/com/android/incallui/call/DialerCall.java
index acedf41..7330820 100644
--- a/java/com/android/incallui/call/DialerCall.java
+++ b/java/com/android/incallui/call/DialerCall.java
@@ -131,6 +131,7 @@ public class DialerCall implements VideoTechListener {
private String mCallSubject;
private PhoneAccountHandle mPhoneAccountHandle;
@CallHistoryStatus private int mCallHistoryStatus = CALL_HISTORY_STATUS_UNKNOWN;
+ private boolean mIsOutgoing = false;
private boolean mIsSpam;
private boolean mIsBlocked;
private boolean isInUserSpamList;
@@ -653,9 +654,15 @@ public class DialerCall implements VideoTechListener {
} else if (mState == State.DISCONNECTED) {
mLogState.duration =
getConnectTimeMillis() == 0 ? 0 : System.currentTimeMillis() - getConnectTimeMillis();
+ } else if (mState == State.DIALING || mState == State.CONNECTING) {
+ mIsOutgoing = true;
}
}
+ public boolean isOutgoing() {
+ return mIsOutgoing;
+ }
+
public int getNumberPresentation() {
return mTelecomCall == null ? -1 : mTelecomCall.getDetails().getHandlePresentation();
}