1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package android.host.systemui; 16 17 /** 18 * Tests the lifecycle of a TileService by adding/removing it and opening/closing 19 * the notification/settings shade through adb commands. 20 */ 21 public class TileServiceTest extends BaseTileServiceTest { 22 23 private static final String SERVICE = "TestTileService"; 24 25 public static final String ACTION_START_ACTIVITY = 26 "android.sysui.testtile.action.START_ACTIVITY"; 27 28 public static final String START_ACTIVITY_AND_COLLAPSE = 29 "am broadcast -a " + ACTION_START_ACTIVITY; 30 TileServiceTest()31 public TileServiceTest() { 32 super(SERVICE); 33 } 34 testAddTile()35 public void testAddTile() throws Exception { 36 if (!supported()) return; 37 addTile(); 38 // Verify that the service starts up and gets a onTileAdded callback. 39 assertTrue(waitFor("onCreate")); 40 assertTrue(waitFor("onTileAdded")); 41 assertTrue(waitFor("onDestroy")); 42 } 43 testRemoveTile()44 public void testRemoveTile() throws Exception { 45 if (!supported()) return; 46 addTile(); 47 // Verify that the service starts up and gets a onTileAdded callback. 48 assertTrue(waitFor("onCreate")); 49 assertTrue(waitFor("onTileAdded")); 50 assertTrue(waitFor("onDestroy")); 51 52 remTile(); 53 assertTrue(waitFor("onTileRemoved")); 54 } 55 testListeningNotifications()56 public void testListeningNotifications() throws Exception { 57 if (!supported()) return; 58 addTile(); 59 assertTrue(waitFor("onDestroy")); 60 61 // Open the notification shade and make sure the tile gets a chance to listen. 62 openNotifications(); 63 assertTrue(waitFor("onStartListening")); 64 // Collapse the shade and make sure the listening ends. 65 collapse(); 66 assertTrue(waitFor("onStopListening")); 67 } 68 testListeningSettings()69 public void testListeningSettings() throws Exception { 70 if (!supported()) return; 71 addTile(); 72 assertTrue(waitFor("onDestroy")); 73 74 // Open the quick settings and make sure the tile gets a chance to listen. 75 openSettings(); 76 assertTrue(waitFor("onStartListening")); 77 // Collapse the shade and make sure the listening ends. 78 collapse(); 79 assertTrue(waitFor("onStopListening")); 80 } 81 testCantAddDialog()82 public void testCantAddDialog() throws Exception { 83 if (!supported()) return; 84 addTile(); 85 assertTrue(waitFor("onDestroy")); 86 87 // Wait for the tile to be added. 88 assertTrue(waitFor("onTileAdded")); 89 90 // Open the quick settings and make sure the tile gets a chance to listen. 91 openSettings(); 92 assertTrue(waitFor("onStartListening")); 93 94 // Try to open a dialog, verify it doesn't happen. 95 showDialog(); 96 assertTrue(waitFor("handleShowDialog")); 97 assertTrue(waitFor("onWindowAddFailed")); 98 } 99 testClick()100 public void testClick() throws Exception { 101 if (!supported()) return; 102 addTile(); 103 // Wait for the tile to be added. 104 assertTrue(waitFor("onTileAdded")); 105 106 // Open the quick settings and make sure the tile gets a chance to listen. 107 openSettings(); 108 assertTrue(waitFor("onStartListening")); 109 110 // Click on the tile and verify it happens. 111 clickTile(); 112 assertTrue(waitFor("onClick")); 113 114 // Verify the state that gets dumped during a click. 115 // Device is expected to be unlocked and unsecure during CTS. 116 // The unlock callback should be triggered immediately. 117 assertTrue(waitFor("is_secure_false")); 118 assertTrue(waitFor("is_locked_false")); 119 assertTrue(waitFor("unlockAndRunRun")); 120 } 121 testClickAndShowDialog()122 public void testClickAndShowDialog() throws Exception { 123 if (!supported()) return; 124 addTile(); 125 assertTrue(waitFor("onDestroy")); 126 127 // Open the quick settings and make sure the tile gets a chance to listen. 128 openSettings(); 129 assertTrue(waitFor("onStartListening")); 130 131 // Click on the tile and verify it happens. 132 clickTile(); 133 assertTrue(waitFor("onClick")); 134 135 // Try to open a dialog, verify it doesn't happen. 136 showDialog(); 137 assertTrue(waitFor("handleShowDialog")); 138 assertTrue(waitFor("onWindowFocusChanged_true")); 139 } 140 testStartActivity()141 public void testStartActivity() throws Exception { 142 if (!supported()) return; 143 addTile(); 144 // Wait for the tile to be added. 145 assertTrue(waitFor("onTileAdded")); 146 147 // Open the quick settings and make sure the tile gets a chance to listen. 148 openSettings(); 149 assertTrue(waitFor("onStartListening")); 150 151 // Trigger the startActivityAndCollapse call and verify we get taken out of listening 152 // because the shade gets collapsed. 153 getDevice().executeShellCommand(START_ACTIVITY_AND_COLLAPSE); 154 assertTrue(waitFor("onStopListening")); 155 } 156 157 } 158