Commit 17de1ef6 authored by Administrator's avatar Administrator

只扫描ratelapp

parent f47ded1d
......@@ -2,9 +2,11 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.virjar.ratel.virtuallocation"
minSdkVersion 18
minSdkVersion 19
targetSdkVersion 28
versionCode 20200825
versionName "v1.0.0"
......
......@@ -3,20 +3,22 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.virjar.ratel.virtuallocation">
<uses-permission
android:name="android.permission.ACCESS_MOCK_LOCATION"
tools:ignore="MockLocation"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<!-- 这个权限用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- 这个权限用于访问GPS定位 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- 获取网络状态,根据网络状态切换进行数据请求网络转换 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- 写外置存储。如果开发者使用了离线地图,并且数据写在外置存储区域,则需要申请该权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- 读取外置存储。如果开发者使用了so动态加载功能并且把so文件放在了外置存储区域,则需要申请该权限,否则不需要 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- 访问网络,进行地图相关业务数据请求,包括地图数据,路线规划,POI检索等 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 调用相机,用于实现扫描二维码,预览个性化地图编辑器生成的个性化地图样式(开发者实际开发中地图SDK不需要该权限)-->
<uses-permission android:name="android.permission.CAMERA" />
<application
android:name="top.littlerich.virtuallocation.common.AppApplication"
android:allowBackup="true"
......
......@@ -21,6 +21,7 @@ import android.widget.Toast;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
......@@ -37,7 +38,6 @@ import com.baidu.mapapi.search.geocode.GeoCoder;
import com.baidu.mapapi.search.geocode.ReverseGeoCodeOption;
import com.virjar.ratel.virtuallocation.R;
import top.littlerich.virtuallocation.base.BaseActivity;
import top.littlerich.virtuallocation.common.AppApplication;
import top.littlerich.virtuallocation.listener.AsyncLocationResultListener;
......@@ -48,7 +48,6 @@ import top.littlerich.virtuallocation.util.LocationUtil;
import top.littlerich.virtuallocation.util.PermissionUtil;
import top.littlerich.virtuallocation.view.TopBanner;
import static top.littlerich.virtuallocation.util.LocationUtil.hasAddTestProvider;
/**
* Created by xuqingfu on 2017/4/15.
......@@ -92,44 +91,45 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
// PermissionUtil.requestPermissions(this,
// new String[]{
// Manifest.permission.READ_PHONE_STATE,
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
// Manifest.permission.ACCESS_FINE_LOCATION},
// 99);
PermissionUtil.requestPermissions(this,
new String[]{
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_FINE_LOCATION},
99);
super.onCreate(savedInstanceState);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
// if (PermissionUtil.checkPermission(this, Manifest.permission.READ_PHONE_STATE)
// == PackageManager.PERMISSION_GRANTED) {
// // 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
// SDKInitializer.initialize(this);
// } else {
// Toast.makeText(this, "没有权限,无法工作", Toast.LENGTH_SHORT).show();
// }
if (PermissionUtil.checkPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(getApplicationContext());
SDKInitializer.setCoordType(CoordType.BD09LL);
} else {
Toast.makeText(this, "没有权限,无法工作", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void IniView() {
bt_Ok = (Button) findViewById(R.id.bt_Ok);
tv_location = (TextView) findViewById(R.id.tv_location);
mDrawerLayout = (DrawerLayout) findViewById(R.id.dl_left);
mTopbanner = (TopBanner) findViewById(R.id.topbanner);
mAboutAuthor = (TextView) findViewById(R.id.tv_about_me);
mCurrentLocation = (ImageView) findViewById(R.id.iv_location);
mStopMock = (ImageView) findViewById(R.id.iv_stop_location);
mPreciseLocation = (TextView) findViewById(R.id.tv_precise);
mAddProcess = (TextView) findViewById(R.id.tv_add_app);
bt_Ok = findViewById(R.id.bt_Ok);
tv_location = findViewById(R.id.tv_location);
mDrawerLayout = findViewById(R.id.dl_left);
mTopbanner = findViewById(R.id.topbanner);
mAboutAuthor = findViewById(R.id.tv_about_me);
mCurrentLocation = findViewById(R.id.iv_location);
mStopMock = findViewById(R.id.iv_stop_location);
mPreciseLocation = findViewById(R.id.tv_precise);
mAddProcess = findViewById(R.id.tv_add_app);
//加载旋转动画
mOperatingAnim = AnimationUtils.loadAnimation(this, R.anim.spinloaing);
LinearInterpolator lin = new LinearInterpolator();
mOperatingAnim.setInterpolator(lin);
// 地图初始化
mMapView = (MapView) findViewById(R.id.bmapView);
mMapView = findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
// 开启定位图层
mBaiduMap.setMyLocationEnabled(true);
......@@ -155,16 +155,16 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
mTopbanner.setTopBannerListener(new TopBanner.OnTopBannerListener() {
@Override
public void leftClick(View v) {
if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
mDrawerLayout.closeDrawer(Gravity.LEFT);
if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
mDrawerLayout.closeDrawer(Gravity.START);
} else {
mDrawerLayout.openDrawer(Gravity.LEFT);
mDrawerLayout.openDrawer(Gravity.START);
}
}
@Override
public void rightClick(View v) {
//mSearch.geocode()
}
});
mAboutAuthor.setOnClickListener(new View.OnClickListener() {
......@@ -233,8 +233,6 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
try {
if (LocationUtil.initLocation(MainActivity.this)) {
LocationUtil.initLocationManager();
} else {//未开启ADB模拟定位功能,则只能选择HOOK技术
}
} catch (Exception e) {
Toast.makeText(MainActivity.this, "虚拟定位功能未打开!", Toast.LENGTH_SHORT).show();
......@@ -359,10 +357,10 @@ public class MainActivity extends BaseActivity implements View.OnClickListener {
latitude = curLatlng.latitude;
longitude = curLatlng.longitude;
try {
if (!hasAddTestProvider) {
LocationUtil.initLocation(MainActivity.this);
LocationUtil.initLocationManager();
}
LocationUtil.initLocation(MainActivity.this);
LocationUtil.initLocationManager();
LocationUtil.setLongitudeAndLatitude(curLatlng.longitude, curLatlng.latitude);
AppApplication.mMockGps.mLatitude = curLatlng.latitude;
AppApplication.mMockGps.mLongitude = curLatlng.longitude;
......
package top.littlerich.virtuallocation.common;
import android.Manifest;
import android.app.Application;
import android.app.Service;
import android.content.pm.PackageManager;
import android.os.Vibrator;
import com.baidu.mapapi.CoordType;
......@@ -9,6 +11,7 @@ import com.baidu.mapapi.SDKInitializer;
import top.littlerich.virtuallocation.model.Gps;
import top.littlerich.virtuallocation.service.LocationService;
import top.littlerich.virtuallocation.util.PermissionUtil;
/**
* Created by xuqingfu on 2017/4/15.
......@@ -34,8 +37,15 @@ public class AppApplication extends Application {
*/
locationService = new LocationService(getApplicationContext());
mVibrator = (Vibrator) getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
SDKInitializer.initialize(getApplicationContext());
SDKInitializer.setCoordType(CoordType.BD09LL);
if (PermissionUtil.checkPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
// 在使用 SDK 各组间之前初始化 context 信息,传入 ApplicationContext
SDKInitializer.initialize(this);
SDKInitializer.setCoordType(CoordType.BD09LL);
}
}
}
\ No newline at end of file
......@@ -7,6 +7,8 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import top.littlerich.virtuallocation.model.MyAppInfo;
......@@ -36,6 +38,14 @@ public class ApkTool {
if (packageInfo.applicationInfo.loadIcon(packageManager) == null) {
continue;
}
String apkPathDir = packageInfo.applicationInfo.sourceDir;
try (ZipFile apkZip = new ZipFile(apkPathDir)) {
ZipEntry entry = apkZip.getEntry("assets/ratel_serialNo.txt");
if (entry == null) {
//normal apk
continue;
}
}
myAppInfo.setImage(packageInfo.applicationInfo.loadIcon(packageManager));
myAppInfos.add(myAppInfo);
}
......
package top.littlerich.virtuallocation.util;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;
/**
......@@ -24,102 +21,37 @@ public class LocationUtil {
private static Double mLongitude = 104.0486168861;
private static LocationManager locationManager;
private static boolean canMockPosition;
/**
* 判断在Android6.0+上是否将本程序添加到ADB模拟定位中
*/
public static boolean hasAddTestProvider = false;
private static Thread mMockThread;
/**
* 初始化模拟定位,并检测是否开启ADB模拟定位
*
* @param context
* @return
*/
public static boolean initLocation(Context context) {
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
canMockPosition = (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION, 0) != 0) || Build.VERSION.SDK_INT > 22;
Log.d(TAG, "hasAddTestProvider:" + canMockPosition);
return canMockPosition;
return false;
}
/**
* 配置LocationManger参数
*/
public static void initLocationManager() throws Exception{
if (canMockPosition && !hasAddTestProvider) {
try {
String providerStr = LocationManager.GPS_PROVIDER;
LocationProvider provider = locationManager.getProvider(providerStr);
if (provider != null) {
locationManager.addTestProvider(
provider.getName()
, provider.requiresNetwork()
, provider.requiresSatellite()
, provider.requiresCell()
, provider.hasMonetaryCost()
, provider.supportsAltitude()
, provider.supportsSpeed()
, provider.supportsBearing()
, provider.getPowerRequirement()
, provider.getAccuracy());
} else {
locationManager.addTestProvider(
providerStr
, true, true, false, false, true, true, true
, Criteria.POWER_HIGH
, Criteria.ACCURACY_FINE);
}
locationManager.setTestProviderEnabled(providerStr, true);
locationManager.requestLocationUpdates(providerStr, 0, 0, new LocationStatuListener());
locationManager.setTestProviderStatus(providerStr, LocationProvider.AVAILABLE, null, System.currentTimeMillis());
Log.i(TAG,"already open GPS!");
// 模拟位置可用
hasAddTestProvider = true;
Log.d(TAG, "hasAddTestProvider:" + hasAddTestProvider);
canMockPosition = true;
} catch (Exception e) {
canMockPosition = false;
Log.d(TAG, "初始化异常:" + e);
throw e;
}
}
public static void initLocationManager() throws Exception {
}
/**
* 开启虚拟定位线程
*/
public static void startLocaton(){
if (mMockThread == null) {
mMockThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(500);
if (!hasAddTestProvider) {
Log.d("xqf", "定位服务未打开");
continue;
}
setLocation(LocationUtil.mLatitude, LocationUtil.mLongitude);
Log.d(TAG, "setLocation240=latitude:" + mLatitude + "?longitude:" + mLongitude);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
mMockThread.start();
}
public static void startLocaton() {
}
/**
* GPS定位需要不停的刷新经纬度值
*/
private static void setLocation(double latitude, double longitude) throws Exception{
private static void setLocation(double latitude, double longitude) throws Exception {
try {
String providerStr = LocationManager.GPS_PROVIDER;
Location mockLocation = new Location(providerStr);
......@@ -134,7 +66,7 @@ public class LocationUtil {
//api 16以上的需要加上这一句才能模拟定位 , 也就是targetSdkVersion > 16
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
locationManager.setTestProviderLocation(providerStr, mockLocation);
} catch (Exception e) {
// 防止用户在软件运行过程中关闭模拟位置或选择其他应用
stopMockLocation();
......@@ -143,18 +75,12 @@ public class LocationUtil {
}
public static void stopMockLocation() {
if (hasAddTestProvider) {
try {
locationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
} catch (Exception ex) {
// 若未成功addTestProvider,或者系统模拟位置已关闭则必然会出错
}
hasAddTestProvider = false;
}
}
/**
* 设置地理经纬度值
*
* @param mLongitude
* @param mLatitude
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment