1 /******************************************************************
\r
3 * Copyright 2018 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
20 ******************************************************************/
\r
22 package org.iotivity.test.rfw.common.devicecontroller.tizen;
\r
24 import java.io.BufferedReader;
\r
25 import java.io.IOException;
\r
26 import java.io.InputStreamReader;
\r
27 import java.util.logging.Logger;
\r
29 import org.iotivity.test.rfw.common.devicecontroller.android.AndroidCommand;
\r
30 import org.iotivity.test.rfw.common.devicecontroller.datamodel.Coordinate;
\r
31 import org.iotivity.test.rfw.common.devicecontroller.datamodel.KeyEventType;
\r
32 import org.iotivity.test.rfw.common.devicecontroller.interfaces.IScreenController;
\r
33 import org.iotivity.test.rfw.common.devicecontroller.linux.LinuxProcess;
\r
34 import org.iotivity.test.rfw.common.util.IoTivityLogger;
\r
35 import org.iotivity.test.rfw.common.util.SystemUtil;
\r
37 import org.iotivity.test.rfw.common.devicecontroller.tizen.TizenCommand;
\r
38 import org.iotivity.test.rfw.common.devicecontroller.tizen.TizenSDBManager;
\r
40 class TizenScreenController implements IScreenController {
\r
42 private TizenSDBManager sdbManager;
\r
43 private LinuxProcess sendPythonManager;
\r
44 private Logger logger = IoTivityLogger.GetLogger();
\r
46 public TizenScreenController(TizenSDBManager sdbManager) {
\r
47 this.sdbManager = sdbManager;
\r
48 initializeSendVTKeyconnection();
\r
52 public boolean touch(Coordinate point) throws IOException {
\r
53 String points = " " + (int) point.getX() + " " + (int) point.getY();
\r
54 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
55 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
56 "touchDown", points);
\r
57 getSdbManager().executeAsyncCommand(command, null);
\r
58 // touchUp doesn't work
\r
59 command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
60 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
62 // getSdbManager().executeAsyncCommand(command, null);
\r
63 executeCommand(command);
\r
68 public boolean touchDown(Coordinate point) throws IOException {
\r
69 String points = " " + (int) point.getX() + " " + (int) point.getY();
\r
70 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
71 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
72 "touchDown", points);
\r
73 getSdbManager().executeAsyncCommand(command, null);
\r
78 public boolean touchUp(Coordinate point) throws IOException {
\r
79 String points = " " + (int) point.getX() + " " + (int) point.getY();
\r
80 // this touchUp doesn't work
\r
81 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
82 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
84 getSdbManager().executeAsyncCommand(command, null);
\r
89 public boolean touchMove(Coordinate point) throws IOException {
\r
90 String points = " " + (int) point.getX() + " " + (int) point.getY();
\r
91 // this move doesn't work
\r
92 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
93 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
95 // getSdbManager().executeAsyncCommand(command, null);
\r
96 // SystemUtil.sleep(10000);
\r
98 executeCommand(command);
\r
103 public boolean pressKey(KeyEventType key) throws IOException {
\r
104 String keyStr = "";
\r
107 keyStr = "KEY_HOME";
\r
110 keyStr = "KEY_BACK";
\r
113 keyStr = "KEY_VOLUMEUP";
\r
116 keyStr = "KEY_VOLUMEDOWN";
\r
119 keyStr = "KEY_POWER";
\r
122 keyStr = "KEY_MENU";
\r
125 keyStr = "KEY_HOME";
\r
131 String pythonCommand = "sendKey";
\r
132 if (KeyEventType.RecentApps == key)
\r
133 pythonCommand = "sendLongKey";
\r
135 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
136 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
137 pythonCommand, keyStr);
\r
138 // getSdbManager().executeAsyncCommand(command, null);
\r
139 // SystemUtil.sleep(10000);
\r
140 executeCommand(command);
\r
144 private TizenSDBManager getSdbManager() {
\r
148 private boolean initializeSendVTKeyconnection() {
\r
151 String command = String.format("%s %s %s %s", TizenCommand.SDB,
\r
152 AndroidCommand.SPECOPTION, this.sdbManager.getDeviceID(),
\r
153 TizenCommand.SHELL);
\r
154 logger.info(command);
\r
156 sendPythonManager = new LinuxProcess("SENDPYTHON", command);
\r
157 sendPythonManager.inputCommand("cd /var/python/bin");
\r
158 Thread.sleep(1000);
\r
159 sendPythonManager.inputCommand("chmod 777 *");
\r
160 Thread.sleep(1000);
\r
161 sendPythonManager.inputCommand("./python2.7");
\r
162 Thread.sleep(1000);
\r
163 sendPythonManager.inputCommand("import fmbttizenagent");
\r
164 Thread.sleep(1000);
\r
166 } catch (InterruptedException e) {
\r
167 e.printStackTrace();
\r
173 public boolean sendString(String text) throws IOException {
\r
175 if (!sendPythonManager.isProcessRunning())
\r
176 initializeSendVTKeyconnection();
\r
177 sendPythonManager.inputCommand(
\r
178 "fmbttizenagent.typeCharHw(\"" + text + "\")");
\r
179 Thread.sleep(2000);
\r
181 } catch (InterruptedException e) {
\r
182 e.printStackTrace();
\r
188 public boolean tap(Coordinate point) throws IOException {
\r
189 String points = " " + (int) point.getX() + " " + (int) point.getY();
\r
191 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
192 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER, "tap",
\r
194 logger.info(command);
\r
196 // getSdbManager().executeAsyncCommand(command, null);
\r
197 executeCommand(command);
\r
202 * @Override public void openControlSocket(Socket socket) throws IOException
\r
206 public void closeControlSocket() throws IOException {
\r
207 sendPythonManager.destroy();
\r
211 public boolean drag(Coordinate from, Coordinate to) throws IOException {
\r
212 String points = " " + (int) from.getX() + " " + (int) from.getY() + " "
\r
213 + (int) to.getX() + " " + (int) to.getY();
\r
214 String command = String.format("%s %s %s %s %s", TizenCommand.SHELL,
\r
215 TizenCommand.PYTHON_PATH, TizenCommand.SCREEN_CONTROLLER,
\r
217 logger.info(command);
\r
219 // getSdbManager().executeAsyncCommand(command, null);
\r
220 executeCommand(command);
\r
224 public void executeCommand(String command) {
\r
226 command = "sdb -s " + sdbManager.getDeviceID() + " " + command;
\r
227 logger.info(command);
\r
228 Process process = Runtime.getRuntime().exec(command);
\r
229 BufferedReader in = new BufferedReader(
\r
230 new InputStreamReader(process.getInputStream()));
\r
231 SystemUtil.sleep(1000);
\r
233 while ((line = in.readLine()) != null) {
\r
234 logger.info("ROOT ON output : " + line);
\r
236 SystemUtil.sleep(1000);
\r
237 } catch (IOException e) {
\r
238 e.printStackTrace();
\r
239 logger.info("Exception occured in executing command " + command
\r
240 + "ERROR::::" + e.toString());
\r