diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-12-11 21:48:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-12-11 21:48:29 +0000 |
commit | 04e88264e69ec2b6974a4d9d6acfa7cd27934e5a (patch) | |
tree | 8d3fe7e8212bfaf312bb5159f898b56a7004f84e /java/com/android/dialer/simulator | |
parent | aab6dc9f075fd8576ffc78c1f983b8fb1d3e77fa (diff) | |
parent | 9ad8a72f81d9868e50e27199bbca248090e7aba9 (diff) |
Merge "Update Spam module to use Dagger"
Diffstat (limited to 'java/com/android/dialer/simulator')
-rw-r--r-- | java/com/android/dialer/simulator/impl/SimulatorNotifications.java | 10 | ||||
-rw-r--r-- | java/com/android/dialer/simulator/impl/SimulatorSpamCallCreator.java | 155 |
2 files changed, 1 insertions, 164 deletions
diff --git a/java/com/android/dialer/simulator/impl/SimulatorNotifications.java b/java/com/android/dialer/simulator/impl/SimulatorNotifications.java index a243c34c3..bd17b7ff8 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorNotifications.java +++ b/java/com/android/dialer/simulator/impl/SimulatorNotifications.java @@ -35,15 +35,7 @@ final class SimulatorNotifications { return new SimulatorSubMenu(context) .addItem( "Missed calls", () -> new SimulatorMissedCallCreator(context).start(NOTIFICATION_COUNT)) - .addItem("Voicemails", () -> addVoicemailNotifications(context)) - .addItem( - "Non spam", - () -> - new SimulatorSpamCallCreator(context, false /* isSpam */).start(NOTIFICATION_COUNT)) - .addItem( - "Confirm spam", - () -> - new SimulatorSpamCallCreator(context, true /* isSpam */).start(NOTIFICATION_COUNT)); + .addItem("Voicemails", () -> addVoicemailNotifications(context)); } private static void addVoicemailNotifications(@NonNull Context context) { diff --git a/java/com/android/dialer/simulator/impl/SimulatorSpamCallCreator.java b/java/com/android/dialer/simulator/impl/SimulatorSpamCallCreator.java deleted file mode 100644 index a843ec03f..000000000 --- a/java/com/android/dialer/simulator/impl/SimulatorSpamCallCreator.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source 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.dialer.simulator.impl; - -import android.content.ContentProviderOperation; -import android.content.Context; -import android.content.OperationApplicationException; -import android.os.Bundle; -import android.os.RemoteException; -import android.provider.CallLog; -import android.support.annotation.NonNull; -import android.telecom.Connection; -import android.telecom.DisconnectCause; -import com.android.dialer.common.Assert; -import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.ThreadUtil; -import com.android.dialer.spam.Spam; -import com.android.dialer.spam.SpamBindingsStub; -import java.util.ArrayList; - -/** - * Creates many spam call notifications by adding new incoming calls one at a time and disconnecting - * them. - */ -final class SimulatorSpamCallCreator implements SimulatorConnectionService.Listener { - private static final String EXTRA_CALL_COUNT = "call_count"; - private static final String EXTRA_IS_SPAM_CALL_CONNECTION = "is_spam_call_connection"; - private static final int DISCONNECT_DELAY_MILLIS = 1000; - - private final Context context; - private final boolean isSpam; - - SimulatorSpamCallCreator(@NonNull Context context, boolean isSpam) { - this.context = Assert.isNotNull(context); - this.isSpam = isSpam; - } - - public void start(int callCount) { - Spam.setForTesting(new SimulatorSpamBindings(isSpam)); - SimulatorConnectionService.addListener(this); - addNextIncomingCall(callCount); - } - - @Override - public void onNewOutgoingConnection(@NonNull SimulatorConnection connection) {} - - @Override - public void onNewIncomingConnection(@NonNull SimulatorConnection connection) { - if (!isSpamCallConnection(connection)) { - return; - } - ThreadUtil.postDelayedOnUiThread( - () -> { - LogUtil.i("SimulatorSpamCallCreator.onNewIncomingConnection", "disconnecting"); - connection.setActive(); - connection.setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); - ThreadUtil.postDelayedOnUiThread( - () -> addNextIncomingCall(getCallCount(connection)), DISCONNECT_DELAY_MILLIS); - }, - DISCONNECT_DELAY_MILLIS); - } - - @Override - public void onConference( - @NonNull SimulatorConnection connection1, @NonNull SimulatorConnection connection2) {} - - private void addNextIncomingCall(int callCount) { - if (callCount <= 0) { - LogUtil.i("SimulatorSpamCallCreator.addNextIncomingCall", "done adding calls"); - SimulatorConnectionService.removeListener(this); - Spam.setForTesting(null); - return; - } - - // Caller ID must be e.164 formatted and unique. - String callerId = String.format("+1-650-234%04d", callCount); - Bundle extras = new Bundle(); - extras.putInt(EXTRA_CALL_COUNT, callCount - 1); - extras.putBoolean(EXTRA_IS_SPAM_CALL_CONNECTION, true); - - // We need to clear the call log because spam notifications are only shown for new calls. - clearCallLog(context); - - SimulatorSimCallManager.addNewIncomingCall(context, callerId, false /* isVideo */, extras); - } - - private static boolean isSpamCallConnection(@NonNull Connection connection) { - return connection.getExtras().getBoolean(EXTRA_IS_SPAM_CALL_CONNECTION); - } - - private static int getCallCount(@NonNull Connection connection) { - return connection.getExtras().getInt(EXTRA_CALL_COUNT); - } - - private static void clearCallLog(@NonNull Context context) { - try { - ArrayList<ContentProviderOperation> operations = new ArrayList<>(); - operations.add(ContentProviderOperation.newDelete(CallLog.Calls.CONTENT_URI).build()); - context.getContentResolver().applyBatch(CallLog.AUTHORITY, operations); - } catch (RemoteException | OperationApplicationException e) { - Assert.fail("failed to clear call log: " + e); - } - } - - /** - * Custom spam bindings that allow us to override which phone numbers are considered to be spam. - * Also disables throttling of spam notifications. - */ - private static class SimulatorSpamBindings extends SpamBindingsStub { - private final boolean isSpam; - - SimulatorSpamBindings(boolean isSpam) { - this.isSpam = isSpam; - } - - @Override - public boolean isSpamEnabled() { - return true; - } - - @Override - public boolean isSpamNotificationEnabled() { - return true; - } - - @Override - public int percentOfSpamNotificationsToShow() { - return 100; - } - - @Override - public int percentOfNonSpamNotificationsToShow() { - return 100; - } - - @Override - public void checkSpamStatus(String number, String countryIso, Listener listener) { - listener.onComplete(isSpam); - } - } -} |