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 // For multi-sim devices, the first sim's phoneType is used so hold button might be not 78 // available for CDMA + GSM devices calling with GSM sim. Adding hold button as low priority 79 // here to let telecom control whether it should be shown. 80 mapping.put(InCallButtonIds.BUTTON_HOLD, MappingInfo.builder(5).setSlotOrder(5).build()); 81 mapping.put( 82 InCallButtonIds.BUTTON_SWITCH_TO_SECONDARY, 83 MappingInfo.builder(5) 84 .setSlotOrder(Integer.MAX_VALUE) 85 .setMutuallyExclusiveButton(InCallButtonIds.BUTTON_SWAP) 86 .build()); 87 88 return new ButtonChooser(new MappedButtonConfig(mapping)); 89 } 90 newGsmButtonChooser()91 private static ButtonChooser newGsmButtonChooser() { 92 Map<Integer, MappingInfo> mapping = createCommonMapping(); 93 mapping.put( 94 InCallButtonIds.BUTTON_SWITCH_TO_SECONDARY, MappingInfo.builder(4).setSlotOrder(0).build()); 95 mapping.put( 96 InCallButtonIds.BUTTON_UPGRADE_TO_VIDEO, MappingInfo.builder(4).setSlotOrder(10).build()); 97 98 /* 99 * Unlike the other configurations, MANAGE_VOICE_CONFERENCE shares a spot with HOLD for GSM. 100 * On GSM, pressing hold while there's a background call just swaps to the background call. It 101 * doesn't make sense to show both SWITCH_TO_SECONDARY and HOLD when they do the same thing, so 102 * we show MANAGE_VOICE_CONFERENCE instead. Previously MANAGE_VOICE_CONFERENCE would not show. 103 */ 104 mapping.put( 105 InCallButtonIds.BUTTON_MANAGE_VOICE_CONFERENCE, 106 MappingInfo.builder(5).setSlotOrder(0).build()); 107 mapping.put(InCallButtonIds.BUTTON_HOLD, MappingInfo.builder(5).setSlotOrder(5).build()); 108 109 return new ButtonChooser(new MappedButtonConfig(mapping)); 110 } 111 createCommonMapping()112 private static Map<Integer, MappingInfo> createCommonMapping() { 113 Map<Integer, MappingInfo> mapping = new ArrayMap<>(); 114 mapping.put(InCallButtonIds.BUTTON_MUTE, MappingInfo.builder(0).build()); 115 mapping.put(InCallButtonIds.BUTTON_DIALPAD, MappingInfo.builder(1).build()); 116 mapping.put(InCallButtonIds.BUTTON_AUDIO, MappingInfo.builder(2).build()); 117 mapping.put(InCallButtonIds.BUTTON_MERGE, MappingInfo.builder(3).setSlotOrder(0).build()); 118 mapping.put(InCallButtonIds.BUTTON_ADD_CALL, MappingInfo.builder(3).build()); 119 mapping.put(InCallButtonIds.BUTTON_SWAP_SIM, MappingInfo.builder(4).build()); 120 return mapping; 121 } 122 } 123