Home | History | Annotate | Download | only in simulator
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.dialer.simulator;
     18 
     19 import android.support.annotation.IntDef;
     20 import android.support.annotation.Nullable;
     21 import android.support.annotation.StringDef;
     22 import android.support.v7.app.AppCompatActivity;
     23 import android.view.ActionProvider;
     24 import java.lang.annotation.Retention;
     25 import java.lang.annotation.RetentionPolicy;
     26 import java.util.Objects;
     27 
     28 /** Used to add menu items to the Dialer menu to test the app using simulated calls and data. */
     29 public interface Simulator {
     30   boolean shouldShow();
     31 
     32   ActionProvider getActionProvider(AppCompatActivity activity);
     33 
     34   /** The type of conference to emulate. */
     35   // TODO(a bug): add VoLTE and CDMA conference call
     36   @Retention(RetentionPolicy.SOURCE)
     37   @IntDef({
     38     CONFERENCE_TYPE_GSM,
     39     CONFERENCE_TYPE_VOLTE,
     40   })
     41   @interface ConferenceType {}
     42 
     43   static final int CONFERENCE_TYPE_GSM = 1;
     44   static final int CONFERENCE_TYPE_VOLTE = 2;
     45 
     46   /** The types of connection service listener events */
     47   @Retention(RetentionPolicy.SOURCE)
     48   @IntDef({
     49     ON_NEW_OUTGOING_CONNECTION,
     50     ON_NEW_INCOMING_CONNECTION,
     51     ON_CONFERENCE,
     52   })
     53   @interface ConnectionServiceEventType {}
     54 
     55   static final int ON_NEW_OUTGOING_CONNECTION = 1;
     56   static final int ON_NEW_INCOMING_CONNECTION = 2;
     57   static final int ON_CONFERENCE = 3;
     58 
     59   static final String CALLER_ID_PRESENTATION_TYPE = "caller_id_";
     60 
     61   /** Bundle keys that are used in making fake call. */
     62   @Retention(RetentionPolicy.SOURCE)
     63   @StringDef({
     64     IS_VOLTE,
     65     PRESENTATION_CHOICE,
     66     IS_ENRICHED_CALL,
     67   })
     68   @interface BundleKey {}
     69 
     70   public final String IS_VOLTE = "ISVOLTE";
     71   public final String PRESENTATION_CHOICE = "PRESENTATIONCHOICE";
     72   public final String IS_ENRICHED_CALL = "ISENRICHEDCALL";
     73 
     74   /** Phone numbers for outgoing and incoming enriched call scenario. */
     75   public static final String ENRICHED_CALL_OUTGOING_NUMBER = "+55-31-2128-6800";
     76 
     77   public static final String ENRICHED_CALL_INCOMING_NUMBER = "+44 (0) 20 7031 3000";
     78 
     79   boolean isSimulatorMode();
     80 
     81   void enableSimulatorMode();
     82 
     83   void disableSimulatorMode();
     84 
     85   /** Information about a connection event. */
     86   public static class Event {
     87     /** The type of connection event. */
     88     @Retention(RetentionPolicy.SOURCE)
     89     @IntDef({
     90       NONE,
     91       ANSWER,
     92       REJECT,
     93       HOLD,
     94       UNHOLD,
     95       DISCONNECT,
     96       STATE_CHANGE,
     97       DTMF,
     98       SESSION_MODIFY_REQUEST,
     99       CALL_AUDIO_STATE_CHANGED,
    100       CONNECTION_ADDED,
    101       MERGE,
    102       SEPARATE,
    103       SWAP,
    104       START_RTT,
    105       STOP_RTT,
    106       HANDLE_RTT_UPGRADE_RESPONSE,
    107     })
    108     public @interface Type {}
    109 
    110     public static final int NONE = -1;
    111     public static final int ANSWER = 1;
    112     public static final int REJECT = 2;
    113     public static final int HOLD = 3;
    114     public static final int UNHOLD = 4;
    115     public static final int DISCONNECT = 5;
    116     public static final int STATE_CHANGE = 6;
    117     public static final int DTMF = 7;
    118     public static final int SESSION_MODIFY_REQUEST = 8;
    119     public static final int CALL_AUDIO_STATE_CHANGED = 9;
    120     public static final int CONNECTION_ADDED = 10;
    121     public static final int MERGE = 11;
    122     public static final int SEPARATE = 12;
    123     public static final int SWAP = 13;
    124     public static final int START_RTT = 14;
    125     public static final int STOP_RTT = 15;
    126     public static final int HANDLE_RTT_UPGRADE_RESPONSE = 16;
    127 
    128     @Type public final int type;
    129     /** Holds event specific information. For example, for DTMF this could be the keycode. */
    130     @Nullable public final String data1;
    131     /**
    132      * Holds event specific information. For example, for STATE_CHANGE this could be the new state.
    133      */
    134     @Nullable public final String data2;
    135 
    136     public Event(@Type int type) {
    137       this(type, null, null);
    138     }
    139 
    140     public Event(@Type int type, String data1, String data2) {
    141       this.type = type;
    142       this.data1 = data1;
    143       this.data2 = data2;
    144     }
    145 
    146     @Override
    147     public boolean equals(Object other) {
    148       if (this == other) {
    149         return true;
    150       }
    151       if (!(other instanceof Event)) {
    152         return false;
    153       }
    154       Event event = (Event) other;
    155       return type == event.type
    156           && Objects.equals(data1, event.data1)
    157           && Objects.equals(data2, event.data2);
    158     }
    159 
    160     @Override
    161     public int hashCode() {
    162       return Objects.hash(Integer.valueOf(type), data1, data2);
    163     }
    164   }
    165 }
    166