From 268aed51f835788ef44329db50b62b34215b9203 Mon Sep 17 00:00:00 2001 From: weijiaxu Date: Fri, 26 Jan 2018 10:56:13 -0800 Subject: Add enriched calling simulation. Test: on a local device. PiperOrigin-RevId: 183414102 Change-Id: I56efda40994e9f0b84f462e42301adbf625273e5 --- java/com/android/dialer/simulator/Simulator.java | 13 +++++ .../dialer/simulator/SimulatorEnrichedCall.java | 9 ++-- .../dialer/simulator/impl/SimulatorImpl.java | 19 ++++++- .../dialer/simulator/impl/SimulatorMainMenu.java | 15 +++++- .../dialer/simulator/impl/SimulatorVoiceCall.java | 62 +++++++++++++++++++--- .../simulator/stub/SimulatorEnrichedCallStub.java | 10 ++-- 6 files changed, 110 insertions(+), 18 deletions(-) diff --git a/java/com/android/dialer/simulator/Simulator.java b/java/com/android/dialer/simulator/Simulator.java index 3931ae49f..3c2526be7 100644 --- a/java/com/android/dialer/simulator/Simulator.java +++ b/java/com/android/dialer/simulator/Simulator.java @@ -63,11 +63,24 @@ public interface Simulator { @StringDef({ IS_VOLTE, PRESENTATION_CHOICE, + IS_ENRICHED_CALL, }) @interface BundleKey {} public final String IS_VOLTE = "ISVOLTE"; public final String PRESENTATION_CHOICE = "PRESENTATIONCHOICE"; + public final String IS_ENRICHED_CALL = "ISENRICHEDCALL"; + + /** Phone numbers for outgoing and incoming enriched call scenario. */ + public static final String ENRICHED_CALL_OUTGOING_NUMBER = "+55-31-2128-6800"; + + public static final String ENRICHED_CALL_INCOMING_NUMBER = "+44 (0) 20 7031 3000"; + + boolean isSimulatorMode(); + + void enableSimulatorMode(); + + void disableSimulatorMode(); /** Information about a connection event. */ public static class Event { diff --git a/java/com/android/dialer/simulator/SimulatorEnrichedCall.java b/java/com/android/dialer/simulator/SimulatorEnrichedCall.java index f6c8a6cd9..ae9447b7a 100644 --- a/java/com/android/dialer/simulator/SimulatorEnrichedCall.java +++ b/java/com/android/dialer/simulator/SimulatorEnrichedCall.java @@ -16,13 +16,14 @@ package com.android.dialer.simulator; -import com.android.dialer.enrichedcall.EnrichedCallManager.StateChangedListener; +import com.android.dialer.enrichedcall.EnrichedCallManager; +import com.google.common.util.concurrent.ListenableFuture; /** Setup enriched calling environment for {@link Simulator}. */ -public interface SimulatorEnrichedCall extends StateChangedListener { +public interface SimulatorEnrichedCall extends EnrichedCallManager.StateChangedListener { /** Setup a session for an incoming enriched call. */ - long setupIncomingEnrichedCall(String number); + ListenableFuture setupIncomingEnrichedCall(String number); /** Setup a session for outgoing enriched call. */ - long setupOutgoingEnrichedCall(String number); + ListenableFuture setupOutgoingEnrichedCall(String number); } diff --git a/java/com/android/dialer/simulator/impl/SimulatorImpl.java b/java/com/android/dialer/simulator/impl/SimulatorImpl.java index be8676392..24f34102e 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorImpl.java +++ b/java/com/android/dialer/simulator/impl/SimulatorImpl.java @@ -25,7 +25,9 @@ import javax.inject.Inject; /** The entry point for the simulator feature. */ final class SimulatorImpl implements Simulator { - + + private boolean simulatorMode = false; + @Inject public SimulatorImpl() {} @@ -38,4 +40,19 @@ final class SimulatorImpl implements Simulator { public ActionProvider getActionProvider(AppCompatActivity activity) { return SimulatorMainMenu.getActionProvider(activity); } + + @Override + public boolean isSimulatorMode() { + return simulatorMode; + } + + @Override + public void enableSimulatorMode() { + simulatorMode = true; + } + + @Override + public void disableSimulatorMode() { + simulatorMode = false; + } } diff --git a/java/com/android/dialer/simulator/impl/SimulatorMainMenu.java b/java/com/android/dialer/simulator/impl/SimulatorMainMenu.java index 174aab5ad..69da2f4cc 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorMainMenu.java +++ b/java/com/android/dialer/simulator/impl/SimulatorMainMenu.java @@ -32,6 +32,7 @@ import com.android.dialer.databasepopulator.VoicemailPopulator; import com.android.dialer.enrichedcall.simulator.EnrichedCallSimulatorActivity; import com.android.dialer.persistentlog.PersistentLogger; import com.android.dialer.preferredsim.PreferredSimFallbackContract; +import com.android.dialer.simulator.SimulatorComponent; import com.android.incallui.rtt.impl.RttChatActivity; import com.android.incallui.speakeasy.SpeakEasy; import com.android.incallui.speakeasy.SpeakEasyActivity; @@ -65,7 +66,19 @@ final class SimulatorMainMenu { "Enriched call simulator", () -> activity.startActivity( - EnrichedCallSimulatorActivity.newIntent(activity.getApplicationContext()))); + EnrichedCallSimulatorActivity.newIntent(activity.getApplicationContext()))) + .addItem( + "Enable simulator mode", + () -> + SimulatorComponent.get(activity.getApplicationContext()) + .getSimulator() + .enableSimulatorMode()) + .addItem( + "Disable simulator mode", + () -> + SimulatorComponent.get(activity.getApplicationContext()) + .getSimulator() + .disableSimulatorMode()); SpeakEasy speakEasy = SpeakEasyComponent.get(activity.getApplicationContext()).speakEasy(); if (speakEasy.isEnabled()) { simulatorSubMenu.addItem( diff --git a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java index ff00dd87e..67a2db804 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java +++ b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java @@ -26,15 +26,21 @@ import android.telecom.DisconnectCause; import android.view.ActionProvider; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.android.dialer.common.concurrent.DialerExecutorComponent; import com.android.dialer.common.concurrent.ThreadUtil; +import com.android.dialer.enrichedcall.EnrichedCallComponent; +import com.android.dialer.enrichedcall.EnrichedCallManager; import com.android.dialer.simulator.Simulator; import com.android.dialer.simulator.Simulator.Event; +import com.android.dialer.simulator.SimulatorComponent; +import com.android.dialer.simulator.SimulatorEnrichedCall; /** Entry point in the simulator to create voice calls. */ final class SimulatorVoiceCall implements SimulatorConnectionService.Listener, SimulatorConnection.Listener { @NonNull private final Context context; @Nullable private String connectionTag; + private final SimulatorEnrichedCall simulatorEnrichedCall; static ActionProvider getActionProvider(@NonNull AppCompatActivity activity) { return new SimulatorSubMenu(activity.getApplicationContext()) @@ -54,6 +60,12 @@ final class SimulatorVoiceCall () -> new SimulatorVoiceCall(activity.getApplicationContext()) .addNewOutgoingCall(activity)) + .addItem( + "Incoming enriched call", + () -> new SimulatorVoiceCall(activity.getApplicationContext()).incomingEnrichedCall()) + .addItem( + "Outgoing enriched call", + () -> new SimulatorVoiceCall(activity.getApplicationContext()).outgoingEnrichedCall()) .addItem( "Spam incoming call", () -> new SimulatorVoiceCall(activity.getApplicationContext()).addSpamIncomingCall()) @@ -77,23 +89,47 @@ final class SimulatorVoiceCall private SimulatorVoiceCall(@NonNull Context context) { this.context = Assert.isNotNull(context); + simulatorEnrichedCall = SimulatorComponent.get(context).getSimulatorEnrichedCall(); SimulatorConnectionService.addListener(this); SimulatorConnectionService.addListener( new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_GSM)); } + private void incomingEnrichedCall() { + simulatorEnrichedCall + .setupIncomingEnrichedCall(Simulator.ENRICHED_CALL_INCOMING_NUMBER) + .addListener( + () -> { + Bundle extras = new Bundle(); + extras.putBoolean(Simulator.IS_ENRICHED_CALL, true); + connectionTag = + SimulatorSimCallManager.addNewIncomingCall( + context, Simulator.ENRICHED_CALL_INCOMING_NUMBER, false, extras); + }, + DialerExecutorComponent.get(context).uiExecutor()); + } + + private void outgoingEnrichedCall() { + getEnrichedCallManager().registerStateChangedListener(simulatorEnrichedCall); + simulatorEnrichedCall + .setupOutgoingEnrichedCall(Simulator.ENRICHED_CALL_OUTGOING_NUMBER) + .addListener( + () -> { + Bundle extras = new Bundle(); + extras.putBoolean(Simulator.IS_ENRICHED_CALL, true); + connectionTag = + SimulatorSimCallManager.addNewOutgoingCall( + context, Simulator.ENRICHED_CALL_OUTGOING_NUMBER, false, extras); + }, + DialerExecutorComponent.get(context).uiExecutor()); + } + private void addNewIncomingCall() { String callerId = "+44 (0) 20 7031 3000" /* Google London office */; connectionTag = SimulatorSimCallManager.addNewIncomingCall(context, callerId, false /* isVideo */); } - private void addNewOutgoingCall() { - String callerId = "+55-31-2128-6800"; // Brazil office. - connectionTag = - SimulatorSimCallManager.addNewOutgoingCall(context, callerId, false /* isVideo */); - } - private void addNewIncomingCall(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { @@ -106,6 +142,12 @@ final class SimulatorVoiceCall .show(activity.getSupportFragmentManager(), "SimulatorDialog"); } + private void addNewOutgoingCall() { + String callerId = "+55-31-2128-6800"; // Brazil office. + connectionTag = + SimulatorSimCallManager.addNewOutgoingCall(context, callerId, false /* isVideo */); + } + private void addNewOutgoingCall(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { @@ -184,6 +226,9 @@ final class SimulatorVoiceCall break; case Event.DISCONNECT: connection.setDisconnected(new DisconnectCause(DisconnectCause.LOCAL)); + if (connection.getExtras().getBoolean(Simulator.IS_ENRICHED_CALL)) { + getEnrichedCallManager().unregisterStateChangedListener(simulatorEnrichedCall); + } break; case Event.SESSION_MODIFY_REQUEST: ThreadUtil.postDelayedOnUiThread(() -> connection.handleSessionModifyRequest(event), 2000); @@ -194,7 +239,8 @@ final class SimulatorVoiceCall } } - private interface DialogCallback { - void callback(String callerId, int callerIdPresentation); + @NonNull + private EnrichedCallManager getEnrichedCallManager() { + return EnrichedCallComponent.get(context).getEnrichedCallManager(); } } diff --git a/java/com/android/dialer/simulator/stub/SimulatorEnrichedCallStub.java b/java/com/android/dialer/simulator/stub/SimulatorEnrichedCallStub.java index 056722fab..5b0727134 100644 --- a/java/com/android/dialer/simulator/stub/SimulatorEnrichedCallStub.java +++ b/java/com/android/dialer/simulator/stub/SimulatorEnrichedCallStub.java @@ -17,6 +17,8 @@ package com.android.dialer.simulator.stub; import com.android.dialer.simulator.SimulatorEnrichedCall; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; import javax.inject.Inject; /** Stub implementation of {@link SimulatorEnrichedCall}. */ @@ -26,13 +28,13 @@ public class SimulatorEnrichedCallStub implements SimulatorEnrichedCall { public SimulatorEnrichedCallStub() {} @Override - public long setupIncomingEnrichedCall(String number) { - return -1; + public ListenableFuture setupIncomingEnrichedCall(String number) { + return Futures.immediateFuture(null); } @Override - public long setupOutgoingEnrichedCall(String number) { - return -1; + public ListenableFuture setupOutgoingEnrichedCall(String number) { + return Futures.immediateFuture(null); } @Override -- cgit v1.2.3