Android Open Source - yousense-android-tracker Location Tracker Service






From Project

Back to project page yousense-android-tracker.

License

The source code is released under:

Energy-efficent motion and location tracker for Android. Based on Mattias's power and tracking work. I plan to release it as GPL, once I have a paper published that goes with it. Might also release i...

If you think the Android project yousense-android-tracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.linnap.locationtracker;
//w  ww . j a v  a  2s.  com
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import com.linnap.locationtracker.ExpectedState.TrackerState;
import com.linnap.locationtracker.gps.LocationFix;
import com.linnap.locationtracker.schedule.SensorScheduler;

abstract public class LocationTrackerService extends Service {

  //// Send these actions with startService()
  public static final String ACTION_START_BACKGROUND = "com.linnap.locationtracker.intent.ACTION_START_BACKGROUND";
  public static final String ACTION_STOP_BACKGROUND = "com.linnap.locationtracker.intent.ACTION_STOP_BACKGROUND";
  public static final String ACTION_LOCK_GPS = "com.linnap.locationtracker.intent.ACTION_LOCK_GPS";
  public static final String ACTION_UNLOCK_GPS = "com.linnap.locationtracker.intent.ACTION_UNLOCK_GPS";
  public static final String ACTION_MOCK_FIX = "com.linnap.locationtracker.intent.ACTION_MOCK_FIX";
  
  //// Binding API. Override this with custom EventBindings to link to the location tracker.
  abstract public EventBindings getEventBindings();
  
  //// Static API. Get static info on current state.
  public static final LocationFix getLastGoodFix() {
    return lastGoodFix;
  }
  
  //// Internals
  
  private static LocationFix lastGoodFix = null; 
  EventBindings eventBindings;
  ExpectedState expectedState;
  SensorScheduler sensorScheduler;
  
  @Override
  public void onCreate() {
    super.onCreate();
    lastGoodFix = null;
    expectedState = new ExpectedState();
    eventBindings = getEventBindings();
    sensorScheduler = new SensorScheduler(this);
  }
  
  @Override
  public void onDestroy() {
    super.onDestroy();
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    if (expectedState != null && sensorScheduler != null) {
      expectedState.intentReceived(intent.getAction());
      sensorScheduler.switchToState(expectedState.getExpectedState());
      if (expectedState.getExpectedState() == TrackerState.OFF)
        lastGoodFix = null;
      
      if (ACTION_MOCK_FIX.equals(intent.getAction())) {
        mockGpsFix(new LocationFix(intent.getExtras()));
      }
    } else {
      if (eventBindings != null) {
        eventBindings.log("LocationTrackerService restarted, with state gone!");
        Log.wtf(SensorConfig.TAG, "LocationTrackerService restarted, with state gone!");
        // TODO: check the logs for this
      }
      
    }
    
    return START_NOT_STICKY;
  }  
  
  @Override
  public IBinder onBind(Intent intent) {
    return null;  // No binding, it breaks startup logic.
  }
  
  //// Internal callbacks for locationtracker modules.
  
  public void gpsFix(LocationFix fix) {
    lastGoodFix = fix;
    eventBindings.gpsFix(fix);
  }
  
  public void mockGpsFix(LocationFix fix) {
    fix.provider = "mock";
    gpsFix(fix);
  }
  
  public void event(String tag, Object extra) {
    eventBindings.event(tag, extra);
  }
  
  public void log(String message) {
    eventBindings.log(message);
  }
  
  public void log(String message, Throwable throwable) {
    eventBindings.log(message, throwable);
  }
  
  public void startForegroundWithNotification() {
    eventBindings.startForegroundWithNotification();
  }
}




Java Source Code List

com.linnap.locationtracker.EventBindings.java
com.linnap.locationtracker.ExpectedState.java
com.linnap.locationtracker.LocationTrackerService.java
com.linnap.locationtracker.SensorConfig.java
com.linnap.locationtracker.Sets.java
com.linnap.locationtracker.StateChange.java
com.linnap.locationtracker.gps.DistanceCycledGps.java
com.linnap.locationtracker.gps.GpsHistory.java
com.linnap.locationtracker.gps.LocationFix.java
com.linnap.locationtracker.movement.AccelerometerData.java
com.linnap.locationtracker.movement.BooleanState.java
com.linnap.locationtracker.movement.DutyCycledAccelerometer.java
com.linnap.locationtracker.movement.SmallMovement.java
com.linnap.locationtracker.movement.StatsAccumulator.java
com.linnap.locationtracker.schedule.SensorScheduler.java
com.linnap.locationtracker.wifi.ScanResultsData.java
com.linnap.locationtracker.wifi.ScanStartedData.java
com.linnap.locationtracker.wifi.TimeoutScan.java
com.linnap.locationtracker.wifi.WifiFingerprint.java
com.linnap.locationtracker.wifi.WifiPlaceChange.java