1 /* 2 * Copyright (C) 2023 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.google.android.mobly.snippet.bundled; 18 19 import android.platform.helpers.HelperAccessor; 20 import android.platform.helpers.IAutoDialHelper; 21 import android.platform.helpers.IAutoVehicleHardKeysHelper; 22 23 import com.google.android.mobly.snippet.Snippet; 24 import com.google.android.mobly.snippet.rpc.Rpc; 25 26 import java.util.List; 27 28 /** Snippet class for exposing Phone/Dial App APIs. */ 29 public class DialerSnippet implements Snippet { 30 private final HelperAccessor<IAutoDialHelper> mDialerHelper; 31 private final HelperAccessor<IAutoVehicleHardKeysHelper> mHardKeysHelper; 32 DialerSnippet()33 public DialerSnippet() { 34 mDialerHelper = new HelperAccessor<>(IAutoDialHelper.class); 35 mHardKeysHelper = new HelperAccessor<>(IAutoVehicleHardKeysHelper.class); 36 } 37 38 @Rpc(description = "Open Phone Application.") openPhoneApp()39 public void openPhoneApp() { 40 mDialerHelper.get().open(); 41 } 42 43 @Rpc(description = "Open Dial Pad and dial in a number using keypad.") dialANumber(String phoneNumber)44 public void dialANumber(String phoneNumber) { 45 mDialerHelper.get().dialANumber(phoneNumber); 46 } 47 48 @Rpc(description = "Make a call.") makeCall()49 public void makeCall() { 50 mDialerHelper.get().makeCall(); 51 } 52 53 @Rpc(description = "End the call.") endCall()54 public void endCall() { 55 mDialerHelper.get().endCall(); 56 } 57 58 @Rpc(description = "Press the hardkey for ending the call.") endCallWithHardkey()59 public void endCallWithHardkey() { 60 mHardKeysHelper.get().pressEndCallKey(); 61 } 62 63 @Rpc(description = "Open Call History.") openCallHistory()64 public void openCallHistory() { 65 mDialerHelper.get().openCallHistory(); 66 } 67 68 @Rpc(description = "Call Contact From Contact List.") callContact(String contactName)69 public void callContact(String contactName) { 70 mDialerHelper.get().callContact(contactName); 71 } 72 73 @Rpc(description = "Delete the dialed number on Dial Pad.") deleteDialedNumber()74 public void deleteDialedNumber() { 75 mDialerHelper.get().deleteDialedNumber(); 76 } 77 78 @Rpc(description = "Get the dialed number when the call is in progress.") getDialedNumber()79 public String getDialedNumber() { 80 return mDialerHelper.get().getDialedNumber(); 81 } 82 83 @Rpc(description = "Get the entered on dial pad.") getDialInNumber()84 public String getDialInNumber() { 85 return mDialerHelper.get().getDialInNumber(); 86 } 87 88 @Rpc(description = "Get the home address from an open contacts page.") getHomeAddress()89 public String getHomeAddress() { 90 return mDialerHelper.get().getHomeAddress(); 91 } 92 93 @Rpc(description = "Get the contact name for dialed number when the call is in progress.") getDialedContactName()94 public String getDialedContactName() { 95 return mDialerHelper.get().getDialedContactName(); 96 } 97 98 @Rpc(description = "Get the recent entry from Call History.") getRecentCallHistory()99 public String getRecentCallHistory() { 100 return mDialerHelper.get().getRecentCallHistory(); 101 } 102 103 @Rpc( 104 description = 105 "Call contact from list open in foreground e.g. Favorites, Recents, Contacts.") dialFromList(String contact)106 public void dialFromList(String contact) { 107 mDialerHelper.get().dialFromList(contact); 108 } 109 110 @Rpc(description = "Dial a number in call dial pad when call is in progress.") inCallDialPad(String phoneNumber)111 public void inCallDialPad(String phoneNumber) { 112 mDialerHelper.get().inCallDialPad(phoneNumber); 113 } 114 115 @Rpc(description = "Mute Call.") muteCall()116 public void muteCall() { 117 mDialerHelper.get().muteCall(); 118 } 119 120 @Rpc(description = "Unmute Call.") unmuteCall()121 public void unmuteCall() { 122 mDialerHelper.get().unmuteCall(); 123 } 124 125 @Rpc(description = "Ongoing Call on homescreen.") isOngoingCallDisplayedOnHome()126 public boolean isOngoingCallDisplayedOnHome() { 127 return mDialerHelper.get().isOngoingCallDisplayedOnHome(); 128 } 129 130 @Rpc(description = "Open Phone from Home Screen card.") openPhoneAppFromHome()131 public void openPhoneAppFromHome() { 132 mDialerHelper.get().openPhoneAppFromHome(); 133 } 134 135 @Rpc(description = "Change audio source to Phone when the call is in progress.") changeAudioSourceToPhone()136 public void changeAudioSourceToPhone() { 137 mDialerHelper.get().changeAudioSource(IAutoDialHelper.AudioSource.PHONE); 138 } 139 140 @Rpc(description = "Change audio source to Car Speakers when the call is in progress.") changeAudioSourceToCarSpeakers()141 public void changeAudioSourceToCarSpeakers() { 142 mDialerHelper.get().changeAudioSource(IAutoDialHelper.AudioSource.CAR_SPEAKERS); 143 } 144 145 @Rpc(description = "Call Most Recent History.") callMostRecentHistory()146 public void callMostRecentHistory() { 147 mDialerHelper.get().callMostRecentHistory(); 148 } 149 150 @Rpc(description = "Get contact name while the call is in progress.") getContactName()151 public String getContactName() { 152 return mDialerHelper.get().getContactName(); 153 } 154 155 @Rpc(description = "Get contact type (Work, Mobile, Home) while the call is in progress.") getContactType()156 public String getContactType() { 157 return mDialerHelper.get().getContactType(); 158 } 159 160 @Rpc(description = "Search contact by name.") searchContactsByName(String contact)161 public void searchContactsByName(String contact) { 162 mDialerHelper.get().searchContactsByName(contact); 163 } 164 165 @Rpc(description = "Search contact by number.") searchContactsByNumber(String number)166 public void searchContactsByNumber(String number) { 167 mDialerHelper.get().searchContactsByNumber(number); 168 } 169 170 @Rpc(description = "Get first search result.") getFirstSearchResult()171 public String getFirstSearchResult() { 172 return mDialerHelper.get().getFirstSearchResult(); 173 } 174 175 @Rpc(description = "Sort contact list by First Name.") sortContactListByFirstName()176 public void sortContactListByFirstName() { 177 mDialerHelper.get().sortContactListBy(IAutoDialHelper.OrderType.FIRST_NAME); 178 } 179 180 @Rpc(description = "Sort contact list by Last Name.") sortContactListByLastName()181 public void sortContactListByLastName() { 182 mDialerHelper.get().sortContactListBy(IAutoDialHelper.OrderType.LAST_NAME); 183 } 184 185 @Rpc(description = "Get first contact from contacts list.") getFirstContactFromContactList()186 public String getFirstContactFromContactList() { 187 return mDialerHelper.get().getFirstContactFromContactList(); 188 } 189 190 @Rpc(description = "Check if given contact is in Favorites.") isContactInFavorites(String contact)191 public boolean isContactInFavorites(String contact) { 192 return mDialerHelper.get().isContactInFavorites(contact); 193 } 194 195 @Rpc(description = "Bluetooth HFP Error") isBluetoothHfpErrorDisplayed()196 public boolean isBluetoothHfpErrorDisplayed() { 197 return mDialerHelper.get().isBluetoothHfpErrorDisplayed(); 198 } 199 200 @Rpc(description = "Open details page for given contact.") openDetailsPage(String contact)201 public void openDetailsPage(String contact) { 202 mDialerHelper.get().openDetailsPage(contact); 203 } 204 205 @Rpc(description = "Open details page for the first contact.") openFirstContactDetails()206 public void openFirstContactDetails() { 207 mDialerHelper.get().openFirstContactDetails(); 208 } 209 210 @Rpc(description = "Open Contacts List.") openContacts()211 public void openContacts() { 212 mDialerHelper.get().openContacts(); 213 } 214 215 @Rpc(description = "Press 'Device' on a prompt, if present.") pressDevice()216 public void pressDevice() { 217 mDialerHelper.get().pressDeviceOnPrompt(); 218 } 219 220 @Rpc(description = "Get list of visible contacts") getListOfAllContacts()221 public List<String> getListOfAllContacts() { 222 return mDialerHelper.get().getListOfAllVisibleContacts(); 223 } 224 225 @Rpc(description = "Add Favorites from favorites tab") addFavoritesFromFavoritesTab(String contact)226 public void addFavoritesFromFavoritesTab(String contact) { 227 mDialerHelper.get().addFavoritesFromFavoritesTab(contact); 228 } 229 230 @Rpc(description = "Open Phone Button in Bluetooth Palette") clickPhoneButton()231 public void clickPhoneButton() { 232 mDialerHelper.get().clickPhoneButton(); 233 } 234 235 @Rpc(description = "is Recents displayed in Dialer page ") verifyDialerRecentsTab()236 public boolean verifyDialerRecentsTab() { 237 return mDialerHelper.get().verifyDialerRecentsTab(); 238 } 239 240 @Rpc(description = "is Contacts displayed in Dialer page ") verifyDialerContactsTab()241 public boolean verifyDialerContactsTab() { 242 return mDialerHelper.get().verifyDialerContactsTab(); 243 } 244 245 @Rpc(description = "is Favorites displayed in Dialer page ") verifyDialerFavoritesTab()246 public boolean verifyDialerFavoritesTab() { 247 return mDialerHelper.get().verifyDialerFavoritesTab(); 248 } 249 250 @Rpc(description = "is Dialpad displayed in Dialer page ") verifyDialerDialpadTab()251 public boolean verifyDialerDialpadTab() { 252 return mDialerHelper.get().verifyDialerDialpadTab(); 253 } 254 255 @Override shutdown()256 public void shutdown() {} 257 } 258