• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 package android.support.test.launcherhelper;
17 
18 import android.app.Instrumentation;
19 import android.support.test.uiautomator.By;
20 import android.support.test.uiautomator.BySelector;
21 import android.support.test.uiautomator.Direction;
22 import android.support.test.uiautomator.UiDevice;
23 import android.support.test.uiautomator.UiObject2;
24 import android.support.test.uiautomator.Until;
25 import android.system.helpers.CommandsHelper;
26 
27 public class AutoLauncherStrategy  implements IAutoLauncherStrategy {
28 
29     private static final String LOG_TAG = AutoLauncherStrategy.class.getSimpleName();
30     private static final String CAR_LENSPICKER = "com.android.support.car.lenspicker";
31 
32     private static final long APP_INIT_WAIT = 10000;
33 
34     //todo: Remove x and y axis and use resource ID's.
35     private static final int FACET_APPS = 560;
36     private static final int MAP_FACET = 250;
37     private static final int DIAL_FACET = 380;
38     private static final int HOME_FACET = 530;
39     private static final int MEDIA_FACET = 680;
40     private static final int SETTINGS_FACET = 810;
41 
42     private static final BySelector R_ID_LENSPICKER_PAGEDOWN =
43             By.res(CAR_LENSPICKER, "page_down");
44 
45     protected UiDevice mDevice;
46     private Instrumentation mInstrumentation;
47 
48     @Override
getSupportedLauncherPackage()49     public String getSupportedLauncherPackage() {
50         return CAR_LENSPICKER;
51     }
52 
53     @Override
setUiDevice(UiDevice uiDevice)54     public void setUiDevice(UiDevice uiDevice) {
55         mDevice = uiDevice;
56     }
57 
58     @Override
setInstrumentation(Instrumentation instrumentation)59     public void setInstrumentation(Instrumentation instrumentation) {
60         mInstrumentation = instrumentation;
61     }
62 
63     @Override
open()64     public void open() {
65 
66     }
67 
68     @Override
openDialFacet()69     public void openDialFacet() {
70         CommandsHelper.getInstance(mInstrumentation).executeShellCommand(
71                 "input tap " + DIAL_FACET + " " + FACET_APPS);
72     }
73 
74     @Override
openMediaFacet(String appName)75     public  void openMediaFacet(String appName) {
76         openApp(appName, MEDIA_FACET, FACET_APPS);
77     }
78 
79     @Override
openSettingsFacet(String appName)80     public void openSettingsFacet(String appName) {
81         openApp(appName, SETTINGS_FACET, FACET_APPS);
82     }
83 
84     @Override
openMapsFacet(String appName)85     public void openMapsFacet(String appName) {
86         CommandsHelper.getInstance(mInstrumentation).executeShellCommand(
87                 "input tap " + MAP_FACET + " " + FACET_APPS);
88     }
89 
90     @Override
openHomeFacet()91     public void openHomeFacet() {
92         CommandsHelper.getInstance(mInstrumentation).executeShellCommand(
93                 "input tap " + HOME_FACET + " " + FACET_APPS);
94     }
95 
openApp(String appName, int x, int y)96     public void openApp(String appName, int x, int y) {
97         do {
98             CommandsHelper.getInstance(mInstrumentation).executeShellCommand(
99                     "input tap " + x + " " + y);
100         }
101         while (!mDevice.hasObject(R_ID_LENSPICKER_PAGEDOWN));
102 
103         UiObject2 scrollContainer = mDevice.findObject(R_ID_LENSPICKER_PAGEDOWN);
104 
105         if (scrollContainer == null) {
106             throw new UnsupportedOperationException("Cannot find scroll container");
107         }
108 
109         if (!mDevice.hasObject(By.text(appName))) {
110             do {
111                 scrollContainer.scroll(Direction.DOWN, 1.0f);
112             }
113             while (!mDevice.hasObject(By.text(appName)) && scrollContainer.isEnabled());
114         }
115 
116         if (!scrollContainer.isEnabled()) {
117             throw new UnsupportedOperationException("Unable to find application " + appName);
118         }
119 
120         UiObject2 application = mDevice.wait(Until.findObject(By.text(appName)), APP_INIT_WAIT);
121         if (application != null) {
122             application.click();
123             mDevice.waitForIdle();
124         } else {
125             throw new RuntimeException("Unable to find permission text ok button");
126         }
127     }
128 
129     @SuppressWarnings("unused")
130     @Override
openAllApps(boolean reset)131     public UiObject2 openAllApps(boolean reset) {
132         throw new UnsupportedOperationException(
133                 "The feature not supported on Auto");
134     }
135 
136     @SuppressWarnings("unused")
137     @Override
getAllAppsButtonSelector()138     public BySelector getAllAppsButtonSelector() {
139         throw new UnsupportedOperationException(
140                 "The feature not supported on Auto");
141     }
142 
143     @SuppressWarnings("unused")
144     @Override
getAllAppsSelector()145     public BySelector getAllAppsSelector() {
146         throw new UnsupportedOperationException(
147                 "The feature not supported on Auto");
148     }
149 
150     @SuppressWarnings("unused")
151     @Override
getAllAppsScrollDirection()152     public Direction getAllAppsScrollDirection() {
153         throw new UnsupportedOperationException(
154                 "The feature not supported on Auto");
155     }
156 
157     @SuppressWarnings("unused")
158     @Override
openAllWidgets(boolean reset)159     public UiObject2 openAllWidgets(boolean reset) {
160         throw new UnsupportedOperationException(
161                 "The feature not supported on Auto");
162     }
163 
164     @SuppressWarnings("unused")
165     @Override
getAllWidgetsSelector()166     public BySelector getAllWidgetsSelector() {
167         throw new UnsupportedOperationException(
168                 "The feature not supported on Auto");
169     }
170 
171     @SuppressWarnings("unused")
172     @Override
getAllWidgetsScrollDirection()173     public Direction getAllWidgetsScrollDirection() {
174         throw new UnsupportedOperationException(
175                 "The feature not supported on Auto");
176     }
177 
178     @SuppressWarnings("unused")
179     @Override
getWorkspaceSelector()180     public BySelector getWorkspaceSelector() {
181         throw new UnsupportedOperationException(
182                 "The feature not supported on Auto");
183     }
184 
185     @SuppressWarnings("unused")
186     @Override
getHotSeatSelector()187     public BySelector getHotSeatSelector() {
188         throw new UnsupportedOperationException(
189                 "The feature not supported on Auto");
190     }
191 
192     @SuppressWarnings("unused")
193     @Override
getWorkspaceScrollDirection()194     public Direction getWorkspaceScrollDirection() {
195         throw new UnsupportedOperationException(
196                 "The feature not supported on Auto");
197     }
198 
199     @SuppressWarnings("unused")
200     @Override
launch(String appName, String packageName)201     public long launch(String appName, String packageName) {
202         return 0;
203     }
204 }
205