Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need your assistance please! #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="lib" path="libs/android-support-v4.jar"/>
<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-4.3.1.jar"/>
<classpathentry kind="lib" path="/home/pix/build/adt-bundle-linux-x86_64/sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar"/>
<classpathentry kind="lib" path="libs/RootTools-2.4.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAvTWtccybClkHF1-Arw3GfMq2YoIzz37Q"></meta-data></application>

</manifest>
Binary file removed libs/GoogleAdMobAdsSdk-4.3.1.jar
Binary file not shown.
Binary file added libs/RootTools-2.4.jar
Binary file not shown.
Binary file modified libs/android-support-v4.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.** { *; }
3 changes: 2 additions & 1 deletion project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 3 additions & 13 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="a14f79584c5f029" />

<com.rc.mockgpspath.MockGPSMapView
<!-- <com.rc.mockgpspath.MockGPSMapView -->
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/adView"
android:layout_marginTop="60dp"
android:apiKey="0_pExoYBVGwE2mraZsxAF-0farEGJTolSPvq4iQ"
android:apiKey="0FxtTfyGwslkLU-6ZFy6ow7cuq9dM0ottT2feSA"
android:clickable="true"
android:enabled="true" />
<!-- android:apiKey="0_pExoYBVGwF6yJGbLYYv1Lq4LOn4s0KUOMftYQ" -->
Expand All @@ -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"
Expand All @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/com/rc/mockgpspath/MockGPSMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -36,4 +39,5 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

return super.onInterceptTouchEvent(ev);
}
*/
}
38 changes: 33 additions & 5 deletions src/com/rc/mockgpspath/MockGPSPathActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rc.mockgpspath;

import java.util.ArrayList;

import java.util.List;

import android.app.Dialog;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
});

Expand Down Expand Up @@ -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<String> pass = new ArrayList<String>();
boolean[] realpoints = new boolean[nodeOverlay.overlaylist.size()];
Expand Down
89 changes: 88 additions & 1 deletion src/com/rc/mockgpspath/MockGPSPathService.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down