[Title]modified for delete socket exception
authorsungmin ha <sungmin82.ha@samsung.com>
Fri, 6 Apr 2012 08:34:43 +0000 (17:34 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Fri, 6 Apr 2012 08:34:43 +0000 (17:34 +0900)
[Type]Bugfix
[Module]eventinjector
[Priority]Major
[Jira#] // Jira Issue Number
[Redmine#]  // Redmine Isuue Number
[Problem]  // Problem Description
[Cause]  // Cause Description
[Solution] // Solution Description
[TestCase]  // Executed the test-target (How to)

org.tizen.injector/src/org/tizen/injector/socket/TelephonySocket.java

index 08fba2e..a5b48f9 100644 (file)
@@ -112,6 +112,8 @@ public class TelephonySocket {
 
                        sendInitialize();
                        isConnected = true;
+               } catch (SocketException e) {
+                       return;
                } catch (Exception e) {
                        e.printStackTrace();
                        throw e;
@@ -135,12 +137,16 @@ public class TelephonySocket {
                        if (input != null)
                                input.close();                  
                        isConnected = false;
+               } catch (SocketException e) {
+                       return;
                } catch (Exception e) {
                        e.printStackTrace();
                } finally {
                        if (socket != null) {
                                try {
                                        socket.close();
+                               } catch (SocketException e) {
+                                       return;
                                } catch (IOException e) {
                                        e.printStackTrace();
                                }
@@ -155,58 +161,81 @@ public class TelephonySocket {
        }
 
        private void sendInitialize() throws IOException {
-               String str = "telephony\n";
-               output.write(str.getBytes(), 0, str.length());
-               output.flush();
-               
-               byte[] abuf = { 0x04, 0x00, 0x40, 0x41 };
-               output.write(abuf);
-               output.flush();
-
-               byte[] bbuf = { 0x16, 0x00, 0x00, 0x00 };
-               output.write(bbuf);
-               output.flush();
-               
-               output.write(str.getBytes(), 0, str.length());
-               output.flush();
-               
-               byte[] cbuf = { 0x00, 0x00, 0x40, 0x47 };
-               output.write(cbuf);
-               output.flush();
-
-               byte[] dbuf = { 0x00, 0x00, 0x40, 0x42 };
-               output.write(dbuf);
-               output.flush();
+               try {
+                       String str = "telephony\n";
+                       output.write(str.getBytes(), 0, str.length());
+                       output.flush();
+                       
+                       byte[] abuf = { 0x04, 0x00, 0x40, 0x41 };
+                       output.write(abuf);
+                       output.flush();
+       
+                       byte[] bbuf = { 0x16, 0x00, 0x00, 0x00 };
+                       output.write(bbuf);
+                       output.flush();
+                       
+                       output.write(str.getBytes(), 0, str.length());
+                       output.flush();
+                       
+                       byte[] cbuf = { 0x00, 0x00, 0x40, 0x47 };
+                       output.write(cbuf);
+                       output.flush();
+       
+                       byte[] dbuf = { 0x00, 0x00, 0x40, 0x42 };
+                       output.write(dbuf);
+                       output.flush();
+               } catch (SocketException e) {
+                       return;
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
        }
 
        public void sendAskData() throws Exception {
                if (!isConnected())
                        connect();
-
-               String str = "telephony\n";
-               output.write(str.getBytes(), 0, str.length());
-               output.flush();
-               
-               byte[] buf = { 0x00, 0x00, 0x11, 0x5b };
-               output.write(buf);
-               output.flush();
+               try {
+                       String str = "telephony\n";
+                       output.write(str.getBytes(), 0, str.length());
+                       output.flush();
+                       
+                       byte[] buf = { 0x00, 0x00, 0x11, 0x5b };
+                       output.write(buf);
+                       output.flush();
+               } catch (SocketException e) {
+                       disconnect();
+                       return;
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       disconnect();
+                       throw e;
+               }
        }
 
        public void sendDispose() throws Exception {
                if (!isConnected())
                        return;
 
-               String str = "telephony\n";
-               output.write(str.getBytes(), 0, str.length());
-               output.flush();
-               
-               byte[] abuf = { 0x00, 0x00, 0x10, 0x01 };
-               output.write(abuf);
-               output.flush();
-
-               byte[] bbuf = { 0x00, 0x00, 0x10, 0x02 };
-               output.write(bbuf);
-               output.flush();
+               try{
+                       String str = "telephony\n";
+                       output.write(str.getBytes(), 0, str.length());
+                       output.flush();
+                       
+                       byte[] abuf = { 0x00, 0x00, 0x10, 0x01 };
+                       output.write(abuf);
+                       output.flush();
+       
+                       byte[] bbuf = { 0x00, 0x00, 0x10, 0x02 };
+                       output.write(bbuf);
+                       output.flush();
+               } catch (SocketException e) {
+                       disconnect();
+                       return;
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       disconnect();
+                       throw e;
+               }
        }
 
        public boolean send(AbstractGA sendObj) throws Exception {
@@ -231,6 +260,9 @@ public class TelephonySocket {
                        }
                        output.flush();
                        result = true;
+               } catch (SocketException e) {
+                       disconnect();
+                       return false;
                } catch (Exception e) {
                        e.printStackTrace();
                        disconnect();
@@ -260,11 +292,13 @@ public class TelephonySocket {
                        
                        byte[] main = sensorMsg.getBytes();
                        if (main.length > 0) {
-//                             ByteUtil.printHex(main, "send body");
                                output.write(main, 0, main.length);
                        }
                        output.flush();
                        result = true;
+               } catch (SocketException e) {
+                       disconnect();
+                       return false;
                } catch (Exception e) {
                        e.printStackTrace();
                        disconnect();
@@ -289,11 +323,13 @@ public class TelephonySocket {
                        
                        byte[] main = locationMsg.getBytes();
                        if (main.length > 0) {
-//                             ByteUtil.printHex(main, "send body");
                                output.write(main, 0, main.length);
                        }
                        output.flush();
                        result = true;
+               } catch (SocketException e) {
+                       disconnect();
+                       return false;
                } catch (Exception e) {
                        e.printStackTrace();
                        disconnect();
@@ -328,6 +364,9 @@ public class TelephonySocket {
                        }
                        output.flush();
                        result = true;
+               } catch (SocketException e) {
+                       disconnect();
+                       return false;
                } catch (Exception e) {
                        e.printStackTrace();
                        disconnect();