summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java31
-rwxr-xr-xorg.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java16
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/PlatformInfo.java92
-rw-r--r--org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java42
4 files changed, 177 insertions, 4 deletions
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
index 7d3bfbe36..67216d066 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
@@ -105,12 +105,12 @@ implements IDevice
* Path for app to be install
*/
protected String installPath;
-
+
/**
* Device root
*/
protected FileEntry root;
-
+
/**
* Constructor with device monitor, serial number and device state.
*
@@ -554,4 +554,31 @@ implements IDevice
return ObjectUtil.equals( getSerialNumber(), device.getSerialNumber() );
}
+ @Override
+ public
+ PlatformInfo
+ getPlatformInfo()
+ throws TimeoutException, SdbCommandRejectedException, IOException
+ {
+ return new PlatformInfo(this);
+ }
+
+ @Override
+ public
+ boolean
+ becomeSuperUser(
+ boolean isOn
+ )
+ throws TimeoutException, SdbCommandRejectedException, IOException
+ {
+ String msg = String.format("root:%s", (isOn == true) ? "on" : "off");
+ byte[] reqBytes = SdbHelper.sendServiceRequest(SmartDevelopmentBridge.getBridge(), this, msg);
+
+ String str = SdbHelper.replyToString(reqBytes);
+ if (!str.startsWith("Permission denied"))
+ {
+ return true;
+ }
+ return false;
+ }
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
index a5bdf79c5..39b90edfb 100755
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
@@ -259,4 +259,20 @@ IDevice
IShellOutputReceiver receiver
)
throws IOException;
+
+ /**
+ * Returns {@link PlatformInfo}
+ */
+ PlatformInfo
+ getPlatformInfo()
+ throws TimeoutException, SdbCommandRejectedException, IOException;
+
+ /**
+ * Switches to root or developer account mode
+ * @param isOn true is to root, and vice versa
+ * @return <code>true</code> if success.
+ */
+ boolean
+ becomeSuperUser(boolean isOn)
+ throws TimeoutException, SdbCommandRejectedException, IOException;
}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/PlatformInfo.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/PlatformInfo.java
new file mode 100644
index 000000000..ed491ce9d
--- /dev/null
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/PlatformInfo.java
@@ -0,0 +1,92 @@
+/*
+* Common
+*
+* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+*
+* Contact:
+* Kangho Kim <kh5325.kim@samsung.com>
+* Yoonki Park<yoonki.park@samsung.com>
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+* Contributors:
+* - S-Core Co., Ltd
+*
+*/
+package org.tizen.sdblib;
+
+import java.io.IOException;
+
+import org.tizen.sdblib.exception.SdbCommandRejectedException;
+import org.tizen.sdblib.exception.TimeoutException;
+
+/**
+ * Represents of the platform information.
+ *
+ * @author Yoonki Park<yoonki.park@samsung.com>
+ */
+public class PlatformInfo {
+ /**
+ * Model name
+ */
+ private String modelName;
+
+ /**
+ * Platform name
+ */
+ private String platformName;
+
+ /**
+ * Platform version
+ */
+ private String platformVersion;
+
+ /**
+ * Profile name
+ */
+ private String profileName;
+
+ public PlatformInfo(Device device) throws TimeoutException, SdbCommandRejectedException, IOException {
+ byte[] reqBytes = SdbHelper.sendServiceRequest(SmartDevelopmentBridge.getBridge(), device, "sysinfo:");
+ byte[] tmpByte = new byte[64];
+
+ // 0~64 bytes stand for info structure version.
+ System.arraycopy(reqBytes, 64, tmpByte, 0, 64);
+ this.modelName = SdbHelper.replyToString(tmpByte);
+
+ System.arraycopy(reqBytes, 128, tmpByte, 0, 64);
+ this.platformName = SdbHelper.replyToString(tmpByte);
+
+ System.arraycopy(reqBytes, 192, tmpByte, 0, 64);
+ this.platformVersion = SdbHelper.replyToString(tmpByte);
+
+ System.arraycopy(reqBytes, 256, tmpByte, 0, 64);
+ this.profileName = SdbHelper.replyToString(tmpByte);
+ }
+
+ public String getModelName() {
+ return this.modelName;
+ }
+
+ public String getPlatformName() {
+ return this.platformName;
+ }
+
+ public String getPlatformVersion() {
+ return this.platformVersion;
+ }
+
+ public String getProfileName() {
+ return this.profileName;
+ }
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
index 649e5e1b8..1c7674813 100644
--- a/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
+++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/SdbHelper.java
@@ -301,7 +301,7 @@ public class SdbHelper {
/**
* Converts reply bytes as a string.
*/
- static String replyToString(byte[] reply) {
+ public static String replyToString(byte[] reply) {
try {
return new String(reply, DEFAULT_ENCODING);
} catch (UnsupportedEncodingException uee) {
@@ -347,7 +347,7 @@ public class SdbHelper {
int count = chan.read(buf);
if (count < 0) {
Log.d("sdb", "read: channel EOF");
- throw new IOException("EOF");
+ break;
} else if (count == 0) {
// TODO: need more accurate timeout?
if ( 0 < timeout && System.currentTimeMillis() - startTime > timeout) {
@@ -450,4 +450,42 @@ public class SdbHelper {
throw new SdbCommandRejectedException( resp.message );
}
}
+
+ /**
+ * Returns bytes from the given service request
+ *
+ * @param sdb bridge to open channel the socket connection
+ * @param device device for requesting a service
+ * @param req service
+ *
+ * @throws TimeoutException in case of timeout on the connection.
+ * @throws SdbCommandRejectedException if sdb rejects the command
+ * @throws IOException in case of I/O error on the connection.
+ */
+ public static byte[] sendServiceRequest(final SmartDevelopmentBridge sdb, final Device device, final String req)
+ throws TimeoutException, SdbCommandRejectedException, IOException {
+ SocketChannel sdbChan = null;
+ byte[] msg = new byte[256];
+ try {
+ sdbChan = sdb.openChannel();
+ initializeDevice(sdbChan, device.getSerialNumber());
+
+ final byte[] request = formSdbRequest(req);
+ write(sdbChan, request);
+
+ SdbResponse resp = readSdbResponse(sdbChan);
+ if (resp.okay == false) {
+ Log.w("sendServiceRequest", "Error creating service(" + req + "):" + resp.message);
+ throw new SdbCommandRejectedException(resp.message);
+ }
+ read(sdbChan, msg);
+ } finally {
+ tryClose( sdbChan );
+ if (sdbChan != null) {
+ sdbChan.close();
+ }
+ }
+
+ return msg;
+ }
}