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;
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;
}
}
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;
}
}