19 package org.sleuthkit.autopsy.modules.android;
 
   22 import java.sql.Connection;
 
   23 import java.sql.DriverManager;
 
   24 import java.sql.ResultSet;
 
   25 import java.sql.SQLException;
 
   26 import java.sql.Statement;
 
   27 import java.util.List;
 
   28 import java.util.logging.Level;
 
   29 import org.openide.util.NbBundle;
 
   30 import org.openide.util.NbBundle.Messages;
 
   47 class GoogleMapLocationAnalyzer {
 
   49     private static final String moduleName = AndroidModuleFactory.getModuleName();
 
   50     private static final Logger logger = Logger.getLogger(GoogleMapLocationAnalyzer.class.getName());
 
   51     private static Blackboard blackboard;
 
   53     public static void findGeoLocations(Content dataSource, FileManager fileManager,
 
   54             IngestJobContext context) {
 
   55         List<AbstractFile> absFiles;
 
   56         blackboard = Case.getCurrentCase().getServices().getBlackboard();
 
   58             absFiles = fileManager.findFiles(dataSource, 
"da_destination_history"); 
 
   59             if (absFiles.isEmpty()) {
 
   62             for (AbstractFile abstractFile : absFiles) {
 
   64                     File jFile = 
new java.io.File(Case.getCurrentCase().getTempDirectory(), abstractFile.getName());
 
   65                     ContentUtils.writeToFile(abstractFile, jFile, context::dataSourceIngestIsCancelled);
 
   66                     findGeoLocationsInDB(jFile.toString(), abstractFile);
 
   67                 } 
catch (Exception e) {
 
   68                     logger.log(Level.SEVERE, 
"Error parsing Google map locations", e); 
 
   71         } 
catch (TskCoreException e) {
 
   72             logger.log(Level.SEVERE, 
"Error finding Google map locations", e); 
 
   76     @Messages({
"GoogleMapLocationAnalyzer.indexError.message=Failed to index GPS route artifact for keyword search."})
 
   77     private static void findGeoLocationsInDB(String DatabasePath, AbstractFile f) {
 
   78         Connection connection = null;
 
   79         ResultSet resultSet = null;
 
   80         Statement statement = null;
 
   82         if (DatabasePath == null || DatabasePath.isEmpty()) {
 
   86             Class.forName(
"org.sqlite.JDBC"); 
 
   87             connection = DriverManager.getConnection(
"jdbc:sqlite:" + DatabasePath); 
 
   88             statement = connection.createStatement();
 
   89         } 
catch (ClassNotFoundException | SQLException e) {
 
   90             logger.log(Level.SEVERE, 
"Error opening database", e); 
 
   95             resultSet = statement.executeQuery(
 
   96                     "SELECT time,dest_lat,dest_lng,dest_title,dest_address,source_lat,source_lng FROM destination_history;"); 
 
   98             while (resultSet.next()) {
 
   99                 Long time = Long.valueOf(resultSet.getString(
"time")) / 1000; 
 
  100                 String dest_title = resultSet.getString(
"dest_title"); 
 
  101                 String dest_address = resultSet.getString(
"dest_address"); 
 
  103                 double dest_lat = convertGeo(resultSet.getString(
"dest_lat")); 
 
  104                 double dest_lng = convertGeo(resultSet.getString(
"dest_lng")); 
 
  105                 double source_lat = convertGeo(resultSet.getString(
"source_lat")); 
 
  106                 double source_lng = convertGeo(resultSet.getString(
"source_lng")); 
 
  123                 BlackboardArtifact bba = f.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_GPS_ROUTE);
 
  124                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName,
 
  125                         NbBundle.getMessage(GoogleMapLocationAnalyzer.class,
 
  126                                 "GoogleMapLocationAnalyzer.bbAttribute.destination")));
 
  127                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME, moduleName, time));
 
  128                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END, moduleName, dest_lat));
 
  129                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_END, moduleName, dest_lng));
 
  130                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START, moduleName, source_lat));
 
  131                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START, moduleName, source_lng));
 
  132                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_NAME, moduleName, dest_title));
 
  133                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION, moduleName, dest_address));
 
  134                 bba.addAttribute(
new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME, moduleName,
 
  135                         NbBundle.getMessage(GoogleMapLocationAnalyzer.class,
 
  136                                 "GoogleMapLocationAnalyzer.bbAttribute.googleMapsHistory")));
 
  140                     blackboard.indexArtifact(bba);
 
  141                 } 
catch (Blackboard.BlackboardException ex) {
 
  142                     logger.log(Level.SEVERE, 
"Unable to index blackboard artifact " + bba.getArtifactID(), ex); 
 
  143                     MessageNotifyUtil.Notify.error(
 
  144                             Bundle.GoogleMapLocationAnalyzer_indexError_message(), bba.getDisplayName());
 
  147         } 
catch (Exception e) {
 
  148             logger.log(Level.SEVERE, 
"Error parsing Google map locations to the Blackboard", e); 
 
  151                 if (resultSet != null) {
 
  156             } 
catch (Exception e) {
 
  157                 logger.log(Level.SEVERE, 
"Error closing the database", e); 
 
  163     private static double convertGeo(String s) {
 
  164         if (s.length() > 6) {
 
  165             return Double.valueOf(s.substring(0, s.length() - 6) + 
"." + s.substring(s.length() - 6, s.length()));
 
  167             return Double.valueOf(s);