diff --git a/.classpath b/.classpath index 10dc009..3e5d40f 100644 --- a/.classpath +++ b/.classpath @@ -5,6 +5,7 @@ - + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8000cd6 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5cba32f..67ab953 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -39,6 +39,6 @@ - + \ No newline at end of file diff --git a/libs/GoogleAdMobAdsSdk-4.3.1.jar b/libs/GoogleAdMobAdsSdk-4.3.1.jar deleted file mode 100644 index f95e90e..0000000 Binary files a/libs/GoogleAdMobAdsSdk-4.3.1.jar and /dev/null differ diff --git a/libs/RootTools-2.4.jar b/libs/RootTools-2.4.jar new file mode 100644 index 0000000..4541f7a Binary files /dev/null and b/libs/RootTools-2.4.jar differ diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar index 99e063b..6080877 100644 Binary files a/libs/android-support-v4.jar and b/libs/android-support-v4.jar differ diff --git a/proguard.cfg b/proguard.cfg index 4f49987..24c44b8 100644 --- a/proguard.cfg +++ b/proguard.cfg @@ -41,6 +41,10 @@ public static final android.os.Parcelable$Creator *; } +-keep class * extends java.util.ListResourceBundle { + protected Object[][] getContents(); +} + -dontwarn **CompatHoneycomb -dontwarn android.support.v4.** -keep class android.support.v4.** { *; } diff --git a/project.properties b/project.properties index a24efac..5b53de3 100644 --- a/project.properties +++ b/project.properties @@ -9,4 +9,5 @@ proguard.config=proguard.cfg # Project target. -target=Google Inc.:Google APIs:14 +target=Google Inc.:Google APIs:17 +android.library.reference.1=../adt-bundle-linux-x86_64/sdk/extras/google/google_play_services/libproject/google-play-services_lib diff --git a/res/layout/main.xml b/res/layout/main.xml index 4f04f4d..bb2d924 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -4,21 +4,13 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" > - - - + @@ -27,7 +19,6 @@ android:id="@+id/searchtext" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_above="@+id/adView" android:layout_marginBottom="8dp" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" @@ -41,7 +32,6 @@ android:id="@+id/search" android:layout_width="48dp" android:layout_height="48dp" - android:layout_above="@+id/adView" android:layout_alignParentRight="true" android:layout_marginBottom="8dp" android:layout_marginRight="8dp" diff --git a/src/com/rc/mockgpspath/MockGPSMapView.java b/src/com/rc/mockgpspath/MockGPSMapView.java index b6b4489..d0bce1c 100644 --- a/src/com/rc/mockgpspath/MockGPSMapView.java +++ b/src/com/rc/mockgpspath/MockGPSMapView.java @@ -18,8 +18,11 @@ public class MockGPSMapView extends MapView { public MockGPSMapView(Context context, AttributeSet attrs) { super(context, attrs); + this.setBuiltInZoomControls(true); + //this.setReticleDrawMode(MapView.ReticleDrawMode.DRAW_RETICLE_OVER); } + /* @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { @@ -36,4 +39,5 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev); } + */ } \ No newline at end of file diff --git a/src/com/rc/mockgpspath/MockGPSPathActivity.java b/src/com/rc/mockgpspath/MockGPSPathActivity.java index 1431a03..b773279 100644 --- a/src/com/rc/mockgpspath/MockGPSPathActivity.java +++ b/src/com/rc/mockgpspath/MockGPSPathActivity.java @@ -1,6 +1,7 @@ package com.rc.mockgpspath; import java.util.ArrayList; + import java.util.List; import android.app.Dialog; @@ -27,8 +28,8 @@ import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; -import com.google.ads.AdRequest; -import com.google.ads.AdView; +//import com.google.ads.AdRequest; +//import com.google.ads.AdView; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; @@ -40,6 +41,8 @@ import com.rc.mockgpspath.quickaction.QuickAction; import com.rc.mockgpspath.quickaction.QuickAction.OnActionItemClickListener; +import com.stericson.RootTools.RootTools; + /** * Main activity. Handles all UI operations. Contains the main map view which is * used by the user to add points, and track the progress of the route. @@ -58,6 +61,8 @@ public class MockGPSPathActivity extends MapActivity { final static int MODE_ADDING = 1; final static int MODE_PLAYING = 2; + boolean canUpdateMock = false; + MapView mapView; NodeOverlay nodeOverlay; ImageView trash, play, stop; @@ -77,7 +82,10 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapview); - mapView.getController().setZoom(2); + + mapView.setBuiltInZoomControls(true); + + //mapView.getController().setZoom(2); DraggableLayout draggableLayout = (DraggableLayout) findViewById(R.id.topbar); mappin = findViewById(R.id.mappin); @@ -109,6 +117,16 @@ public void onCreate(Bundle savedInstanceState) { trash.setOnClickListener(trashClickListener); play.setOnClickListener(playClickListener); stop.setOnClickListener(stopClickListener); + + RootTools.debugMode = true; + + if(RootTools.isAccessGiven()) { + RootTools.log("got access"); + canUpdateMock = true; + } else { + RootTools.log("no access"); + } + if (MockGPSPathService.instance != null && MockGPSPathService.instance.currentThread != null) { // If the service is running, then we already have a path and are @@ -138,17 +156,23 @@ public void onCreate(Bundle savedInstanceState) { } } + /* mapView.getController().setZoom(zoomLevel); if (centerPoint != null) mapView.getController().setCenter(centerPoint); + */ + /* AdView adView = (AdView) findViewById(R.id.adView); adView.setVisibility(View.VISIBLE); AdRequest adRequest = new AdRequest(); adView.loadAd(adRequest); + */ View search = findViewById(R.id.search); search.setOnClickListener(searchClickListener); + + } @Override @@ -244,10 +268,13 @@ public void runningMode() { protected void onResume() { super.onResume(); myLocationOverlay.enableMyLocation(); + checkIfMockEnabled(); } private void checkIfMockEnabled() { + if (canUpdateMock) return; + try { int mock_location = Settings.Secure.getInt(getContentResolver(), "mock_location"); if (mock_location == 0) { @@ -515,7 +542,7 @@ public void onItemClick(QuickAction source, int pos, int actionId) { } double MperSec = progress * 1000.0 / 3600.0; - startMockPaths(MperSec, randomizespeed.isChecked()); + startMockPaths(MperSec, randomizespeed.isChecked(), canUpdateMock); } }); @@ -558,12 +585,13 @@ public void onClick(View v) { * @param randomizespeed * Whether or not to use a random speed. */ - void startMockPaths(double MperSec, boolean randomizespeed) { + void startMockPaths(double MperSec, boolean randomizespeed, boolean canUpdateMock) { Intent i = new Intent(MockGPSPathActivity.this, MockGPSPathService.class); i.putExtra("action", "com.rc.mockgpspath.start"); i.putExtra("MperSec", MperSec); i.putExtra("randomizespeed", randomizespeed); + i.putExtra("canUpdateMock", canUpdateMock); ArrayList pass = new ArrayList(); boolean[] realpoints = new boolean[nodeOverlay.overlaylist.size()]; diff --git a/src/com/rc/mockgpspath/MockGPSPathService.java b/src/com/rc/mockgpspath/MockGPSPathService.java index a3e3670..9e474c1 100644 --- a/src/com/rc/mockgpspath/MockGPSPathService.java +++ b/src/com/rc/mockgpspath/MockGPSPathService.java @@ -1,13 +1,21 @@ package com.rc.mockgpspath; import java.util.ArrayList; +import java.lang.String; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.stericson.RootTools.CommandCapture; +import com.stericson.RootTools.RootTools; import android.app.Notification; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; +import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; +import android.provider.Settings; import android.os.IBinder; import android.util.Log; @@ -62,6 +70,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { currentThread.realpoints = intent.getBooleanArrayExtra("realpoints"); currentThread.MperSec = intent.getDoubleExtra("MperSec", 500); currentThread.randomizespeed = intent.getBooleanExtra("randomizespeed", false); + currentThread.canUpdateMock = intent.getBooleanExtra("canUpdateMock", false); currentThread.start(); } @@ -109,22 +118,82 @@ class UpdateGPSThread extends Thread { public double MperSec; public boolean randomizespeed; + public boolean canUpdateMock; + private double curLat, curLong; private long startTime; private float curBearing; private double lastMetersTravelled = 0; + private String quote(String s) { + return "\""+s.replace("\\","\\\\").replace("\"", "\\\"")+"\""; + } + + private void restoreMock(boolean mock) { + if (canUpdateMock) { + int value = mock?1:0; + CommandCapture command = new CommandCapture(0, "su -c " + +quote("sqlite3 /data/data/com.android.providers.settings/databases/settings.db " + +quote("update secure set value="+quote(Integer.toString(value))+" where name="+quote("mock_location")+";"))); + try { + RootTools.getShell(true).add(command).waitForFinish(); + RootTools.log("su command completed"); + } catch (Exception e) { + RootTools.log(e.getStackTrace().toString()); + } + } + } + + private boolean getMockValue() { + boolean oldMock = false; + try { + oldMock = Settings.Secure.getInt(getContentResolver(), "mock_location")!=0; + } catch (Exception e) { + RootTools.log(e.getStackTrace().toString()); + } + return oldMock; + } + + private boolean enableMockAndGetOldValue() { + boolean oldMock; + oldMock = getMockValue(); + RootTools.log("old mock: "+oldMock); + restoreMock(true); + RootTools.log("double checking..."+getMockValue()); + /*while(getMockValue()!=true) { + RootTools.log("waiting for mock.."); + } + RootTools.log("got it..."); + */ + String permission = "android.permission.ACCESS_MOCK_LOCATION"; + RootTools.log("also, "+permission+" is "+(getApplicationContext().checkCallingOrSelfPermission(permission)==PackageManager.PERMISSION_GRANTED)); + + return oldMock; + } + + @Override public void run() { + boolean oldMock; + Log.i("MockGPSService", "Starting UpdateGPSThread"); createProgressNotification(); Running = true; LocationManager locationManager = (LocationManager) getSystemService("location"); - locationManager.addTestProvider("gps", false, false, false, false, false, true, true, 1, 1); + + //locationManager.addTestProvider("gps", false, false, false, false, false, true, true, 1, 1); + + // the way FreeGPS does it: + + oldMock = enableMockAndGetOldValue(); + + locationManager.addTestProvider("gps", false, true, false, false, true, false, false, 1, 1); locationManager.setTestProviderEnabled("gps", true); + restoreMock(oldMock); + startTime = System.currentTimeMillis(); distances = new double[locations.size() - 1]; for (int i = 0; i < locations.size() - 1; i++) { @@ -140,14 +209,32 @@ public void run() { loc.setLongitude(curLong); loc.setBearing(curBearing); loc.setSpeed((float) MperSec); + loc.setAccuracy(4); + + // crazy jellybean fix + try { + Location.class.getMethod("makeComplete").invoke(loc); + } catch (NoSuchMethodException e) { + ; + } catch (Exception e) { + e.printStackTrace(); + } + + oldMock = enableMockAndGetOldValue(); locationManager.setTestProviderLocation("gps", loc); + restoreMock(oldMock); + try { Thread.sleep(TIME_BETWEEN_UPDATES_MS); } catch (Exception e) { } } + + oldMock = enableMockAndGetOldValue(); locationManager.setTestProviderEnabled("gps", false); locationManager.removeTestProvider("gps"); + restoreMock(oldMock); + removeProgressNotification(); if (currentThread == this) currentThread = null;