1#!/usr/bin/env python3 2# 3# Copyright 2022 - Google 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17 18import time 19from acts.libs.utils.multithread import multithread_func 20from acts.libs.utils.multithread import run_multithread_func 21from acts_contrib.test_utils.net import ui_utils as uutils 22from acts.controllers.android_lib.errors import AndroidDeviceError 23from acts_contrib.test_utils.tel.tel_logging_utils import log_screen_shot 24from acts_contrib.test_utils.tel.tel_logging_utils import get_screen_shot_log 25from acts_contrib.test_utils.tel.tel_logging_utils import get_screen_shot_logs 26 27RESOURCE_ID_ENABLE_CHAT_FEATURE = "com.google.android.apps.messaging:id/switchWidget" 28RESOURCE_ID_RCS_SETTINGS = "com.google.android.apps.messaging/.ui.appsettings.RcsSettingsActivity" 29RESOURCE_ID_START_CHAT = "com.google.android.apps.messaging:id/start_chat_fab" 30 31def go_to_message_app(ad): 32 """Launch message app. 33 34 Args: 35 ad: android devices 36 37 Returns: 38 True if pass; False if fail 39 """ 40 ad.log.info("Launch message settings") 41 ad.adb.shell("am start -n com.google.android.apps.messaging/.ui." 42 "ConversationListActivity") 43 log_screen_shot(ad, "launch_msg_settings") 44 if uutils.has_element(ad, resource_id=RESOURCE_ID_START_CHAT): 45 return True 46 else: 47 return False 48 49def go_to_rcs_settings(ad): 50 """Goes to RCS settings. 51 52 Args: 53 ad: android devices 54 Returns: 55 True if pass; False if fail 56 """ 57 ad.log.info("Go to chat features settings") 58 ad.adb.shell("am start -n com.google.android.apps.messaging/.ui." 59 "appsettings.RcsSettingsActivity") 60 log_screen_shot(ad, "launch_rcs_settings") 61 if uutils.has_element(ad, text="Chat features"): 62 return True 63 else: 64 return False 65 66def is_rcs_enabled(ad): 67 """Checks RCS feature is enabled or not. 68 69 Args: 70 ad: android devices 71 Returns: 72 True if RCS is enabled; False if RCS is not enabled 73 """ 74 go_to_rcs_settings(ad) 75 if uutils.has_element(ad, text="Status: Connected", timeout=30): 76 ad.log.info("RCS is connected") 77 return True 78 return False 79 80 81def enable_chat_feature(ad): 82 """Enable chat feature. 83 84 Args: 85 ad: android devices 86 87 Returns: 88 True if pass; False if fail 89 """ 90 if not is_rcs_enabled(ad): 91 ad.log.info("Try to enable chat feature") 92 go_to_rcs_settings(ad) 93 time.sleep(2) 94 if uutils.has_element(ad, resource_id=RESOURCE_ID_ENABLE_CHAT_FEATURE): 95 uutils.wait_and_click(ad, resource_id=RESOURCE_ID_ENABLE_CHAT_FEATURE, 96 matching_node=1) 97 ad.log.info("Click on enable chat features") 98 time.sleep(2) 99 log_screen_shot(ad, "enable_chat_feature") 100 if uutils.has_element(ad, text="Status: Connected", timeout=30): 101 ad.log.info("RCS status shows connected") 102 if uutils.has_element(ad, text="Verify your number"): 103 uutils.wait_and_click(ad, text="Verify your number") 104 ad.log.info("Click on Verify your number") 105 time.sleep(2) 106 log_screen_shot(ad, "verify_number") 107 if not uutils.has_element(ad, text=ad.phone_number, timeout=30): 108 uutils.wait_and_input_text(ad, input_text=ad.phone_number) 109 ad.log.info("input phone number %s", ad.phone_number) 110 time.sleep(2) 111 log_screen_shot(ad, "input_phone_num") 112 # click verify now 113 if uutils.has_element(ad, text="Verify now"): 114 uutils.wait_and_click(ad, text="Verify now") 115 ad.log.info("Click verify now") 116 time.sleep(2) 117 log_screen_shot(ad, "verify_now") 118 # wait for RCS to be enabled 119 time.sleep(120) 120 else: 121 ad.log.info("RCS is already enabled") 122 if not is_rcs_enabled(ad): 123 ad.log.info("RCS is not enabled") 124 return False 125 return True 126 127 128def disable_chat_feature(ad): 129 """Disable chat feature. 130 131 Args: 132 ad: android devices 133 134 Returns: 135 True if pass; False if fail 136 """ 137 go_to_rcs_settings(ad) 138 time.sleep(2) 139 log_screen_shot(ad, "before_disable_chat_feature") 140 if uutils.has_element(ad, text="Status: Connected", timeout=30): 141 ad.log.info("RCS is connected") 142 uutils.wait_and_click(ad, resource_id=RESOURCE_ID_ENABLE_CHAT_FEATURE, 143 matching_node=1) 144 time.sleep(2) 145 ad.log.info("Turn off chat features") 146 if uutils.has_element(ad, text="Turn off", timeout=30): 147 uutils.wait_and_click(ad, text="Turn off") 148 time.sleep(2) 149 log_screen_shot(ad, "after_disable_chat_feature") 150 return True 151 else: 152 ad.log.info("RCS is not connected") 153 return False 154 155def is_rcs_connected(ad, begin_time=None): 156 """search logcat for RCS related message. 157 158 Args: 159 ad: android devices 160 begin_time: only the lines with time stamps later than begin_time 161 will be searched. 162 Returns: 163 True if found RCS connected message; False if fail 164 """ 165 bugle_log_results = ad.search_logcat('BugleRcsEngine', begin_time) 166 ad.log.info('BugleRcsEngine result %s' %bugle_log_results) 167 log_results = ad.search_logcat('Enter PublishedState', begin_time) 168 ad.log.info('Enter PublishedState result %s' %log_results) 169 if log_results: 170 ad.log.info("RCS is connected") 171 return True 172 return False 173