summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--InCallUI/src/com/android/incallui/Call.java16
-rw-r--r--InCallUI/src/com/android/incallui/CallList.java49
-rw-r--r--InCallUI/src/com/android/incallui/InCallServiceImpl.java12
3 files changed, 71 insertions, 6 deletions
diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java
index 932e712b4..7418218e7 100644
--- a/InCallUI/src/com/android/incallui/Call.java
+++ b/InCallUI/src/com/android/incallui/Call.java
@@ -60,6 +60,7 @@ public class Call {
public static final int CONFERENCED = 11; /* Call part of a conference call */
public static final int SELECT_PHONE_ACCOUNT = 12; /* Waiting for account selection */
public static final int CONNECTING = 13; /* Waiting for Telecom broadcast to finish */
+ public static final int BLOCKED = 14; /* The number was found on the block list */
public static boolean isConnectingOrConnected(int state) {
@@ -112,6 +113,8 @@ public class Call {
return "SELECT_PHONE_ACCOUNT";
case CONNECTING:
return "CONNECTING";
+ case BLOCKED:
+ return "BLOCKED";
default:
return "UNKNOWN";
}
@@ -307,8 +310,11 @@ public class Call {
private void updateFromTelecomCall() {
Log.d(this, "updateFromTelecomCall: " + mTelecomCall.toString());
- setState(translateState(mTelecomCall.getState()));
- setDisconnectCause(mTelecomCall.getDetails().getDisconnectCause());
+ final int translatedState = translateState(mTelecomCall.getState());
+ if (mState != State.BLOCKED) {
+ setState(translatedState);
+ setDisconnectCause(mTelecomCall.getDetails().getDisconnectCause());
+ }
if (mTelecomCall.getVideoCall() != null) {
if (mVideoCallCallback == null) {
@@ -414,6 +420,12 @@ public class Call {
return getHandle() == null ? null : getHandle().getSchemeSpecificPart();
}
+ public void blockCall() {
+ // TODO: Some vibration still occurs.
+ mTelecomCall.reject(false, null);
+ setState(State.BLOCKED);
+ }
+
public Uri getHandle() {
return mTelecomCall == null ? null : mTelecomCall.getDetails().getHandle();
}
diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java
index 4e3315dab..8a58e5568 100644
--- a/InCallUI/src/com/android/incallui/CallList.java
+++ b/InCallUI/src/com/android/incallui/CallList.java
@@ -23,6 +23,7 @@ import android.telecom.DisconnectCause;
import android.telecom.PhoneAccount;
import com.android.contacts.common.testing.NeededForTesting;
+import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
@@ -33,6 +34,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
/**
* Maintains the list of active calls and notifies interested classes of changes to the call list
@@ -46,6 +48,7 @@ public class CallList {
private static final int DISCONNECTED_CALL_LONG_TIMEOUT_MS = 5000;
private static final int EVENT_DISCONNECTED_TIMEOUT = 1;
+ private static final long BLOCK_QUERY_TIMEOUT_MS = 1000;
private static CallList sInstance = new CallList();
@@ -63,6 +66,7 @@ public class CallList {
.newHashMap();
private final Set<Call> mPendingDisconnectCalls = Collections.newSetFromMap(
new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1));
+ private FilteredNumberAsyncQueryHandler mFilteredQueryHandler;
/**
* Static singleton accessor method.
@@ -79,17 +83,52 @@ public class CallList {
CallList() {
}
- public void onCallAdded(android.telecom.Call telecomCall) {
+ public void onCallAdded(android.telecom.Call telecomCall, final String countryIso) {
Trace.beginSection("onCallAdded");
- Call call = new Call(telecomCall);
+ final Call call = new Call(telecomCall);
Log.d(this, "onCallAdded: callState=" + call.getState());
+ // Check if call should be blocked.
+ if (!call.isEmergencyCall() && call.getState() == Call.State.INCOMING) {
+ final AtomicBoolean hasTimedOut = new AtomicBoolean(false);
+ // Proceed with call if query is slow.
+ // Call may be blocked later when FilteredQueryHandler returns.
+ final Handler handler = new Handler();
+ final Runnable runnable = new Runnable() {
+ public void run() {
+ hasTimedOut.set(true);
+ onCallAddedInternal(call);
+ }
+ };
+ handler.postDelayed(runnable, BLOCK_QUERY_TIMEOUT_MS);
+ mFilteredQueryHandler.isBlocked(
+ new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() {
+ @Override
+ public void onCheckComplete(final Integer id) {
+ if (!hasTimedOut.get()) {
+ handler.removeCallbacks(runnable);
+ }
+ if (id == null) {
+ if (!hasTimedOut.get()) {
+ onCallAddedInternal(call);
+ }
+ } else {
+ call.blockCall();
+ }
+ }
+ }, null, call.getNumber(), countryIso);
+ } else {
+ onCallAddedInternal(call);
+ }
+ Trace.endSection();
+ }
+
+ private void onCallAddedInternal(Call call) {
if (call.getState() == Call.State.INCOMING ||
call.getState() == Call.State.CALL_WAITING) {
onIncoming(call, call.getCannedSmsResponses());
} else {
onUpdate(call);
}
- Trace.endSection();
}
public void onCallRemoved(android.telecom.Call telecomCall) {
@@ -582,6 +621,10 @@ public class CallList {
}
};
+ public void setFilteredNumberQueryHandler(FilteredNumberAsyncQueryHandler handler) {
+ mFilteredQueryHandler = handler;
+ }
+
/**
* Listener interface for any class that wants to be notified of changes
* to the call list.
diff --git a/InCallUI/src/com/android/incallui/InCallServiceImpl.java b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
index b9a5aae87..6078d3d20 100644
--- a/InCallUI/src/com/android/incallui/InCallServiceImpl.java
+++ b/InCallUI/src/com/android/incallui/InCallServiceImpl.java
@@ -23,6 +23,11 @@ import android.telecom.Call;
import android.telecom.CallAudioState;
import android.telecom.InCallService;
+import com.android.contacts.common.util.TelephonyManagerUtils;
+import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
+
+import java.util.Locale;
+
/**
* Used to receive updates about calls from the Telecom component. This service is bound to
* Telecom while there exist calls which potentially require UI. This includes ringing (incoming),
@@ -43,7 +48,10 @@ public class InCallServiceImpl extends InCallService {
@Override
public void onCallAdded(Call call) {
- CallList.getInstance().onCallAdded(call);
+ final String countryIso = TelephonyManagerUtils.getCurrentCountryIso(
+ getApplicationContext(),
+ Locale.getDefault());
+ CallList.getInstance().onCallAdded(call, countryIso);
InCallPresenter.getInstance().onCallAdded(call);
}
@@ -76,6 +84,8 @@ public class InCallServiceImpl extends InCallService {
InCallPresenter.getInstance().onServiceBind();
InCallPresenter.getInstance().maybeStartRevealAnimation(intent);
TelecomAdapter.getInstance().setInCallService(this);
+ CallList.getInstance().setFilteredNumberQueryHandler(
+ new FilteredNumberAsyncQueryHandler(getContentResolver()));
return super.onBind(intent);
}