From 8e1eddf0b8dc8d52331eb4fefbe91d8ff187a8e8 Mon Sep 17 00:00:00 2001 From: weijiaxu Date: Tue, 15 May 2018 15:02:34 -0700 Subject: Refactoring simulator portal and related files. Delete simulator/portal package and move all files to simulator/impl package. Bug: 79488174 Test: presubmit test. PiperOrigin-RevId: 196735123 Change-Id: I2f578ca0912552ee32104d9ee5088bbb34ce5123 --- .../android/dialer/simulator/impl/RttChatBot.java | 6 +- .../simulator/impl/SimulatorConferenceCreator.java | 6 +- .../dialer/simulator/impl/SimulatorImpl.java | 1 - .../dialer/simulator/impl/SimulatorMainPortal.java | 191 ++++++++++++++++++++ .../dialer/simulator/impl/SimulatorMenu.java | 76 ++++++++ .../simulator/impl/SimulatorMissedCallCreator.java | 4 +- .../simulator/impl/SimulatorPortalEntryGroup.java | 45 +++++ .../dialer/simulator/impl/SimulatorRttCall.java | 10 +- .../dialer/simulator/impl/SimulatorVideoCall.java | 8 +- .../dialer/simulator/impl/SimulatorVoiceCall.java | 20 +-- .../simulator/portal/SimulatorMainPortal.java | 198 --------------------- .../dialer/simulator/portal/SimulatorMenu.java | 76 -------- .../portal/SimulatorPortalEntryGroup.java | 45 ----- 13 files changed, 339 insertions(+), 347 deletions(-) create mode 100644 java/com/android/dialer/simulator/impl/SimulatorMainPortal.java create mode 100644 java/com/android/dialer/simulator/impl/SimulatorMenu.java create mode 100644 java/com/android/dialer/simulator/impl/SimulatorPortalEntryGroup.java delete mode 100644 java/com/android/dialer/simulator/portal/SimulatorMainPortal.java delete mode 100644 java/com/android/dialer/simulator/portal/SimulatorMenu.java delete mode 100644 java/com/android/dialer/simulator/portal/SimulatorPortalEntryGroup.java (limited to 'java') diff --git a/java/com/android/dialer/simulator/impl/RttChatBot.java b/java/com/android/dialer/simulator/impl/RttChatBot.java index b2860e387..cd5234317 100644 --- a/java/com/android/dialer/simulator/impl/RttChatBot.java +++ b/java/com/android/dialer/simulator/impl/RttChatBot.java @@ -32,7 +32,7 @@ import java.util.Random; /** Chat bot to generate remote RTT chat messages. */ @TargetApi(28) -public class RttChatBot { +class RttChatBot { interface Callback { void type(String text); @@ -62,14 +62,14 @@ public class RttChatBot { } @MainThread - public void start() { + void start() { Assert.isMainThread(); LogUtil.enterBlock("RttChatBot.start"); messageHandler.sendEmptyMessage(START_SENDING); } @MainThread - public void stop() { + void stop() { Assert.isMainThread(); LogUtil.enterBlock("RttChatBot.stop"); if (handlerThread != null && handlerThread.isAlive()) { diff --git a/java/com/android/dialer/simulator/impl/SimulatorConferenceCreator.java b/java/com/android/dialer/simulator/impl/SimulatorConferenceCreator.java index 8e794f051..aec939848 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorConferenceCreator.java +++ b/java/com/android/dialer/simulator/impl/SimulatorConferenceCreator.java @@ -32,7 +32,7 @@ import java.util.ArrayList; import java.util.Locale; /** Creates a conference with a given number of participants. */ -public final class SimulatorConferenceCreator +final class SimulatorConferenceCreator implements SimulatorConnectionService.Listener, SimulatorConnection.Listener, SimulatorConference.Listener { @@ -46,7 +46,7 @@ public final class SimulatorConferenceCreator @Simulator.ConferenceType private final int conferenceType; - public SimulatorConferenceCreator( + SimulatorConferenceCreator( @NonNull Context context, @Simulator.ConferenceType int conferenceType) { this.context = Assert.isNotNull(context); this.conferenceType = conferenceType; @@ -58,7 +58,7 @@ public final class SimulatorConferenceCreator * * @param callCount the number of calls in conference to create. */ - public void start(int callCount) { + void start(int callCount) { onNewIncomingConnectionEnabled = true; SimulatorConnectionService.addListener(this); if (conferenceType == Simulator.CONFERENCE_TYPE_VOLTE) { diff --git a/java/com/android/dialer/simulator/impl/SimulatorImpl.java b/java/com/android/dialer/simulator/impl/SimulatorImpl.java index 44f8e118b..ee910ba2c 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorImpl.java +++ b/java/com/android/dialer/simulator/impl/SimulatorImpl.java @@ -22,7 +22,6 @@ import com.android.dialer.buildtype.BuildType; import com.android.dialer.buildtype.BuildType.Type; import com.android.dialer.common.LogUtil; import com.android.dialer.simulator.Simulator; -import com.android.dialer.simulator.portal.SimulatorMainPortal; import javax.inject.Inject; /** The entry point for the simulator feature. */ diff --git a/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java b/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java new file mode 100644 index 000000000..273826f70 --- /dev/null +++ b/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2018 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.Context; +import android.support.v7.app.AppCompatActivity; +import android.telecom.VideoProfile; +import android.view.ActionProvider; +import com.android.dialer.enrichedcall.simulator.EnrichedCallSimulatorActivity; +import com.android.dialer.simulator.Simulator; +import com.android.dialer.simulator.SimulatorComponent; +import com.google.common.collect.ImmutableMap; + +/** Implements the top level simulator menu. */ +public final class SimulatorMainPortal { + + private final Context context; + private final AppCompatActivity activity; + private SimulatorPortalEntryGroup simulatorMainPortal; + + public SimulatorMainPortal(AppCompatActivity activity) { + this.activity = activity; + this.context = activity.getApplicationContext(); + buildMainPortal(); + } + + private void buildMainPortal() { + this.simulatorMainPortal = + SimulatorPortalEntryGroup.builder() + .setMethods( + ImmutableMap.builder() + .put("Populate database", () -> SimulatorUtils.populateDatabase(context)) + .put("Populate voicemail", () -> SimulatorUtils.populateVoicemail(context)) + .put( + "Fast Populate database", + () -> SimulatorUtils.fastPopulateDatabase(context)) + .put( + "Fast populate voicemail database", + () -> SimulatorUtils.populateVoicemailFast(context)) + .put("Clean database", () -> SimulatorUtils.cleanDatabase(context)) + .put("clear preferred SIM", () -> SimulatorUtils.clearPreferredSim(context)) + .put("Sync voicemail", () -> SimulatorUtils.syncVoicemail(context)) + .put("Share persistent log", () -> SimulatorUtils.sharePersistentLog(context)) + .put( + "Enriched call simulator", + () -> + context.startActivity(EnrichedCallSimulatorActivity.newIntent(context))) + .put( + "Enable simulator mode", + () -> { + SimulatorComponent.get(context).getSimulator().enableSimulatorMode(); + SimulatorSimCallManager.register(context); + }) + .put( + "Disable simulator mode", + () -> { + SimulatorComponent.get(context).getSimulator().disableSimulatorMode(); + SimulatorSimCallManager.unregister(context); + }) + .build()) + .setSubPortals( + ImmutableMap.of( + "VoiceCall", + buildSimulatorVoiceCallPortal(), + "VideoCall", + buildSimulatorVideoCallPortal(), + "RttCall", + buildSimulatorRttCallPortal(), + "Notifications", + buildSimulatorNotificationsPortal())) + .build(); + } + + public SimulatorPortalEntryGroup buildSimulatorVoiceCallPortal() { + return SimulatorPortalEntryGroup.builder() + .setMethods( + ImmutableMap.builder() + .put("Incoming call", () -> new SimulatorVoiceCall(context).addNewIncomingCall()) + .put("Outgoing call", () -> new SimulatorVoiceCall(context).addNewOutgoingCall()) + .put( + "Customized incoming call", + () -> new SimulatorVoiceCall(context).addNewIncomingCall(activity)) + .put( + "Customized outgoing call", + () -> new SimulatorVoiceCall(context).addNewOutgoingCall(activity)) + .put( + "Incoming enriched call", + () -> new SimulatorVoiceCall(context).incomingEnrichedCall()) + .put( + "Outgoing enriched call", + () -> new SimulatorVoiceCall(context).outgoingEnrichedCall()) + .put( + "Spam incoming call", + () -> new SimulatorVoiceCall(context).addSpamIncomingCall()) + .put( + "Emergency call back", + () -> new SimulatorVoiceCall(context).addNewEmergencyCallBack()) + .put( + "GSM conference", + () -> + new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_GSM) + .start(5)) + .put( + "VoLTE conference", + () -> + new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_VOLTE) + .start(5)) + .build()) + .build(); + } + + private SimulatorPortalEntryGroup buildSimulatorVideoCallPortal() { + return SimulatorPortalEntryGroup.builder() + .setMethods( + ImmutableMap.builder() + .put( + "Incoming one way", + () -> + new SimulatorVideoCall(context, VideoProfile.STATE_RX_ENABLED) + .addNewIncomingCall()) + .put( + "Incoming two way", + () -> + new SimulatorVideoCall(context, VideoProfile.STATE_BIDIRECTIONAL) + .addNewIncomingCall()) + .put( + "Outgoing one way", + () -> + new SimulatorVideoCall(context, VideoProfile.STATE_TX_ENABLED) + .addNewOutgoingCall()) + .put( + "Outgoing two way", + () -> + new SimulatorVideoCall(context, VideoProfile.STATE_BIDIRECTIONAL) + .addNewOutgoingCall()) + .build()) + .build(); + } + + private SimulatorPortalEntryGroup buildSimulatorRttCallPortal() { + return SimulatorPortalEntryGroup.builder() + .setMethods( + ImmutableMap.builder() + .put("Incoming call", () -> new SimulatorRttCall(context).addNewIncomingCall(false)) + .put("Outgoing call", () -> new SimulatorRttCall(context).addNewOutgoingCall()) + .put("Emergency call", () -> new SimulatorRttCall(context).addNewEmergencyCall()) + .build()) + .build(); + } + + private SimulatorPortalEntryGroup buildSimulatorNotificationsPortal() { + return SimulatorPortalEntryGroup.builder() + .setMethods( + ImmutableMap.builder() + .put( + "Missed calls", + () -> + new SimulatorMissedCallCreator(context) + .start(SimulatorUtils.NOTIFICATION_COUNT)) + .put( + "Missed calls (few)", + () -> + new SimulatorMissedCallCreator(context) + .start(SimulatorUtils.NOTIFICATION_COUNT_FEW)) + .put( + "Voicemails", + () -> + SimulatorUtils.addVoicemailNotifications( + context, SimulatorUtils.NOTIFICATION_COUNT)) + .build()) + .build(); + } + + public ActionProvider getActionProvider() { + return new SimulatorMenu(context, simulatorMainPortal); + } +} diff --git a/java/com/android/dialer/simulator/impl/SimulatorMenu.java b/java/com/android/dialer/simulator/impl/SimulatorMenu.java new file mode 100644 index 000000000..0c8f242cd --- /dev/null +++ b/java/com/android/dialer/simulator/impl/SimulatorMenu.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2018 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.Context; +import android.support.annotation.NonNull; +import android.view.ActionProvider; +import android.view.MenuItem; +import android.view.SubMenu; +import android.view.View; +import com.android.dialer.common.Assert; +import java.util.Map.Entry; + +/** Makes option menu for simulator. */ +public final class SimulatorMenu extends ActionProvider { + + SimulatorPortalEntryGroup portal; + + Context context; + + public SimulatorMenu(@NonNull Context context, SimulatorPortalEntryGroup portal) { + super(Assert.isNotNull(context)); + this.context = context; + this.portal = portal; + } + + @Override + public View onCreateActionView() { + return null; + } + + @Override + public View onCreateActionView(MenuItem forItem) { + return null; + } + + @Override + public boolean hasSubMenu() { + return true; + } + + @Override + public void onPrepareSubMenu(SubMenu subMenu) { + super.onPrepareSubMenu(subMenu); + subMenu.clear(); + + for (Entry subPortal : portal.subPortals().entrySet()) { + subMenu + .add(subPortal.getKey()) + .setActionProvider(new SimulatorMenu(context, subPortal.getValue())); + } + for (Entry method : portal.methods().entrySet()) { + subMenu + .add(method.getKey()) + .setOnMenuItemClickListener( + (i) -> { + method.getValue().run(); + return true; + }); + } + } +} diff --git a/java/com/android/dialer/simulator/impl/SimulatorMissedCallCreator.java b/java/com/android/dialer/simulator/impl/SimulatorMissedCallCreator.java index 52d7352ac..b8556156b 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorMissedCallCreator.java +++ b/java/com/android/dialer/simulator/impl/SimulatorMissedCallCreator.java @@ -30,14 +30,14 @@ import com.android.dialer.common.concurrent.ThreadUtil; * notifications instead of writing to the call log directly. This makes the simulator behave more * like the real application. */ -public final class SimulatorMissedCallCreator implements SimulatorConnectionService.Listener { +final class SimulatorMissedCallCreator implements SimulatorConnectionService.Listener { private static final String EXTRA_CALL_COUNT = "call_count"; private static final String EXTRA_IS_MISSED_CALL_CONNECTION = "is_missed_call_connection"; private static final int DISCONNECT_DELAY_MILLIS = 1000; private final Context context; - public SimulatorMissedCallCreator(@NonNull Context context) { + SimulatorMissedCallCreator(@NonNull Context context) { this.context = Assert.isNotNull(context); } diff --git a/java/com/android/dialer/simulator/impl/SimulatorPortalEntryGroup.java b/java/com/android/dialer/simulator/impl/SimulatorPortalEntryGroup.java new file mode 100644 index 000000000..200b10fdd --- /dev/null +++ b/java/com/android/dialer/simulator/impl/SimulatorPortalEntryGroup.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 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 com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableMap; +import java.util.Collections; +import java.util.Map; + +/** Represents a portal that receives requests from either UI or IPC. */ +@AutoValue +public abstract class SimulatorPortalEntryGroup { + abstract ImmutableMap methods(); + + abstract ImmutableMap subPortals(); + + static Builder builder() { + return new AutoValue_SimulatorPortalEntryGroup.Builder() + .setMethods(Collections.emptyMap()) + .setSubPortals(Collections.emptyMap()); + } + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setMethods(Map value); + + abstract Builder setSubPortals(Map value); + + abstract SimulatorPortalEntryGroup build(); + } +} diff --git a/java/com/android/dialer/simulator/impl/SimulatorRttCall.java b/java/com/android/dialer/simulator/impl/SimulatorRttCall.java index afd897775..62e05a7a4 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorRttCall.java +++ b/java/com/android/dialer/simulator/impl/SimulatorRttCall.java @@ -28,21 +28,21 @@ import com.android.dialer.simulator.Simulator; import com.android.dialer.simulator.Simulator.Event; /** Entry point in the simulator to create voice calls. */ -public final class SimulatorRttCall +final class SimulatorRttCall implements SimulatorConnectionService.Listener, SimulatorConnection.Listener { @NonNull private final Context context; @Nullable private String connectionTag; private RttChatBot rttChatBot; - public SimulatorRttCall(@NonNull Context context) { + SimulatorRttCall(@NonNull Context context) { this.context = Assert.isNotNull(context); SimulatorConnectionService.addListener(this); SimulatorConnectionService.addListener( new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_GSM)); } - public void addNewIncomingCall(boolean isSpam) { + void addNewIncomingCall(boolean isSpam) { String callerId = isSpam ? "+1-661-778-3020" /* Blacklisted custom spam number */ @@ -52,14 +52,14 @@ public final class SimulatorRttCall context, callerId, SimulatorSimCallManager.CALL_TYPE_RTT); } - public void addNewOutgoingCall() { + void addNewOutgoingCall() { String callerId = "+55-31-2128-6800"; // Brazil office. connectionTag = SimulatorSimCallManager.addNewOutgoingCall( context, callerId, SimulatorSimCallManager.CALL_TYPE_RTT); } - public void addNewEmergencyCall() { + void addNewEmergencyCall() { String callerId = "911"; connectionTag = SimulatorSimCallManager.addNewIncomingCall( diff --git a/java/com/android/dialer/simulator/impl/SimulatorVideoCall.java b/java/com/android/dialer/simulator/impl/SimulatorVideoCall.java index c7c92e7b9..986ed99fa 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorVideoCall.java +++ b/java/com/android/dialer/simulator/impl/SimulatorVideoCall.java @@ -30,14 +30,14 @@ import com.android.dialer.common.concurrent.ThreadUtil; import com.android.dialer.simulator.Simulator.Event; /** Entry point in the simulator to create video calls. */ -public final class SimulatorVideoCall +final class SimulatorVideoCall implements SimulatorConnectionService.Listener, SimulatorConnection.Listener { @NonNull private final Context context; private final int initialVideoCapability; private final int initialVideoState; @Nullable private String connectionTag; - public SimulatorVideoCall(@NonNull Context context, int initialVideoState) { + SimulatorVideoCall(@NonNull Context context, int initialVideoState) { this.context = Assert.isNotNull(context); this.initialVideoCapability = Connection.CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL @@ -46,7 +46,7 @@ public final class SimulatorVideoCall SimulatorConnectionService.addListener(this); } - public void addNewIncomingCall() { + void addNewIncomingCall() { if (!isVideoAccountEnabled()) { showVideoAccountSettings(); return; @@ -57,7 +57,7 @@ public final class SimulatorVideoCall context, callerId, SimulatorSimCallManager.CALL_TYPE_VIDEO); } - public void addNewOutgoingCall() { + void addNewOutgoingCall() { if (!isVideoAccountEnabled()) { showVideoAccountSettings(); return; diff --git a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java index a9f332e4a..4b3033f32 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java +++ b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java @@ -36,13 +36,13 @@ import com.android.dialer.simulator.SimulatorComponent; import com.android.dialer.simulator.SimulatorEnrichedCall; /** Entry point in the simulator to create voice calls. */ -public final class SimulatorVoiceCall +final class SimulatorVoiceCall implements SimulatorConnectionService.Listener, SimulatorConnection.Listener { @NonNull private final Context context; @Nullable private String connectionTag; private final SimulatorEnrichedCall simulatorEnrichedCall; - public SimulatorVoiceCall(@NonNull Context context) { + SimulatorVoiceCall(@NonNull Context context) { this.context = Assert.isNotNull(context); simulatorEnrichedCall = SimulatorComponent.get(context).getSimulatorEnrichedCall(); SimulatorConnectionService.addListener(this); @@ -50,7 +50,7 @@ public final class SimulatorVoiceCall new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_GSM)); } - public void incomingEnrichedCall() { + void incomingEnrichedCall() { simulatorEnrichedCall .setupIncomingEnrichedCall(Simulator.ENRICHED_CALL_INCOMING_NUMBER) .addListener( @@ -67,7 +67,7 @@ public final class SimulatorVoiceCall DialerExecutorComponent.get(context).uiExecutor()); } - public void outgoingEnrichedCall() { + void outgoingEnrichedCall() { getEnrichedCallManager().registerStateChangedListener(simulatorEnrichedCall); simulatorEnrichedCall .setupOutgoingEnrichedCall(Simulator.ENRICHED_CALL_OUTGOING_NUMBER) @@ -85,14 +85,14 @@ public final class SimulatorVoiceCall DialerExecutorComponent.get(context).uiExecutor()); } - public void addNewIncomingCall() { + void addNewIncomingCall() { String callerId = "+44 (0) 20 7031 3000" /* Google London office */; connectionTag = SimulatorSimCallManager.addNewIncomingCall( context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE); } - public void addNewIncomingCall(AppCompatActivity activity) { + void addNewIncomingCall(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { Bundle extras = new Bundle(); @@ -104,14 +104,14 @@ public final class SimulatorVoiceCall .show(activity.getSupportFragmentManager(), "SimulatorDialog"); } - public void addNewOutgoingCall() { + void addNewOutgoingCall() { String callerId = "+55-31-2128-6800"; // Brazil office. connectionTag = SimulatorSimCallManager.addNewOutgoingCall( context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE); } - public void addNewOutgoingCall(AppCompatActivity activity) { + void addNewOutgoingCall(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { Bundle extras = new Bundle(); @@ -123,14 +123,14 @@ public final class SimulatorVoiceCall .show(activity.getSupportFragmentManager(), "SimulatorDialog"); } - public void addSpamIncomingCall() { + void addSpamIncomingCall() { String callerId = "+1-661-778-3020"; /* Blacklisted custom spam number */ connectionTag = SimulatorSimCallManager.addNewIncomingCall( context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE); } - public void addNewEmergencyCallBack() { + void addNewEmergencyCallBack() { String callerId = "911"; connectionTag = SimulatorSimCallManager.addNewIncomingCall( diff --git a/java/com/android/dialer/simulator/portal/SimulatorMainPortal.java b/java/com/android/dialer/simulator/portal/SimulatorMainPortal.java deleted file mode 100644 index fdec2a540..000000000 --- a/java/com/android/dialer/simulator/portal/SimulatorMainPortal.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (C) 2018 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.portal; - -import android.content.Context; -import android.support.v7.app.AppCompatActivity; -import android.telecom.VideoProfile; -import android.view.ActionProvider; -import com.android.dialer.enrichedcall.simulator.EnrichedCallSimulatorActivity; -import com.android.dialer.simulator.Simulator; -import com.android.dialer.simulator.SimulatorComponent; -import com.android.dialer.simulator.impl.SimulatorConferenceCreator; -import com.android.dialer.simulator.impl.SimulatorMissedCallCreator; -import com.android.dialer.simulator.impl.SimulatorRttCall; -import com.android.dialer.simulator.impl.SimulatorSimCallManager; -import com.android.dialer.simulator.impl.SimulatorUtils; -import com.android.dialer.simulator.impl.SimulatorVideoCall; -import com.android.dialer.simulator.impl.SimulatorVoiceCall; -import com.google.common.collect.ImmutableMap; - -/** Implements the top level simulator menu. */ -public final class SimulatorMainPortal { - - private final Context context; - private final AppCompatActivity activity; - private SimulatorPortalEntryGroup simulatorMainPortal; - - public SimulatorMainPortal(AppCompatActivity activity) { - this.activity = activity; - this.context = activity.getApplicationContext(); - buildMainPortal(); - } - - private void buildMainPortal() { - this.simulatorMainPortal = - SimulatorPortalEntryGroup.builder() - .setMethods( - ImmutableMap.builder() - .put("Populate database", () -> SimulatorUtils.populateDatabase(context)) - .put("Populate voicemail", () -> SimulatorUtils.populateVoicemail(context)) - .put( - "Fast Populate database", - () -> SimulatorUtils.fastPopulateDatabase(context)) - .put( - "Fast populate voicemail database", - () -> SimulatorUtils.populateVoicemailFast(context)) - .put("Clean database", () -> SimulatorUtils.cleanDatabase(context)) - .put("clear preferred SIM", () -> SimulatorUtils.clearPreferredSim(context)) - .put("Sync voicemail", () -> SimulatorUtils.syncVoicemail(context)) - .put("Share persistent log", () -> SimulatorUtils.sharePersistentLog(context)) - .put( - "Enriched call simulator", - () -> - context.startActivity(EnrichedCallSimulatorActivity.newIntent(context))) - .put( - "Enable simulator mode", - () -> { - SimulatorComponent.get(context).getSimulator().enableSimulatorMode(); - SimulatorSimCallManager.register(context); - }) - .put( - "Disable simulator mode", - () -> { - SimulatorComponent.get(context).getSimulator().disableSimulatorMode(); - SimulatorSimCallManager.unregister(context); - }) - .build()) - .setSubPortals( - ImmutableMap.of( - "VoiceCall", - buildSimulatorVoiceCallPortal(), - "VideoCall", - buildSimulatorVideoCallPortal(), - "RttCall", - buildSimulatorRttCallPortal(), - "Notifications", - buildSimulatorNotificationsPortal())) - .build(); - } - - public SimulatorPortalEntryGroup buildSimulatorVoiceCallPortal() { - return SimulatorPortalEntryGroup.builder() - .setMethods( - ImmutableMap.builder() - .put("Incoming call", () -> new SimulatorVoiceCall(context).addNewIncomingCall()) - .put("Outgoing call", () -> new SimulatorVoiceCall(context).addNewOutgoingCall()) - .put( - "Customized incoming call", - () -> new SimulatorVoiceCall(context).addNewIncomingCall(activity)) - .put( - "Customized outgoing call", - () -> new SimulatorVoiceCall(context).addNewOutgoingCall(activity)) - .put( - "Incoming enriched call", - () -> new SimulatorVoiceCall(context).incomingEnrichedCall()) - .put( - "Outgoing enriched call", - () -> new SimulatorVoiceCall(context).outgoingEnrichedCall()) - .put( - "Spam incoming call", - () -> new SimulatorVoiceCall(context).addSpamIncomingCall()) - .put( - "Emergency call back", - () -> new SimulatorVoiceCall(context).addNewEmergencyCallBack()) - .put( - "GSM conference", - () -> - new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_GSM) - .start(5)) - .put( - "VoLTE conference", - () -> - new SimulatorConferenceCreator(context, Simulator.CONFERENCE_TYPE_VOLTE) - .start(5)) - .build()) - .build(); - } - - private SimulatorPortalEntryGroup buildSimulatorVideoCallPortal() { - return SimulatorPortalEntryGroup.builder() - .setMethods( - ImmutableMap.builder() - .put( - "Incoming one way", - () -> - new SimulatorVideoCall(context, VideoProfile.STATE_RX_ENABLED) - .addNewIncomingCall()) - .put( - "Incoming two way", - () -> - new SimulatorVideoCall(context, VideoProfile.STATE_BIDIRECTIONAL) - .addNewIncomingCall()) - .put( - "Outgoing one way", - () -> - new SimulatorVideoCall(context, VideoProfile.STATE_TX_ENABLED) - .addNewOutgoingCall()) - .put( - "Outgoing two way", - () -> - new SimulatorVideoCall(context, VideoProfile.STATE_BIDIRECTIONAL) - .addNewOutgoingCall()) - .build()) - .build(); - } - - private SimulatorPortalEntryGroup buildSimulatorRttCallPortal() { - return SimulatorPortalEntryGroup.builder() - .setMethods( - ImmutableMap.builder() - .put("Incoming call", () -> new SimulatorRttCall(context).addNewIncomingCall(false)) - .put("Outgoing call", () -> new SimulatorRttCall(context).addNewOutgoingCall()) - .put("Emergency call", () -> new SimulatorRttCall(context).addNewEmergencyCall()) - .build()) - .build(); - } - - private SimulatorPortalEntryGroup buildSimulatorNotificationsPortal() { - return SimulatorPortalEntryGroup.builder() - .setMethods( - ImmutableMap.builder() - .put( - "Missed calls", - () -> - new SimulatorMissedCallCreator(context) - .start(SimulatorUtils.NOTIFICATION_COUNT)) - .put( - "Missed calls (few)", - () -> - new SimulatorMissedCallCreator(context) - .start(SimulatorUtils.NOTIFICATION_COUNT_FEW)) - .put( - "Voicemails", - () -> - SimulatorUtils.addVoicemailNotifications( - context, SimulatorUtils.NOTIFICATION_COUNT)) - .build()) - .build(); - } - - public ActionProvider getActionProvider() { - return new SimulatorMenu(context, simulatorMainPortal); - } -} diff --git a/java/com/android/dialer/simulator/portal/SimulatorMenu.java b/java/com/android/dialer/simulator/portal/SimulatorMenu.java deleted file mode 100644 index 01fd4aa0e..000000000 --- a/java/com/android/dialer/simulator/portal/SimulatorMenu.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2018 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.portal; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.view.ActionProvider; -import android.view.MenuItem; -import android.view.SubMenu; -import android.view.View; -import com.android.dialer.common.Assert; -import java.util.Map.Entry; - -/** Makes option menu for simulator. */ -public final class SimulatorMenu extends ActionProvider { - - SimulatorPortalEntryGroup portal; - - Context context; - - public SimulatorMenu(@NonNull Context context, SimulatorPortalEntryGroup portal) { - super(Assert.isNotNull(context)); - this.context = context; - this.portal = portal; - } - - @Override - public View onCreateActionView() { - return null; - } - - @Override - public View onCreateActionView(MenuItem forItem) { - return null; - } - - @Override - public boolean hasSubMenu() { - return true; - } - - @Override - public void onPrepareSubMenu(SubMenu subMenu) { - super.onPrepareSubMenu(subMenu); - subMenu.clear(); - - for (Entry subPortal : portal.subPortals().entrySet()) { - subMenu - .add(subPortal.getKey()) - .setActionProvider(new SimulatorMenu(context, subPortal.getValue())); - } - for (Entry method : portal.methods().entrySet()) { - subMenu - .add(method.getKey()) - .setOnMenuItemClickListener( - (i) -> { - method.getValue().run(); - return true; - }); - } - } -} diff --git a/java/com/android/dialer/simulator/portal/SimulatorPortalEntryGroup.java b/java/com/android/dialer/simulator/portal/SimulatorPortalEntryGroup.java deleted file mode 100644 index 30a248cb1..000000000 --- a/java/com/android/dialer/simulator/portal/SimulatorPortalEntryGroup.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2018 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.portal; - -import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableMap; -import java.util.Collections; -import java.util.Map; - -/** Represents a portal that receives requests from either UI or IPC. */ -@AutoValue -public abstract class SimulatorPortalEntryGroup { - abstract ImmutableMap methods(); - - abstract ImmutableMap subPortals(); - - static Builder builder() { - return new AutoValue_SimulatorPortalEntryGroup.Builder() - .setMethods(Collections.emptyMap()) - .setSubPortals(Collections.emptyMap()); - } - - @AutoValue.Builder - abstract static class Builder { - abstract Builder setMethods(Map value); - - abstract Builder setSubPortals(Map value); - - abstract SimulatorPortalEntryGroup build(); - } -} -- cgit v1.2.3