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 /** Opens the dial pad from the dialer main screen. */ 44 @Rpc(description = "Open Dial Pad.") openDialPad()45 public void openDialPad() { 46 mDialerHelper.get().openDialPad(); 47 } 48 49 @Rpc(description = "Open Dial Pad and dial in a number using keypad.") dialANumber(String phoneNumber)50 public void dialANumber(String phoneNumber) { 51 mDialerHelper.get().dialANumber(phoneNumber); 52 } 53 54 @Rpc(description = "Make a call.") makeCall()55 public void makeCall() { 56 mDialerHelper.get().makeCall(); 57 } 58 59 @Rpc(description = "End the call.") endCall()60 public void endCall() { 61 mDialerHelper.get().endCall(); 62 } 63 64 @Rpc(description = "Press the hardkey for ending the call.") endCallWithHardkey()65 public void endCallWithHardkey() { 66 mHardKeysHelper.get().pressEndCallKey(); 67 } 68 69 @Rpc(description = "Open Call History.") openCallHistory()70 public void openCallHistory() { 71 mDialerHelper.get().openCallHistory(); 72 } 73 74 /** Open Dialer settings from the Dialer app */ 75 @Rpc(description = "Open Dialer Settings from the Dialer app.") openDialerSettings()76 public void openDialerSettings() { 77 mDialerHelper.get().openDialerSettings(); 78 } 79 80 @Rpc(description = "Call Contact From Contact List.") callContact(String contactName)81 public void callContact(String contactName) { 82 mDialerHelper.get().callContact(contactName); 83 } 84 85 @Rpc(description = "Return whether the \"Connected Phone\" field holds the given name.") getConnectedPhoneName()86 public String getConnectedPhoneName() { 87 return mDialerHelper.get().getConnectedPhoneName(); 88 } 89 90 @Rpc(description = "Delete the dialed number on Dial Pad.") deleteDialedNumber()91 public void deleteDialedNumber() { 92 mDialerHelper.get().deleteDialedNumber(); 93 } 94 95 @Rpc(description = "Get the dialed number while the call is in progress.") getDialingNumber()96 public String getDialingNumber() { 97 return mDialerHelper.get().getDialingNumber(); 98 } 99 100 @Rpc(description = "Get the phone number while the call is in progress.") getUserProfilePhoneNumber()101 public String getUserProfilePhoneNumber() { 102 return mDialerHelper.get().getUserProfilePhoneNumber(); 103 } 104 105 @Rpc(description = "Get the entered on dial pad.") getNumberInDialPad()106 public String getNumberInDialPad() { 107 return mDialerHelper.get().getNumberInDialPad(); 108 } 109 110 @Rpc(description = "Get the home address from an open contacts page.") getHomeAddress()111 public String getHomeAddress() { 112 return mDialerHelper.get().getHomeAddress(); 113 } 114 115 @Rpc(description = "Get the contact name for dialed number when the call is in progress.") getDialedContactName()116 public String getDialedContactName() { 117 return mDialerHelper.get().getDialedContactName(); 118 } 119 120 @Rpc(description = "Get the recent entry from Call History.") getRecentCallHistory()121 public String getRecentCallHistory() { 122 return mDialerHelper.get().getRecentCallHistory(); 123 } 124 125 /** RPC to get the number of call history entries */ 126 @Rpc(description = "Get the number of entries in the display call history.") getNumCallHistoryEntries()127 public int getNumCallHistoryEntries() { 128 return mDialerHelper.get().getNumberOfCallHistoryEntries(); 129 } 130 131 @Rpc( 132 description = 133 "Call contact from list open in foreground e.g. Favorites, Recents, Contacts.") dialFromList(String contact)134 public void dialFromList(String contact) { 135 mDialerHelper.get().dialFromList(contact); 136 } 137 138 @Rpc(description = "Returns whether a call is currently ongoing and in full-screen mode.") isOngoingCallInFullScreen()139 public boolean isOngoingCallInFullScreen() { 140 return mDialerHelper.get().isOngoingCallInFullScreen(); 141 } 142 143 @Rpc(description = "Return whether the Active Call toggle is chechked") isActiveCallEnabled()144 public boolean isActiveCallEnabled() { 145 return mDialerHelper.get().isActiveCallEnabled(); 146 } 147 148 @Rpc(description = "Dial a number in call dial pad when call is in progress.") inCallDialPad(String phoneNumber)149 public void inCallDialPad(String phoneNumber) { 150 mDialerHelper.get().inCallDialPad(phoneNumber); 151 } 152 153 @Rpc(description = "Mute Call.") muteCall()154 public void muteCall() { 155 mDialerHelper.get().muteCall(); 156 } 157 158 @Rpc(description = "Unmute Call.") unmuteCall()159 public void unmuteCall() { 160 mDialerHelper.get().unmuteCall(); 161 } 162 163 @Rpc(description = "Ongoing Call on homescreen.") isOngoingCallDisplayedOnHome()164 public boolean isOngoingCallDisplayedOnHome() { 165 return mDialerHelper.get().isOngoingCallDisplayedOnHome(); 166 } 167 168 @Rpc(description = "Open Phone from Home Screen card.") openPhoneAppFromHome()169 public void openPhoneAppFromHome() { 170 mDialerHelper.get().openPhoneAppFromHome(); 171 } 172 173 @Rpc(description = "Change audio source to Phone when the call is in progress.") changeAudioSourceToPhone()174 public void changeAudioSourceToPhone() { 175 mDialerHelper.get().changeAudioSource(IAutoDialHelper.AudioSource.PHONE); 176 } 177 178 @Rpc(description = "Change audio source to Car Speakers when the call is in progress.") changeAudioSourceToCarSpeakers()179 public void changeAudioSourceToCarSpeakers() { 180 mDialerHelper.get().changeAudioSource(IAutoDialHelper.AudioSource.CAR_SPEAKERS); 181 } 182 183 @Rpc(description = "Call Most Recent History.") callMostRecentHistory()184 public void callMostRecentHistory() { 185 mDialerHelper.get().callMostRecentHistory(); 186 } 187 188 @Rpc(description = "Get contact name while the call is in progress.") getContactName()189 public String getContactName() { 190 return mDialerHelper.get().getContactName(); 191 } 192 193 @Rpc(description = "Get contact type (Work, Mobile, Home) while the call is in progress.") getContactType()194 public String getContactType() { 195 return mDialerHelper.get().getContactType(); 196 } 197 198 @Rpc(description = "Search contact by name.") searchContactsByName(String contact)199 public void searchContactsByName(String contact) { 200 mDialerHelper.get().searchContactsByName(contact); 201 } 202 203 @Rpc(description = "Search contact by number.") searchContactsByNumber(String number)204 public void searchContactsByNumber(String number) { 205 mDialerHelper.get().searchContactsByNumber(number); 206 } 207 208 @Rpc(description = "Get first contact search result.") getFirstSearchResult()209 public String getFirstSearchResult() { 210 return mDialerHelper.get().getFirstSearchResult(); 211 } 212 213 @Rpc(description = "Sort contact list by First Name.") sortContactListByFirstName()214 public void sortContactListByFirstName() { 215 mDialerHelper.get().sortContactListBy(IAutoDialHelper.OrderType.FIRST_NAME); 216 } 217 218 @Rpc(description = "Sort contact list by Last Name.") sortContactListByLastName()219 public void sortContactListByLastName() { 220 mDialerHelper.get().sortContactListBy(IAutoDialHelper.OrderType.LAST_NAME); 221 } 222 223 @Rpc(description = "Get first contact from contacts list.") getFirstContactFromContactList()224 public String getFirstContactFromContactList() { 225 return mDialerHelper.get().getFirstContactFromContactList(); 226 } 227 228 @Rpc(description = "Check if given contact is in Favorites.") isContactInFavorites(String contact)229 public boolean isContactInFavorites(String contact) { 230 return mDialerHelper.get().isContactInFavorites(contact); 231 } 232 233 @Rpc(description = "Bluetooth HFP Error") isBluetoothHfpErrorDisplayed()234 public boolean isBluetoothHfpErrorDisplayed() { 235 return mDialerHelper.get().isBluetoothHfpErrorDisplayed(); 236 } 237 238 @Rpc(description = "Open details page for given contact.") openDetailsPage(String contact)239 public void openDetailsPage(String contact) { 240 mDialerHelper.get().openDetailsPage(contact); 241 } 242 243 @Rpc(description = "Open details page for the first contact.") openFirstContactDetails()244 public void openFirstContactDetails() { 245 mDialerHelper.get().openFirstContactDetails(); 246 } 247 248 @Rpc(description = "Open Contacts List.") openContacts()249 public void openContacts() { 250 mDialerHelper.get().openContacts(); 251 } 252 253 /** Press 'Device' prompt which comes up when trying to transfer files to a device. */ 254 @Rpc(description = "Press 'Device' on a prompt, if present.") pressDevice()255 public void pressDevice() { 256 mDialerHelper.get().pressDeviceOnPrompt(); 257 } 258 259 /** Press Active Call toggle */ 260 @Rpc(description = "Press Active Call toggle") pressActiveCallToggle()261 public void pressActiveCallToggle() { 262 mDialerHelper.get().pressActiveCallToggle(); 263 } 264 265 /** Press Active Call toggle */ 266 @Rpc(description = "Press the dialer button on the phone card on the home screen.") pressDialerButtonOnPhoneCard()267 public void pressDialerButtonOnPhoneCard() { 268 mDialerHelper.get().pressDialerButtonOnPhoneCard(); 269 } 270 271 /** Rpc to press the Mobile call action button on a contact page */ 272 @Rpc(description = "Press the Mobile call button on a contact page") pressMobileCallOnContact()273 public void pressMobileCallOnContact() { 274 mDialerHelper.get().pressMobileCallOnContact(); 275 } 276 277 /** Rpc to press a search result with a given name */ 278 @Rpc(description = "Press search result with a given name") pressContactResult(String expectedName)279 public void pressContactResult(String expectedName) { 280 mDialerHelper.get().pressContactResult(expectedName); 281 } 282 283 @Rpc(description = "Get list of visible contacts") getListOfAllContacts()284 public List<String> getListOfAllContacts() { 285 return mDialerHelper.get().getListOfAllVisibleContacts(); 286 } 287 288 @Rpc(description = "Add Favorites from favorites tab") addFavoritesFromFavoritesTab(String contact)289 public void addFavoritesFromFavoritesTab(String contact) { 290 mDialerHelper.get().addFavoritesFromFavoritesTab(contact); 291 } 292 293 @Rpc(description = "Open Phone Button in Bluetooth Palette") clickPhoneButton()294 public void clickPhoneButton() { 295 mDialerHelper.get().clickPhoneButton(); 296 } 297 298 @Rpc(description = "is Recents displayed in Dialer page ") verifyDialerRecentsTab()299 public boolean verifyDialerRecentsTab() { 300 return mDialerHelper.get().verifyDialerRecentsTab(); 301 } 302 303 @Rpc(description = "is Contacts displayed in Dialer page ") verifyDialerContactsTab()304 public boolean verifyDialerContactsTab() { 305 return mDialerHelper.get().verifyDialerContactsTab(); 306 } 307 308 @Rpc(description = "is Favorites displayed in Dialer page ") verifyDialerFavoritesTab()309 public boolean verifyDialerFavoritesTab() { 310 return mDialerHelper.get().verifyDialerFavoritesTab(); 311 } 312 313 @Rpc(description = "is Dialpad displayed in Dialer page ") verifyDialerDialpadTab()314 public boolean verifyDialerDialpadTab() { 315 return mDialerHelper.get().verifyDialerDialpadTab(); 316 } 317 318 @Override shutdown()319 public void shutdown() {} 320 } 321