diff options
author | weijiaxu <weijiaxu@google.com> | 2018-06-22 12:52:21 -0700 |
---|---|---|
committer | Weijia Xu <weijiaxu@google.com> | 2018-06-25 11:58:15 -0700 |
commit | 4bf1692c60c7653598a3ad1d898dc2e139974617 (patch) | |
tree | 7c7a9abd8c2dcad5155ead7228442c0bdf88cca1 /java/com/android/dialer/simulator/impl | |
parent | d202effe09466dc4cf9e646d5f8c8338ab39fa72 (diff) |
Add Simulator service.
Add Simulator service so that trusted clients can access to dialer simulator apis.
Bug: 79488174
Test: included tests.
PiperOrigin-RevId: 201727670
Change-Id: Ic4ebb256d178e03f1de98a4e40a2b02efd3a9620
Diffstat (limited to 'java/com/android/dialer/simulator/impl')
3 files changed, 102 insertions, 11 deletions
diff --git a/java/com/android/dialer/simulator/impl/AndroidManifest.xml b/java/com/android/dialer/simulator/impl/AndroidManifest.xml index a30504d3f..718d50e1d 100644 --- a/java/com/android/dialer/simulator/impl/AndroidManifest.xml +++ b/java/com/android/dialer/simulator/impl/AndroidManifest.xml @@ -1,4 +1,19 @@ <?xml version="1.0" encoding="utf-8"?> +<!-- + ~ 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 + --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.dialer.simulator.impl"> diff --git a/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java b/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java index 273826f70..261275756 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java +++ b/java/com/android/dialer/simulator/impl/SimulatorMainPortal.java @@ -18,19 +18,25 @@ package com.android.dialer.simulator.impl; import android.content.Context; import android.support.v7.app.AppCompatActivity; +import android.telecom.TelecomManager; import android.telecom.VideoProfile; import android.view.ActionProvider; +import com.android.dialer.common.concurrent.DialerExecutorComponent; 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; +import com.google.common.util.concurrent.ListenableFuture; /** Implements the top level simulator menu. */ -public final class SimulatorMainPortal { +public class SimulatorMainPortal { private final Context context; private final AppCompatActivity activity; - private SimulatorPortalEntryGroup simulatorMainPortal; + private SimulatorPortalEntryGroup simulatorPortalEntryGroup; + private String callerId = ""; + private int presentation = TelecomManager.PRESENTATION_ALLOWED; + private int missedCallNum = 1; public SimulatorMainPortal(AppCompatActivity activity) { this.activity = activity; @@ -38,8 +44,50 @@ public final class SimulatorMainPortal { buildMainPortal(); } + public SimulatorMainPortal(Context context) { + this.activity = null; + this.context = context; + buildMainPortal(); + } + + public void setCallerId(String callerId) { + this.callerId = callerId; + } + + public void setPresentation(int presentation) { + this.presentation = presentation; + } + + public void setMissedCallNum(int missedCallNum) { + this.missedCallNum = missedCallNum; + } + + /** + * Executes commands sent to this portal. + * + * @param commands a string array that stores commands that trigger runnable methods stored in the + * portal. For example: ["VoiceCall", "Incoming Call"] triggers "() -> new + * SimulatorVoiceCall(context).addNewIncomingCall()" runnable method. + */ + public void execute(String[] commands) { + @SuppressWarnings("unused") + ListenableFuture<?> executeCommand = + DialerExecutorComponent.get(context) + .backgroundExecutor() + .submit(() -> execute(simulatorPortalEntryGroup, commands, 0)); + } + + private void execute( + SimulatorPortalEntryGroup simulatorPortalEntryGroup, String[] commands, int index) { + if (simulatorPortalEntryGroup.methods().containsKey(commands[index])) { + simulatorPortalEntryGroup.methods().get(commands[index]).run(); + } else if (simulatorPortalEntryGroup.subPortals().containsKey(commands[index])) { + execute(simulatorPortalEntryGroup.subPortals().get(commands[index]), commands, index + 1); + } + } + private void buildMainPortal() { - this.simulatorMainPortal = + simulatorPortalEntryGroup = SimulatorPortalEntryGroup.builder() .setMethods( ImmutableMap.<String, Runnable>builder() @@ -92,11 +140,25 @@ public final class SimulatorMainPortal { .put("Incoming call", () -> new SimulatorVoiceCall(context).addNewIncomingCall()) .put("Outgoing call", () -> new SimulatorVoiceCall(context).addNewOutgoingCall()) .put( + "Customized incoming call (Dialog)", + () -> + new SimulatorVoiceCall(context) + .addCustomizedIncomingCallWithDialog(activity)) + .put( + "Customized outgoing call (Dialog)", + () -> + new SimulatorVoiceCall(context) + .addCustomizedOutgoingCallWithDialog(activity)) + .put( "Customized incoming call", - () -> new SimulatorVoiceCall(context).addNewIncomingCall(activity)) + () -> + new SimulatorVoiceCall(context) + .addCustomizedIncomingCall(this.callerId, this.presentation)) .put( "Customized outgoing call", - () -> new SimulatorVoiceCall(context).addNewOutgoingCall(activity)) + () -> + new SimulatorVoiceCall(context) + .addCustomizedOutgoingCall(this.callerId, this.presentation)) .put( "Incoming enriched call", () -> new SimulatorVoiceCall(context).incomingEnrichedCall()) @@ -173,9 +235,7 @@ public final class SimulatorMainPortal { .start(SimulatorUtils.NOTIFICATION_COUNT)) .put( "Missed calls (few)", - () -> - new SimulatorMissedCallCreator(context) - .start(SimulatorUtils.NOTIFICATION_COUNT_FEW)) + () -> new SimulatorMissedCallCreator(context).start(missedCallNum)) .put( "Voicemails", () -> @@ -186,6 +246,6 @@ public final class SimulatorMainPortal { } public ActionProvider getActionProvider() { - return new SimulatorMenu(context, simulatorMainPortal); + return new SimulatorMenu(context, simulatorPortalEntryGroup); } } diff --git a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java index 4b3033f32..9e38470ac 100644 --- a/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java +++ b/java/com/android/dialer/simulator/impl/SimulatorVoiceCall.java @@ -92,7 +92,15 @@ final class SimulatorVoiceCall context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE); } - void addNewIncomingCall(AppCompatActivity activity) { + void addCustomizedIncomingCall(String callerId, int callerIdPresentation) { + Bundle extras = new Bundle(); + extras.putInt(Simulator.PRESENTATION_CHOICE, callerIdPresentation); + connectionTag = + SimulatorSimCallManager.addNewIncomingCall( + context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE, extras); + } + + void addCustomizedIncomingCallWithDialog(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { Bundle extras = new Bundle(); @@ -111,7 +119,15 @@ final class SimulatorVoiceCall context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE); } - void addNewOutgoingCall(AppCompatActivity activity) { + void addCustomizedOutgoingCall(String callerId, int callerIdPresentation) { + Bundle extras = new Bundle(); + extras.putInt(Simulator.PRESENTATION_CHOICE, callerIdPresentation); + connectionTag = + SimulatorSimCallManager.addNewIncomingCall( + context, callerId, SimulatorSimCallManager.CALL_TYPE_VOICE, extras); + } + + void addCustomizedOutgoingCallWithDialog(AppCompatActivity activity) { SimulatorDialogFragment.newInstance( (callerId, callerIdPresentation) -> { Bundle extras = new Bundle(); |