Commit 34c772a9 authored by liuzhaoce's avatar liuzhaoce

update

parent 9e9c7ba1
......@@ -6,8 +6,8 @@ android {
applicationId "com.tencent.mm"
minSdkVersion 19
targetSdkVersion 26
versionCode 9
versionName "1.9"
versionCode 23
versionName "1.23"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
......
......@@ -89,14 +89,16 @@
</intent-filter>
</receiver>
<!--&lt;!&ndash;覆盖安装后唤醒service&ndash;&gt;-->
<!--<receiver android:name="com.virjar.g4proxy.SelfStartReceiver">-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.PACKAGE_REPLACED" />-->
<!--<data android:scheme="package" />-->
<!--</intent-filter>-->
<!--</receiver>-->
<!--覆盖安装后唤醒service-->
<!--有些机器会报错-->
<receiver android:name="com.virjar.g4proxy.SelfStartReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<service
android:name="top.wuhaojie.installerlibrary.InstallAccessibilityService"
......
......@@ -6,4 +6,8 @@ public class Constant {
public static final String sharedPreferenceFile = "config";
public static final String schedulerTAG = "SchedulerTask";
public static final String DeviceMessageUtilTAG = "DeviceMessage";
public static final String DeviceInfoHolderTAG = "DeviceInfoHolder";
}
......@@ -10,7 +10,6 @@ import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.util.Log;
......@@ -20,13 +19,11 @@ import com.virjar.g4proxy.client.G4ProxyClient;
import com.virjar.g4proxy.client.LittelProxyBootstrap;
import com.virjar.g4proxy.utils.DeviceInfoHolder;
import org.littleshoot.proxy.Launcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.atomic.AtomicBoolean;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
/**
......@@ -107,7 +104,7 @@ public class HttpProxyService extends Service {
startForeground(110, notification);// 开始前台服务
String clientKey = DeviceInfoHolder.getCachedImei(this);
String clientKey = DeviceInfoHolder.getDeviceId(this);
Log.i("weijia", "start G4Proxy front service");
......
......@@ -14,6 +14,7 @@ import com.virjar.g4proxy.service.SchedulerTaskService;
// 这里我们先依靠slave进行守护保活
public class SelfStartReceiver extends BroadcastReceiver {
//TODO: 有些自启动机器会报错
@Override
public void onReceive(Context context, Intent intent) {
......@@ -42,8 +43,12 @@ public class SelfStartReceiver extends BroadcastReceiver {
Intent launchHttpProxyService = new Intent(context, HttpProxyService.class);
launchHttpProxyService.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent mainActivity = new Intent(context, MainActivity.class);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(launchAppUpdateService);
context.startActivity(launchHttpProxyService);
context.startService(launchHttpProxyService);
context.startActivity(mainActivity);
}
}
}
......
......@@ -44,7 +44,7 @@ public class SchedulerTaskService extends Service {
public static final int reportInterval = 5;
public static final String getNewestModifiedApkUrl = "http://www.scumall.com:5597/hermes/ModifiedApp/getNewestModifiedApk?appPackageName=";
//public static final String msgReportlUrl ="http://taskcenter.beta.qunar.com/api/phone/report"
// public static final String msgReportlUrl ="http://taskcenter.beta.qunar.com/api/phone/report";
public static final String msgReportlUrl = "https://hotelcrawl.qunar.com/api/phone/report";
private long lastCheckUpdateTimestamp = 0;
......
......@@ -2,7 +2,6 @@ package com.virjar.g4proxy.utils;
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
......@@ -16,6 +15,11 @@ import android.util.Log;
import com.virjar.g4proxy.Constant;
import com.virjar.g4proxy.MainActivity;
import java.io.BufferedReader;
import java.io.FileReader;
import static com.virjar.g4proxy.Constant.DeviceInfoHolderTAG;
public class DeviceInfoHolder {
......@@ -23,6 +27,8 @@ public class DeviceInfoHolder {
private static String androidId;
private static String serialNumber;
public static void initDeviceInfo(MainActivity activity) {
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.ACCESS_FINE_LOCATION)) {
......@@ -65,7 +71,12 @@ public class DeviceInfoHolder {
imei = imeiCopy;
}
if (imei == null){
imei = DeviceMessageUtil.getMachineImei(activity);
}
androidId = Settings.System.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
serialNumber = android.os.Build.SERIAL;
save(activity);
} catch (Exception e) {
......@@ -103,6 +114,7 @@ public class DeviceInfoHolder {
edit.putString("imei", imei);
edit.putString("androidId", androidId);
edit.putString("serialNumber", serialNumber);
edit.apply();
}
......@@ -115,4 +127,48 @@ public class DeviceInfoHolder {
restoreInfo(context);
return androidId;
}
public static String getDeviceId(Context context) {
int channel = 0;
String deviceId;
String slaveInfoPath = "/sdcard/slave_info.txt";
String firstLine = null;
try {
FileReader fileReader = new FileReader(slaveInfoPath);
BufferedReader br = new BufferedReader(fileReader, 8192);
firstLine = br.readLine();
br.close();
} catch (Exception e) {
Log.e(DeviceInfoHolderTAG, "Cannot find slave_info.txt !");
e.printStackTrace();
}
if (firstLine != null) {
channel = Integer.valueOf(firstLine.split(",")[1]);
} else {
Log.e(DeviceInfoHolderTAG, "slave_info.txt can not be parsed!");
}
//0:UI 1:沙盒
switch (channel) {
case 0:
deviceId = DeviceMessageUtil.getSerialNumber();
Log.e(DeviceInfoHolderTAG, "channel: " + channel);
break;
case 1:
deviceId = DeviceMessageUtil.getSerialNumber() + "_" + getCachedAndroidId(context);
Log.e(DeviceInfoHolderTAG, "channel: " + channel);
break;
default:
deviceId = null;
Log.e(DeviceInfoHolderTAG, "channel error!");
}
if (deviceId == null){
System.exit(0);
Log.e(DeviceInfoHolderTAG, "exit for deviceId is null.");
}
return deviceId;
}
}
......@@ -17,6 +17,7 @@ import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
......@@ -30,6 +31,7 @@ import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
......@@ -43,6 +45,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static android.content.Context.ACTIVITY_SERVICE;
import static android.content.Context.TELEPHONY_SERVICE;
import static com.virjar.g4proxy.Constant.DeviceMessageUtilTAG;
/**
......@@ -53,7 +57,6 @@ public class DeviceMessageUtil {
private static String latitude = "latitude";
private static String longitude = "longitude";
private static String DeviceMsg = "DeviceMsg";
//0:UI 1:沙盒
private static int channel;
......@@ -85,25 +88,11 @@ public class DeviceMessageUtil {
JSONObject devicesMsg = new JSONObject();
Map<String, String> latAndLon = DeviceMessageUtil.getLatAndLon(context);
//对channel完成赋值
String slaveInfo = getSlaveInfo(context);
String deviceId;
switch (channel) {
case 0:
deviceId = getSerialNumber();
Log.e(DeviceMsg, "channel: " + channel);
break;
case 1:
deviceId = getSerialNumber() + "_" + getAndroidID(context);
Log.e(DeviceMsg, "channel: " + channel);
break;
default:
deviceId = null;
Log.e(DeviceMsg, "channel error!");
}
try {
devicesMsg.put("deviceId", deviceId);
devicesMsg.put("deviceId", getDeviceId(context));
devicesMsg.put("brand", android.os.Build.BRAND);
devicesMsg.put("os", Build.VERSION.RELEASE);
devicesMsg.put("mac", getNewMac());
......@@ -112,8 +101,8 @@ public class DeviceMessageUtil {
devicesMsg.put("memoryTotal", getMemoryTotal());
devicesMsg.put("memoryUsage", getMemUsage(context));
devicesMsg.put("slaveInfo", slaveInfo);
devicesMsg.put("latitude", latAndLon.get(latitude));
devicesMsg.put("longitude", latAndLon.get(longitude));
devicesMsg.put("latitude", Double.valueOf(latAndLon.get(latitude)) == 0.0 ? "": latAndLon.get(latitude));
devicesMsg.put("longitude", Double.valueOf(latAndLon.get(longitude)) == 0.0 ? "": latAndLon.get(longitude));
devicesMsg.put("osType", 2);
// devicesMsg.put("appList", getAPPList(context));
} catch (JSONException e) {
......@@ -122,6 +111,30 @@ public class DeviceMessageUtil {
return devicesMsg;
}
/**
* 获取DeviceId
*/
private static String getDeviceId(Context context){
String deviceId;
//0:UI 1:沙盒
switch (channel) {
case 0:
deviceId = getSerialNumber();
Log.e(DeviceMessageUtilTAG, "channel: " + channel);
break;
case 1:
deviceId = getSerialNumber() + "_" + getAndroidID(context);
Log.e(DeviceMessageUtilTAG, "channel: " + channel);
break;
default:
deviceId = null;
Log.e(DeviceMessageUtilTAG, "channel error!");
}
return deviceId;
}
/**
* 获取手机经纬度
......@@ -134,7 +147,7 @@ public class DeviceMessageUtil {
return latAndLon;
}
String bestProvider = locationManager.getBestProvider(getCriteria(), true);
Log.e(DeviceMsg, "bestProvider: " + bestProvider);
Log.e(DeviceMessageUtilTAG, "bestProvider: " + bestProvider);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return latAndLon;
......@@ -160,16 +173,14 @@ public class DeviceMessageUtil {
}
}
if (location == null) {
latAndLon.put(latitude, "" + Const.LATITUDE);
latAndLon.put(longitude, "" + Const.LONGITUDE);
}
if (location != null) {
Log.e(DeviceMsg, "Latitude: " + String.valueOf(location.getLatitude()));
Log.e(DeviceMsg, "Longitude: " + String.valueOf(location.getLongitude()));
latAndLon.put(latitude, String.valueOf(location.getLatitude()));
latAndLon.put(longitude, String.valueOf(location.getLongitude()));
} else {
Log.e(DeviceMsg, "location is null");
Log.e(DeviceMessageUtilTAG, "location is null");
latAndLon.put(latitude, "" + String.format(Locale.CHINA, "%.6f", Const.LATITUDE));
latAndLon.put(longitude, "" + String.format(Locale.CHINA, "%.6f", Const.LONGITUDE));
}else{
Log.e(DeviceMessageUtilTAG, "Latitude: " + String.valueOf(location.getLatitude()));
Log.e(DeviceMessageUtilTAG, "Longitude: " + String.valueOf(location.getLongitude()));
latAndLon.put(latitude, String.format(Locale.CHINA, "%.6f", location.getLatitude()));
latAndLon.put(longitude, String.format(Locale.CHINA, "%.6f", location.getLongitude()));
}
return latAndLon;
}
......@@ -301,9 +312,12 @@ public class DeviceMessageUtil {
}
}
}
double rate = -1;
double rate;
if (totalJiffies[0] > 0 && totalJiffies[1] > 0 && totalJiffies[0] != totalJiffies[1]) {
rate = 1.0 * ((totalJiffies[1] - totalIdle[1]) - (totalJiffies[0] - totalIdle[0])) / (totalJiffies[1] - totalJiffies[0]);
}else {
Log.e(DeviceMessageUtilTAG, "get getCPURateDesc failed.");
return "";
}
return String.format(Locale.CHINA, "%.2f", rate * 100);
......@@ -337,13 +351,12 @@ public class DeviceMessageUtil {
private static String getSlaveInfo(Context context) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
return null;
}
String slaveInfoPath = "/sdcard/slave_info.txt";
Log.e(DeviceMsg, "slave_info.txt path: " + slaveInfoPath);
Log.e(DeviceMessageUtilTAG, "slave_info.txt path: " + slaveInfoPath);
String firstLine = null;
try {
FileReader fileReader = new FileReader(slaveInfoPath);
......@@ -351,7 +364,7 @@ public class DeviceMessageUtil {
firstLine = br.readLine();
br.close();
} catch (Exception e) {
Log.e(DeviceMsg, "Cannot find slave_info.txt !");
Log.e(DeviceMessageUtilTAG, "Cannot find slave_info.txt !");
e.printStackTrace();
}
......@@ -360,7 +373,7 @@ public class DeviceMessageUtil {
slaveInfo = firstLine.split(",")[0];
channel = Integer.valueOf(firstLine.split(",")[1]);
} else {
Log.e(DeviceMsg, "slave_info.txt can not be parsed!");
Log.e(DeviceMessageUtilTAG, "slave_info.txt can not be parsed!");
}
return slaveInfo;
}
......@@ -381,14 +394,14 @@ public class DeviceMessageUtil {
String subMemoryLine = memoryLine.substring(memoryLine.indexOf("MemTotal:"));
br.close();
long totalMemorySize = Integer.parseInt(subMemoryLine.replaceAll("\\D+", ""));
Log.e(DeviceMsg, "totalMemorySize: " + totalMemorySize);
Log.e(DeviceMessageUtilTAG, "totalMemorySize: " + totalMemorySize);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
if (activityManager == null) {
return null;
}
activityManager.getMemoryInfo(mi);
long availableSize = mi.availMem / 1024;
Log.e(DeviceMsg, "availableSize: " + availableSize);
Log.e(DeviceMessageUtilTAG, "availableSize: " + availableSize);
int memUsage = (int) ((totalMemorySize - availableSize) / 1024);
return String.valueOf(memUsage);
} catch (Exception e) {
......@@ -402,7 +415,7 @@ public class DeviceMessageUtil {
* 获取手机序列号
*/
@SuppressLint("HardwareIds")
private static String getSerialNumber() {
static String getSerialNumber() {
return android.os.Build.SERIAL;
}
......@@ -425,11 +438,10 @@ public class DeviceMessageUtil {
return firstLine;
}
} catch (Exception e) {
Log.e(DeviceMsg, "Cannot find slave_info.txt !");
Log.e(DeviceMessageUtilTAG, "Cannot find slave_info.txt !");
e.printStackTrace();
}
// 另一种获取方式
// DeviceInfoHolder.getCachedAndroidId(context)
return Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
......@@ -452,7 +464,7 @@ public class DeviceMessageUtil {
CharSequence name = info.activityInfo.loadLabel(packageManager);
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
Log.e(DeviceMsg, name + "----" + packageName + "----" + cls + "----versionName: "
Log.e(DeviceMessageUtilTAG, name + "----" + packageName + "----" + cls + "----versionName: "
+ packageInfo.versionName + "----versionCode: " + packageInfo.versionCode);
App app = new App(String.valueOf(name), packageInfo.versionName);
appList.add(app);
......@@ -464,6 +476,22 @@ public class DeviceMessageUtil {
}
/**
* 获取IMEI
*/
public static String getMachineImei(Context context) {
TelephonyManager manager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
Class clazz = manager.getClass();
String imei = "";
try {
Method getImei=clazz.getDeclaredMethod("getImei",int.class);//(int slotId)
getImei.setAccessible(true);
imei = (String) getImei.invoke(manager);
} catch (Exception e) {
}
return imei;
}
/**
* 获取经纬度provider
*/
private static Criteria getCriteria() {
......
......@@ -107,6 +107,9 @@ public class MyLocationListener implements BDLocationListener{
Log.i("BaiduLocationApiDem", sb.toString());
//定位成功,可以将定位的数据保存下来,Const就是保存数据的类
if(location.getLongitude() == 4.9E-324){
return;
}
if(Const.LONGITUDE == 0 || Const.LONGITUDE == 4.9E-324) {
Const.LONGITUDE = location.getLongitude();
Const.LATITUDE = location.getLatitude();
......
......@@ -6,4 +6,5 @@ package com.virjar.g4proxy.utils;
public class SmsManagerUtil {
//TODO: 短信收发
}
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