• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.incallui.incall.impl;
18 
19 import android.support.v4.util.ArrayMap;
20 import android.telephony.TelephonyManager;
21 import com.android.incallui.incall.impl.MappedButtonConfig.MappingInfo;
22 import com.android.incallui.incall.protocol.InCallButtonIds;
23 import java.util.Map;
24 
25 /**
26  * Creates {@link ButtonChooser} objects, based on the current network and phone type.
27  */
28 class ButtonChooserFactory {
29 
30   /**
31    * Creates the appropriate {@link ButtonChooser} based on the given information.
32    *
33    * @param voiceNetworkType the result of a call to {@link TelephonyManager#getVoiceNetworkType()}.
34    * @param isWiFi {@code true} if the call is made over WiFi, {@code false} otherwise.
35    * @param phoneType the result of a call to {@link TelephonyManager#getPhoneType()}.
36    * @return the ButtonChooser.
37    */
newButtonChooser( int voiceNetworkType, boolean isWiFi, int phoneType)38   public static ButtonChooser newButtonChooser(
39       int voiceNetworkType, boolean isWiFi, int phoneType) {
40     if (voiceNetworkType == TelephonyManager.NETWORK_TYPE_LTE || isWiFi) {
41       return newImsAndWiFiButtonChooser();
42     }
43 
44     if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
45       return newCdmaButtonChooser();
46     }
47 
48     if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
49       return newGsmButtonChooser();
50     }
51 
52     return newImsAndWiFiButtonChooser();
53   }
54 
newImsAndWiFiButtonChooser()55   private static ButtonChooser newImsAndWiFiButtonChooser() {
56     Map<Integer, MappingInfo> mapping = createCommonMapping();
57     mapping.put(
58         InCallButtonIds.BUTTON_MANAGE_VOICE_CONFERENCE,
59         MappingInfo.builder(4).setSlotOrder(0).build());
60     mapping.put(
61         InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, MappingInfo.builder(4).setSlotOrder(10).build());
62     mapping.put(
63         InCallButtonIds.BUTTON_SWITCH_TO_SECONDARY, MappingInfo.builder(5).setSlotOrder(0).build());
64     mapping.put(InCallButtonIds.BUTTON_HOLD, MappingInfo.builder(5).setSlotOrder(10).build());
65 
66     return new ButtonChooser(new MappedButtonConfig(mapping));
67   }
68 
newCdmaButtonChooser()69   private static ButtonChooser newCdmaButtonChooser() {
70     Map<Integer, MappingInfo> mapping = createCommonMapping();
71     mapping.put(
72         InCallButtonIds.BUTTON_MANAGE_VOICE_CONFERENCE,
73         MappingInfo.builder(4).setSlotOrder(0).build());
74     mapping.put(
75         InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, MappingInfo.builder(4).setSlotOrder(10).build());
76     mapping.put(InCallButtonIds.BUTTON_SWAP, MappingInfo.builder(5).setSlotOrder(0).build());
77 
78     return new ButtonChooser(new MappedButtonConfig(mapping));
79   }
80 
newGsmButtonChooser()81   private static ButtonChooser newGsmButtonChooser() {
82     Map<Integer, MappingInfo> mapping = createCommonMapping();
83     mapping.put(
84         InCallButtonIds.BUTTON_SWITCH_TO_SECONDARY, MappingInfo.builder(4).setSlotOrder(0).build());
85     mapping.put(
86         InCallButtonIds.BUTTON_MANAGE_VOICE_CONFERENCE,
87         MappingInfo.builder(4).setSlotOrder(5).build());
88     mapping.put(
89         InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, MappingInfo.builder(4).setSlotOrder(10).build());
90     mapping.put(InCallButtonIds.BUTTON_HOLD, MappingInfo.builder(5).setSlotOrder(0).build());
91 
92     return new ButtonChooser(new MappedButtonConfig(mapping));
93   }
94 
createCommonMapping()95   private static Map<Integer, MappingInfo> createCommonMapping() {
96     Map<Integer, MappingInfo> mapping = new ArrayMap<>();
97     mapping.put(InCallButtonIds.BUTTON_MUTE, MappingInfo.builder(0).build());
98     mapping.put(InCallButtonIds.BUTTON_DIALPAD, MappingInfo.builder(1).build());
99     mapping.put(InCallButtonIds.BUTTON_AUDIO, MappingInfo.builder(2).build());
100     mapping.put(InCallButtonIds.BUTTON_MERGE, MappingInfo.builder(3).setSlotOrder(0).build());
101     mapping.put(InCallButtonIds.BUTTON_ADD_CALL, MappingInfo.builder(3).build());
102     return mapping;
103   }
104 }
105