Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 336cc00d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Add Simulator service."

parents d202effe 4bf1692c
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -71,8 +71,11 @@ LOCAL_FULL_LIBS_MANIFEST_FILES := \

LOCAL_SRC_FILES := $(call all-java-files-under, $(BASE_DIR))
LOCAL_SRC_FILES += $(call all-proto-files-under, $(BASE_DIR))
LOCAL_SRC_FILES += $(call all-Iaidl-files-under, $(BASE_DIR))
LOCAL_SRC_FILES := $(filter-out $(EXCLUDE_FILES),$(LOCAL_SRC_FILES))

LOCAL_AIDL_INCLUDES := $(call all-Iaidl-files-under, $(BASE_DIR))

LOCAL_PROTOC_FLAGS := --proto_path=$(LOCAL_PATH)

LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(RES_DIRS))
+15 −0
Original line number Diff line number Diff line
<?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">

+69 −9
Original line number Diff line number Diff line
@@ -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()
@@ -91,12 +139,26 @@ public final class SimulatorMainPortal {
            ImmutableMap.<String, Runnable>builder()
                .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);
  }
}
+18 −2
Original line number Diff line number Diff line
@@ -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();
+29 −0
Original line number Diff line number Diff line
<?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.service">

  <application>

    <service
        android:name=".SimulatorService"
        android:exported="true">
    </service>

  </application>

</manifest>
 No newline at end of file
Loading