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.IAutoBluetoothSettingsHelper; 21 import android.platform.helpers.IAutoDateTimeSettingsHelper; 22 import android.platform.helpers.IAutoSettingHelper; 23 import android.platform.helpers.IAutoStatusBarHelper; 24 import android.platform.helpers.SettingsConstants; 25 26 import com.google.android.mobly.snippet.Snippet; 27 import com.google.android.mobly.snippet.rpc.Rpc; 28 29 /** Snippet class for exposing Settings APIs. */ 30 public class SettingsSnippet implements Snippet { 31 32 private HelperAccessor<IAutoSettingHelper> mSettingsHelper; 33 private HelperAccessor<IAutoBluetoothSettingsHelper> mBluetoothSettingsHelper; 34 private HelperAccessor<IAutoStatusBarHelper> mStatusBarHelper; 35 36 private static String sBluetoothSettings = "OPEN_BLUETOOTH_SETTINGS_WORKFLOW"; 37 private HelperAccessor<IAutoDateTimeSettingsHelper> mDateTimeSettingsHelper; 38 SettingsSnippet()39 public SettingsSnippet() { 40 mSettingsHelper = new HelperAccessor<>(IAutoSettingHelper.class); 41 mBluetoothSettingsHelper = new HelperAccessor<>(IAutoBluetoothSettingsHelper.class); 42 mStatusBarHelper = new HelperAccessor<>(IAutoStatusBarHelper.class); 43 mDateTimeSettingsHelper = new HelperAccessor<>(IAutoDateTimeSettingsHelper.class); 44 } 45 46 @Rpc(description = "Return whether the bluetooth preference button is checked") isBluetoothPreferenceChecked()47 public boolean isBluetoothPreferenceChecked() { 48 return mBluetoothSettingsHelper.get().isBluetoothPreferenceChecked(); 49 } 50 51 @Rpc(description = "Return whether the media preference button is checked") isMediaPreferenceChecked()52 public boolean isMediaPreferenceChecked() { 53 return mBluetoothSettingsHelper.get().isMediaPreferenceChecked(); 54 } 55 56 @Rpc(description = "Return whether the media preference button is enabled") isMediaPreferenceEnabled()57 public boolean isMediaPreferenceEnabled() { 58 return mBluetoothSettingsHelper.get().isMediaPreferenceEnabled(); 59 } 60 61 @Rpc(description = "Return whether the phone preference button is checked.") isPhonePreferenceChecked()62 public boolean isPhonePreferenceChecked() { 63 return mBluetoothSettingsHelper.get().isPhonePreferenceChecked(); 64 } 65 66 @Rpc(description = "Return whether the phone preference button is enabled") isPhonePreferenceEnabled()67 public boolean isPhonePreferenceEnabled() { 68 return mBluetoothSettingsHelper.get().isPhonePreferenceEnabled(); 69 } 70 71 @Rpc( 72 description = 73 "Get the device summary of a device " 74 + "whose level two connection screen is currently open.") getDeviceSummary()75 public String getDeviceSummary() { 76 return mBluetoothSettingsHelper.get().getDeviceSummary(); 77 } 78 79 @Rpc(description = "Open system settings.") openSystemSettings()80 public void openSystemSettings() { 81 mSettingsHelper.get().openFullSettings(); 82 } 83 84 @Rpc(description = "Open the bluetooth settings (from home screen)") openBluetoothSettings()85 public void openBluetoothSettings() { 86 mSettingsHelper.get().openSetting(sBluetoothSettings); 87 } 88 @Rpc(description = "Open the bluetooth settings (from status bar)") openBluetoothSettingsFromStatusBar()89 public void openBluetoothSettingsFromStatusBar() { 90 mStatusBarHelper.get().openBluetoothPalette(); 91 mStatusBarHelper.get().openBluetoothSettings(); 92 } 93 94 /** Go Back to bluetooth settings (from L2 Pages) */ 95 @Rpc(description = "Go Back to bluetooth settings (from L2 Pages)") goBackToBluetoothSettings()96 public void goBackToBluetoothSettings() { 97 mBluetoothSettingsHelper.get().goBackToBluetoothSettings(); 98 } 99 100 /** Press the phone preference toggle button */ 101 @Rpc(description = "Press the phone toggle on a entry under 'Paired Devices'") pressPhoneToggleOnDevice(String deviceName)102 public void pressPhoneToggleOnDevice(String deviceName) { 103 mBluetoothSettingsHelper.get().pressPhoneToggleOnDevice(deviceName); 104 } 105 106 @Rpc(description = "Press the bluetooth toggle on a entry under 'Paired Devices'") pressBluetoothToggleOnDevice(String deviceName)107 public void pressBluetoothToggleOnDevice(String deviceName) { 108 mBluetoothSettingsHelper.get().pressBluetoothToggleOnDevice(deviceName); 109 } 110 111 /** 112 * RPC to press the bluetooth toggle on a entry under 'Paired Devices'" 113 * 114 * @param deviceName - The listed device whose bluetooth toggle should be switched. 115 */ 116 @Rpc(description = "Press the bluetooth toggle on a entry under 'Paired Devices'") pressMediaToggleOnDevice(String deviceName)117 public void pressMediaToggleOnDevice(String deviceName) { 118 mBluetoothSettingsHelper.get().pressMediaToggleOnDevice(deviceName); 119 } 120 121 @Rpc(description = "Press device on device list.") pressDeviceInBluetoothSettings(String deviceName)122 public void pressDeviceInBluetoothSettings(String deviceName) { 123 mBluetoothSettingsHelper.get().pressDevice(deviceName); 124 } 125 126 @Rpc(description = "Press an entry listed under 'Paired Devices'") pressDeviceName(String deviceName)127 public void pressDeviceName(String deviceName) { 128 mBluetoothSettingsHelper.get().pressDevice(deviceName); 129 } 130 131 @Rpc( 132 description = 133 "Get the connection status of a device " 134 + "whose level two connection screen is currently open.") deviceIsConnected()135 public void deviceIsConnected() { 136 mBluetoothSettingsHelper.get().isConnected(); 137 } 138 139 @Rpc(description = "Press the Forget button on a currently open Level Two connection screen") pressForget()140 public void pressForget() { 141 mBluetoothSettingsHelper.get().pressForget(); 142 } 143 144 @Rpc(description = "Get the device timezone") getTimeZone()145 public String getTimeZone() { 146 return mDateTimeSettingsHelper.get().getTimeZone(); 147 } 148 149 @Rpc(description = "Open Date time Setting") setTimeZone(String timezone)150 public void setTimeZone(String timezone) { 151 mSettingsHelper.get().openSetting(SettingsConstants.DATE_AND_TIME_SETTINGS); 152 mDateTimeSettingsHelper.get().setTimeZone(timezone); 153 } 154 155 @Override shutdown()156 public void shutdown() {} 157 } 158