1 /******************************************************************
3 * Copyright 2018 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 ******************************************************************/
22 package org.iotivity.test.rfw.common.devicecontroller.tizen;
24 import java.io.BufferedReader;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.util.ArrayList;
29 import org.iotivity.test.rfw.common.devicecontroller.interfaces.INetworkController;
30 import org.iotivity.test.rfw.common.util.SystemUtil;
32 import org.iotivity.test.rfw.common.devicecontroller.tizen.TizenCommand;
34 class TizenNetworkManager implements INetworkController {
36 private String deviceID = null;
38 public TizenNetworkManager(String deviceID) {
39 this.deviceID = deviceID;
43 public boolean wifiOn() {
45 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
46 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
47 TizenCommand.CLEAN, TizenCommand.WIFI_SERVICE_ENABLE };
49 Process process = Runtime.getRuntime().exec(command);
50 BufferedReader in = new BufferedReader(
51 new InputStreamReader(process.getInputStream()));
53 SystemUtil.sleep(1000);
54 while ((line = in.readLine()) != null) {
55 if (line.contains("fail"))
58 } catch (IOException e) {
65 public boolean wifiOff() {
66 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
67 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
68 TizenCommand.CLEAN, TizenCommand.WIFI_SERVICE_DISABLE };
70 Process process = Runtime.getRuntime().exec(command);
71 BufferedReader in = new BufferedReader(
72 new InputStreamReader(process.getInputStream()));
75 SystemUtil.sleep(1000);
76 while ((line = in.readLine()) != null) {
77 if (line.contains("fail"))
80 } catch (IOException e) {
87 public boolean blueToothOn() {
88 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
89 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
90 TizenCommand.CLEAN, TizenCommand.BLUETOOTH_SERVICE_ENABLE };
92 Process process = Runtime.getRuntime().exec(command);
93 BufferedReader in = new BufferedReader(
94 new InputStreamReader(process.getInputStream()));
96 SystemUtil.sleep(1000);
97 while ((line = in.readLine()) != null) {
98 if (line.contains("fail"))
101 } catch (IOException e) {
109 public boolean blueToothOff() {
110 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
111 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
112 TizenCommand.CLEAN, TizenCommand.BLUETOOTH_SERVICE_DISABLE };
114 Process process = Runtime.getRuntime().exec(command);
115 BufferedReader in = new BufferedReader(
116 new InputStreamReader(process.getInputStream()));
118 SystemUtil.sleep(1000);
119 while ((line = in.readLine()) != null) {
120 if (line.contains("fail"))
123 } catch (IOException e) {
130 public String getIPAddress() {
132 String line = "NULL";
133 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
134 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
135 TizenCommand.CLEAN, TizenCommand.GET_IP_ADDRESS };
138 Process process = Runtime.getRuntime().exec(command);
139 BufferedReader in = new BufferedReader(
140 new InputStreamReader(process.getInputStream()));
142 SystemUtil.sleep(1000);
143 while ((line = in.readLine()) != null) {
144 if (line.contains("fail"))
145 return "Bluetooth Address failed";
146 else if (line.contains("")) {
147 if (line.contains("IP Address:")) {
148 int start = line.indexOf("IP Address: ")
149 + "IP Address: ".length();
150 String ret = line.substring(start, line.length());
155 } catch (IOException e) {
157 line = "Exception " + e.toString();
164 public String getBluetoothMacAddress() {
166 String line = "NULL";
167 String[] command = { TizenCommand.SDB, TizenCommand.SPECOPTION,
168 this.deviceID, TizenCommand.SHELL, TizenCommand.ROOT,
169 TizenCommand.CLEAN, TizenCommand.GET_MAC_ADDRESS };
171 // String cmd = "service call bluetooth_manager 10";
173 Process process = Runtime.getRuntime().exec(command);
174 BufferedReader in = new BufferedReader(
175 new InputStreamReader(process.getInputStream()));
177 SystemUtil.sleep(1000);
178 while ((line = in.readLine()) != null) {
179 if (line.contains("fail"))
180 return "Bluetooth Address failed";
181 else if (line.contains("")) {
182 if (line.contains("Adapter address:")) {
183 int start = line.indexOf("Adapter address: ")
184 + "Adapter address: ".length();
185 int end = line.indexOf(".");
186 String ret = line.substring(start, end);
191 } catch (IOException e) {
198 public ArrayList<String> getNetworkInformations() {
203 public boolean setSDKPath(String sdkPath) {