[Title] modify location event
authorjihye1128.kim <jihye1128.kim@samsung.com>
Fri, 17 Feb 2012 03:20:13 +0000 (12:20 +0900)
committerjihye1128.kim <jihye1128.kim@samsung.com>
Fri, 17 Feb 2012 03:21:01 +0000 (12:21 +0900)
[Type] Enhancement
[Module] event injector(emulator)
[Priority] major
[Jira#]
[Redmine#]
[Problem] NMEA mode -> Log mode or Manula mode
[Cause]
[Solution]
[TestCase]

Change-Id: If4cc917500b4d7d79fb728e3f464fb750fdc40c7

org.tizen.location.core/src/org/tizen/location/core/injector/LocationInjector.java

index 6fad345..189b35b 100644 (file)
@@ -27,9 +27,7 @@
 
 package org.tizen.location.core.injector;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
 import java.io.IOException;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -39,110 +37,118 @@ import org.tizen.common.connection.ConnectionPlugin;
 import org.tizen.common.connection.ConnectionPlugin.ISelectionListener;
 import org.tizen.common.model.ITableVO;
 import org.tizen.sdblib.FileListingService.FileEntry;
-import org.tizen.injector.socket.LocationSocket;
-import org.tizen.injector.socket.TelephonySocket;
+import org.tizen.sdblib.IDevice;
+import org.tizen.sdblib.SyncService;
+import org.tizen.sdblib.SyncService.SyncResult;
 //import org.tizen.location.core.injector.DebugLog;
 import org.tizen.location.core.model.GeoLocationVO;
-import org.tizen.location.core.protocol.AbstractNMEA0183;
 import org.tizen.location.core.protocol.GeoLocation;
-import org.tizen.location.core.protocol.NMEA0183_GPRMC;
 
 public class LocationInjector implements ISelectionListener {
        private IProgressMonitor monitor;
-       
+
+       private final String remoteFilePath = "/opt/data/gps-manager/replay/nmea_replay.log";
+       private final String setStopMode        = "vconftool set -t int db/location/replay/ReplayMode 0"; // STOP MODE
+       private final String setLogMode         = "vconftool set -t int db/location/replay/ReplayMode 1"; // NMEA MODE(LOG MODE)
+       private final String setManualMode      = "vconftool set -t int db/location/replay/ReplayMode 2"; // MANUAL MODE
+
        public LocationInjector() {
                ConnectionPlugin.getDefault().addSelectionListener(this);
 //             TargetConnectionControl.addTargetConnectionListener(this);
        }
 
+       private void setStopMode() throws IOException {
+               IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice();
+               currentDevice.executeShellCommand(setStopMode);
+       }
+
+       private void setLogMode() throws IOException {
+               IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice();
+               currentDevice.executeShellCommand(setLogMode);
+       }
+       
+       private void setManualMode() throws IOException {
+               IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice();
+               currentDevice.executeShellCommand(setManualMode);
+       }
+
+       private boolean injectLocation(double latitude, double longitude) throws IOException {
+               IDevice currentDevice = ConnectionPlugin.getDefault().getCurrentDevice();
+               String latitudeCmd  = String.format("vconftool set -t double db/location/replay/ManualLatitude %f", latitude);
+               String longitudeCmd = String.format("vconftool set -t double db/location/replay/ManualLongitude %f", longitude);
+
+               currentDevice.executeShellCommand(latitudeCmd);
+               currentDevice.executeShellCommand(longitudeCmd);
+
+               return true;
+       }
+
        public boolean inject(final File filename, IProgressMonitor monitor) throws IOException {
                if (monitor == null) {
                        monitor = new NullProgressMonitor();
                }
-               
+
                setMonitor(monitor);
 
-               BufferedReader br;
+               // PUSH FILE TO EMULATOR
+               SyncService sync = ConnectionPlugin.getDefault().getCurrentDevice().getSyncService();
+               if (sync != null) {
+                       SyncResult result = sync.pushFile(filename.getPath(), remoteFilePath, SyncService.getNullProgressMonitor());
+                   if (result.getCode() != SyncService.RESULT_OK) {
+                       // TODO
+                       return false;
+                   }
+               }
+
+               // SET LOG MODE
+               setLogMode();
 
                while(true) {
-                       br = new BufferedReader(new FileReader(filename));
-       
-                       String line = "";
-                       while (line != null) {
-                               line = br.readLine();
-                               if (line == null) {
-                                       break;
-                               }
-                               
-                               if (!line.startsWith("$GPRMC")) {
-                                       continue;
-                               }
-       
-//                             DebugLog.log("[Injector] File: " + line);
-                               
+                       synchronized (monitor) {
                                try {
-                               //      LocationSocket.getInstance().send(line.concat("\n"));
-                                       boolean res = TelephonySocket.getInstance().sendLocation(line.concat("\n"));
-                                       if(res == false)
-                                               return res;
-                               } catch (Exception e) {
-                                       // TODO Auto-generated catch block
+                                       monitor.wait(1000);
+                               } catch (InterruptedException e) {
                                        e.printStackTrace();
                                }
+                       }
 
-                               synchronized (monitor) {
-                                       try {
-                                               monitor.wait(1000);
-                                       } catch (InterruptedException e) {
-                                               // TODO Auto-generated catch block
-                                               e.printStackTrace();
-                                       }
-                               }
-
-                               if (monitor.isCanceled()) {
-//                                     DebugLog.log("[Injector] Canceled");
-                                       br.close();
-                                       
-                                       return true;
-                               }
+                       if (monitor.isCanceled()) {
+//                             DebugLog.log("[Injector] Canceled");
+                               // SET STOP MODE
+                               setStopMode();
+                               return true;
                        }
                }
        }
-       
+
        public void inject(GeoLocation location, IProgressMonitor monitor) throws IOException {
                if (monitor == null) {
                        monitor = new NullProgressMonitor();
                }
-               
+
                setMonitor(monitor);
-       
+
+               // SET MANUAL MODE
+               setManualMode();
+
+               if (!injectLocation(location.getLatitude(), location.getLongitude())) {
+                       monitor.setCanceled(true);
+                       return ;
+               }
+
                while(true) {
-                       AbstractNMEA0183 sentence = new NMEA0183_GPRMC(location.getLatitude(), location.getLongitude());
-                       
-//                     DebugLog.log("[Injector] NMEA: " + sentence.getSentence());
-                       
-                       try {
-                       //      LocationSocket.getInstance().send(sentence.getSentence().concat("\n"));
-                               boolean res = TelephonySocket.getInstance().sendLocation(sentence.getSentence().concat("\n"));
-                               if(res == false)
-                                       break;
-                       } catch (Exception e) {
-                               // TODO Auto-generated catch block
-                               e.printStackTrace();
-                       }
-                       
                        synchronized (monitor) {
                                try {
                                        monitor.wait(1000);
                                } catch (InterruptedException e) {
-                                       // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
 
                        if (monitor.isCanceled()) {
 //                             DebugLog.log("[Injector] Canceled");
-                               
+                               // SET STOP MODE
+                               setStopMode();
                                return;
                        }
                }
@@ -155,37 +161,29 @@ public class LocationInjector implements ISelectionListener {
                
                setMonitor(monitor);
 
+               // SET MANUAL MODE
+               setManualMode();
+
                while(true) {
                        for (int i = 0; i < locations.length; i++) {
                                GeoLocationVO location = (GeoLocationVO) locations[i];
-                               AbstractNMEA0183 sentence = new NMEA0183_GPRMC(location.getLocation().getLatitude(), location.getLocation().getLongitude());
-//                             DebugLog.log("[Injector] NMEA: " + sentence.getSentence());
-                               
-                               try {
-                               //      LocationSocket.getInstance().send(sentence.getSentence().concat("\n"));
-                                       boolean res = TelephonySocket.getInstance().sendLocation(sentence.getSentence().concat("\n"));
-                                       if(res == false)
-                                       {
-                                               monitor.setCanceled(true);
-                                               return res;
-                                       }
-                               } catch (Exception e) {
-                                       // TODO Auto-generated catch block
-                                       e.printStackTrace();
+                               if (!injectLocation(location.getLocation().getLatitude(), location.getLocation().getLongitude())) {
+                                       monitor.setCanceled(true);
+                                       return false;
                                }
-                               
+
                                synchronized (monitor) {
                                        try {
                                                monitor.wait(1000);
                                        } catch (InterruptedException e) {
-                                               // TODO Auto-generated catch block
                                                e.printStackTrace();
                                        }
                                }
-                                                       
+       
                                if (monitor.isCanceled()) {
 //                                     DebugLog.log("[Injector] Canceled");
-                               
+                                       // SET STOP MODE
+                                       setStopMode();
                                        return true;
                                }
                        }