[Title] applied tizen_2.1 branch's change.
authorGun Kim <gune.kim@samsung.com>
Wed, 17 Apr 2013 08:56:10 +0000 (17:56 +0900)
committerGun Kim <gune.kim@samsung.com>
Wed, 17 Apr 2013 08:56:10 +0000 (17:56 +0900)
added pkgcmd's error message &
applied "sdb launch" &
fixed bugs
[Type]
[Module]
[Priority]
[Jira#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

Change-Id: I0d14f43f0c3b911e932eb9e06890f20d672debbb

org.tizen.common.sdblib/src/org/tizen/sdblib/Device.java
org.tizen.common.sdblib/src/org/tizen/sdblib/IDevice.java
org.tizen.common/src/org/tizen/common/TizenPlatformConstants.java
org.tizen.common/src/org/tizen/common/rds/RdsDeployer.java
org.tizen.common/src/org/tizen/common/sdb/command/SdbCommand.java
org.tizen.common/src/org/tizen/common/sdb/command/message/PkgcmdErrorMessages.java
org.tizen.common/src/org/tizen/common/sdb/command/message/PkgcmdErrorMessages.properties
org.tizen.common/src/org/tizen/common/sdb/command/message/PkgcmdErrorType.java
org.tizen.common/src/org/tizen/common/sdb/command/receiver/CommandOutputReceiver.java
org.tizen.common/src/org/tizen/common/sdb/command/receiver/PkgCmdReceiver.java

index e95b713..86ec094 100644 (file)
 
 package org.tizen.sdblib;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.io.InputStreamReader;
 
 import org.tizen.sdblib.SyncService.SyncResult;
 
@@ -129,6 +131,68 @@ final class Device implements IDevice {
     public FileListingService getFileListingService() {
         return new FileListingService(this);
     }
+    
+    @Override
+    public void executeLaunchCommand(IShellOutputReceiver receiver, String options) throws IOException {
+        executeCommand("launch", receiver, options);
+    }
+
+    public void executeCommand(String command, IShellOutputReceiver receiver, String options) throws IOException {
+        SmartDevelopmentBridge sdb = SmartDevelopmentBridge.getBridge();
+        if (sdb == null)
+            return;
+        String sdbPath = sdb.getSdbOsLocation();
+        if (sdbPath == null)
+            return;
+        if (mSerialNumber == null)
+            return;
+        if (command == null || command.isEmpty())
+            return;
+
+        String sdbShellCmd = sdbPath + " -s " + mSerialNumber + " " + command + ((options != null) ? " " + options : "");
+        Process pSdb = Runtime.getRuntime().exec(sdbShellCmd);
+        sdbShellProcess = new SdbShellProcess(pSdb, command);
+        BufferedReader stdInput = null;
+        BufferedReader stdError = null;
+        try {
+            stdInput = new BufferedReader(new InputStreamReader(sdbShellProcess.getInputStream()));
+            stdError = new BufferedReader(new InputStreamReader(sdbShellProcess.getErrorStream()));
+            String s = null;
+            while ((s = stdInput.readLine()) != null) {
+                if (receiver != null && receiver.isCancelled()) {
+                    break;
+                }
+                byte[] bytes = s.getBytes();
+                if (receiver != null) {
+                    receiver.addOutput(s.getBytes(), 0, bytes.length);
+                }
+            }
+            while ((s = stdError.readLine()) != null) {
+                if (receiver != null && receiver.isCancelled()) {
+                    break;
+                }
+                byte[] bytes = s.getBytes();
+                if (receiver != null) {
+                    receiver.addOutput(s.getBytes(), 0, bytes.length);
+                }
+            }
+        } finally {
+            if ( stdInput != null ) {
+                try {
+                    stdInput.close();
+                } catch (Exception e) {
+                }
+            }
+            if ( stdError != null ) {
+                try {
+                    stdError.close();
+                } catch (Exception e) {
+                }
+            }
+            if (receiver != null)
+                receiver.flush();
+        }
+    }
 
     public SdbShellProcess executeShellCommand(String command) throws IOException {
         return (SdbShellProcess) executeShellCommand(command, true);
index 69c497d..9241e78 100755 (executable)
@@ -149,7 +149,7 @@ public interface IDevice {
      * @see SdbShellProcess
      */
     SdbShellProcess executeShellCommand(String command) throws IOException;
-
+    
     /**
      * Executes a shell command to the device promptly and return SdbShellProcess
      *
@@ -211,6 +211,15 @@ public interface IDevice {
             int maxTimeToOutputResponse)
             throws TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException,
             IOException;
+    
+    /**
+     * Executes a sdb launch command on the device, and sends the result to a <var>receiver</var>.
+     *
+     * @param receiver the {@link IShellOutputReceiver} that will receives the output of the command
+     * @param options arguments of the launch command
+     * @throws IOException in case of I/O error on the connection
+     */
+    public void executeLaunchCommand(IShellOutputReceiver receiver, String options) throws IOException;
 
     /**
      * Runs the event log service and outputs the event log to the {@link LogReceiver}.
index cc5439e..b0fd54b 100644 (file)
@@ -86,8 +86,11 @@ public class TizenPlatformConstants {
     public static final String PKG_TOOL_TERMINATE_COMMAND;
     public static final String PKG_TOOL_REINSTALL_COMMAND;
     public static final String PKG_TOOL_INSTALL_PATH_COMMAND;
+    public static final String PKG_TOOL_ROAPP_CHECK_COMMAND;
     public static final String REMOVE_FILE_COMMAND;
     public static final String DLOGUTIL_CMD;
+    public static final String ROAPP_RESULT;
+    public static final String RWAPP_RESULT;
 
     // Definitions for RDS
     public static final String RDS_PUSH_DIRECTORY_COMMAND = "mkdir -p -m 755 \"%s\""+ TizenPlatformConstants.CMD_SUFFIX;
@@ -151,6 +154,10 @@ public class TizenPlatformConstants {
         PKG_TOOL_TERMINATE_COMMAND = PKG_TOOL + " -k -t %s -n %s";
         // Check org.tizen.sdblib.Device.PKG_TOOL_INSTALL_PATH_COMMAND constant
         PKG_TOOL_INSTALL_PATH_COMMAND = PKG_TOOL + " -a";
+        PKG_TOOL_ROAPP_CHECK_COMMAND = "/usr/bin/pkginfo --pkg %s | grep -i Removable";
+        ROAPP_RESULT = "Removable: 0";
+        RWAPP_RESULT = "Removable: 1";
+        
         REMOVE_FILE_COMMAND = "rm -rf %s";
 
         // Should be absolute path
index a03f76f..09bde96 100644 (file)
@@ -230,6 +230,7 @@ public abstract class RdsDeployer implements Closeable{
         if ( file != null ) {
             try {
                 pushFile(file.getCanonicalPath(), strAppInstallPath + "/" + file.getName());
+                command = RdsDeployer.makeRdsLog(NLS.bind(RdsMessages.RDS_PUSH_LOG, file.getCanonicalPath(), strAppInstallPath + "/" + file.getName()));
                 printInfo( command );
             } catch (Exception e) {
                 newCoreException(RdsDeployer.makeRdsLog(RdsMessages.RDS_PUSH_ERROR), e);
index 7f91766..395a95f 100644 (file)
@@ -37,6 +37,7 @@ import org.tizen.common.util.StringUtil;
 import org.tizen.sdblib.IDevice;
 import org.tizen.sdblib.SdbCommandRejectedException;
 import org.tizen.sdblib.ShellCommandUnresponsiveException;
+import org.tizen.sdblib.SmartDevelopmentBridge;
 import org.tizen.sdblib.TimeoutException;
 
 
@@ -72,6 +73,37 @@ public class SdbCommand {
         this.endLine = receiver.getEndLine();
         this.commandOutput = receiver.getCommandOutput();
     }
+    
+    public void runLaunchCommand(String command) throws IOException {
+        runLaunchCommand(command, true);
+    }
+    
+    public Process runLaunchCommand(String command, boolean isBlock) throws IOException {
+        Process process = null;
+        if (console != null) {
+            console.println("$ sdb launch " + command);
+        }
+        
+        if ( isBlock ) {
+            device.executeLaunchCommand(receiver, command);
+
+            this.endLine = receiver.getEndLine();
+            this.commandOutput = receiver.getCommandOutput();
+        }
+        else {
+            SmartDevelopmentBridge sdb = SmartDevelopmentBridge.getBridge();
+            if (sdb == null) {
+                throw new IOException("Cannot find sdb command");
+            }
+            String sdbPath = sdb.getSdbOsLocation();
+            if (sdbPath == null) {
+                throw new IOException("Cannot find sdb command");
+            }
+            process = Runtime.getRuntime().exec(sdbPath + " launch " + command);
+        }
+        
+        return process;
+    }
 
     public CommandErrorType runCommand(String command, CommandErrorType messages ) throws CommandErrorException, TimeoutException, SdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
         return runCommand(command, messages, DEFAULT_TIMEOUT);
@@ -83,7 +115,9 @@ public class SdbCommand {
         }
 
         device.executeShellCommand( makeCommandWithExitcode(command), receiver, timeout);
-
+        this.endLine = receiver.getEndLine();
+        this.commandOutput = receiver.getCommandOutput();
+        
         String endLine = receiver.getEndLine();
         int exitcode = parseExitcode(endLine);
 
@@ -102,6 +136,16 @@ public class SdbCommand {
         return commandOutput;
     }
     
+    public String[] getResultLineStrings() {
+        String strs = commandOutput.toString();
+        if ( StringUtil.isEmpty(strs) ) {
+            return new String[0];
+        }
+        String [] str = StringUtil.split( strs, System.getProperty("line.separator") );
+        
+        return str;
+    }
+    
     private int parseExitcode(String line) {
         int exitcode = -1;
         if ( line.startsWith(TizenPlatformConstants.CMD_RESULT_PREFIX) ) {
index b1c94ca..74591d0 100644 (file)
@@ -51,11 +51,12 @@ public class PkgcmdErrorMessages {
     public static String ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED;
     public static String ERROR_CERTIFICATE_EXPIRED;
     public static String ERROR_INVALID_PRIVILEGE;
+    public static String ERROR_PRIVILEGE_LEVEL_VIOLATION;
     public static String ERROR_MENU_ICON_NOT_FOUND;
     public static String ERROR_FATAL_ERROR;
     public static String ERROR_OUT_OF_STORAGE;
     public static String ERROR_OUT_OF_MEMORY;
-    public static String ERROR_UNKNOWN;
+    public static String ERROR_ARGUMENT_INVALID;
 
     //web app error messages.
     public static String ERROR_WEB_PACKAGE_ALREADY_INSTALLED;
@@ -67,4 +68,6 @@ public class PkgcmdErrorMessages {
     public static String ERROR_WEB_UNINSTALLATION_FAILED;
     public static String ERROR_WEB_PLUGIN_INSTALLATION_FAILED;
     
+    public static String ERROR_UNKNOWN;
+    
 }
index a8ceec0..d643508 100644 (file)
@@ -13,14 +13,16 @@ ERROR_SIGNATURE_INVALID=Check author certificates in Preferences > Tizen SDK > S
 ERROR_SIGNATURE_VERIFICATION_FAILED=Check whether the package is modified illegally.
 ERROR_ROOT_CERTIFICATE_NOT_FOUND=Insert root certificate into device or emulator.
 ERROR_CERTIFICATE_INVALID=Check author certificates in Preferences > Tizen SDK > Secure Profiles > Profile items.
-ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED=Check author certificates in Preferences > Tizen SDK > Secure Profiles > Profile items.
+ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED=Check whether your device`s date and time is current. If the time is wrong, certificate expiration will be happened.\n\
+ Check author certificates in Preferences > Tizen SDK > Secure Profiles > Profile items.
 ERROR_CERTIFICATE_EXPIRED=Check the system time in device or emulator.
 ERROR_INVALID_PRIVILEGE=Check privilege strings in manifest editor > Privileges > Privileges.
+ERROR_PRIVILEGE_LEVEL_VIOLATION=Refer to Help contents > Getting Started with Tizen > Overview > Privilege.
 ERROR_MENU_ICON_NOT_FOUND=Select a menu icon in manifest editor > Basic tab > Icon > MainMenu.
 ERROR_FATAL_ERROR=Installation or uninstallation is not working temporarily.
 ERROR_OUT_OF_STORAGE=Guarantee storage for installation in device or emulator.
 ERROR_OUT_OF_MEMORY=Restart device or emulator.
-ERROR_UNKNOWN=\nUnknown error\n\nSee the error log for more details.
+ERROR_ARGUMENT_INVALID=Check the parameters of pkgcmd command.
 
 # web app error messages
 ERROR_WEB_PACKAGE_ALREADY_INSTALLED=If you want to reinstall, please uninstall the application in target.
@@ -30,4 +32,6 @@ ERROR_WEB_ENCRYPTION_FAILED=Check the encryption option.
 ERROR_WEB_INSTALL_OSP_SERVICE=Check the service application in Project Explorer.
 ERROR_WEB_NOT_DEVELOPER_MODE=You don't have permission to access.
 ERROR_WEB_UNINSTALLATION_FAILED=Check the application's ID what you want to uninstall.
-ERROR_WEB_PLUGIN_INSTALLATION_FAILED=Web runtime initialization is failed(plugins installation).
\ No newline at end of file
+ERROR_WEB_PLUGIN_INSTALLATION_FAILED=Web runtime initialization is failed(plugins installation).
+
+ERROR_UNKNOWN=\nUnknown error\n\nSee the error log for more details.
index 1989c03..9b9eeea 100644 (file)
@@ -99,13 +99,13 @@ public class PkgcmdErrorType implements CommandErrorType {
     
     private String parseErrorMessage( ) {
         int startIdx = commandOutput.indexOf(ERROR_MESSAGE_TEMPLATE);
-        int endIdx = commandOutput.indexOf("\n", startIdx);
+        int endIdx = commandOutput.indexOf(System.getProperty("line.separator"), startIdx);
         
         if ( startIdx == -1 || endIdx == -1) {
             return "";
         }
         else {
-            return commandOutput.substring(startIdx, endIdx);
+            return commandOutput.substring(startIdx + ERROR_MESSAGE_TEMPLATE.length(), endIdx);
         }
     }
     
@@ -127,10 +127,12 @@ public class PkgcmdErrorType implements CommandErrorType {
         CERTIFICATE_CHAIN_VERIFICATION_FAILED(33, PkgcmdErrorMessages.ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED),
         CERTIFICATE_EXPIRED(34, PkgcmdErrorMessages.ERROR_CERTIFICATE_EXPIRED),
         INVALID_PRIVILEGE(41, PkgcmdErrorMessages.ERROR_INVALID_PRIVILEGE),
+        PRIVILEGE_LEVEL_VIOLATION(42, PkgcmdErrorMessages.ERROR_PRIVILEGE_LEVEL_VIOLATION),
         MENU_ICON_NOT_FOUND(51, PkgcmdErrorMessages.ERROR_MENU_ICON_NOT_FOUND),
         FATAL_ERROR(61, PkgcmdErrorMessages.ERROR_FATAL_ERROR),
         OUT_OF_STORAGE(62, PkgcmdErrorMessages.ERROR_OUT_OF_STORAGE),
         OUT_OF_MEMORY(63, PkgcmdErrorMessages.ERROR_OUT_OF_MEMORY),
+        ARGUMENT_INVALID(64, PkgcmdErrorMessages.ERROR_ARGUMENT_INVALID),
         
         //web app error messages.
         WEB_PACKAGE_ALREADY_INSTALLED(121, PkgcmdErrorMessages.ERROR_WEB_PACKAGE_ALREADY_INSTALLED),
index c385b00..2a69627 100644 (file)
@@ -23,7 +23,7 @@ public class CommandOutputReceiver extends MultiLineReceiver {
                 console.println(line);
             }
             commandOutput.append(line);
-            commandOutput.append(File.separatorChar);
+            commandOutput.append(System.getProperty("line.separator"));
         }
         endLine = lines[lines.length - 1];
     }
index 675ec07..fdcba01 100644 (file)
@@ -36,7 +36,7 @@ public class PkgCmdReceiver extends CommandOutputReceiver {
             }
             
             commandOutput.append(line);
-            commandOutput.append(File.separatorChar);
+            commandOutput.append(System.getProperty("line.separator"));
         }
         endLine = lines[lines.length - 1];
     }