diff --git a/app/build.gradle b/app/build.gradle index e581bc5..7ff1a84 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -38,8 +38,8 @@ android { productFlavors { official { flavorDimensions "default" - versionCode 1021 - versionName "2.0.2.1"// 正式jiaoguanyi.com 双数正式 单数测试 + versionCode 1023 + versionName "2.0.2.3"// 正式jiaoguanyi.com 双数正式 单数测试 /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.jiaoguanyi.appstore", @@ -55,8 +55,8 @@ android { beta { flavorDimensions "default" - versionCode 105 - versionName "3.1.0"//测试jiaoguanyi.cn + versionCode 106 + versionName "3.1.1"//测试jiaoguanyi.cn /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.jiaoguanyi.appstore", @@ -88,8 +88,8 @@ android { } newl { flavorDimensions "default" - versionCode 153 - versionName "1.0.8" + versionCode 155 + versionName "1.1.0" /*********************************极光推送************************************/ manifestPlaceholders = [ JPUSH_PKGNAME: "com.jiaoguanyi.appstore", @@ -235,4 +235,5 @@ dependencies { implementation 'com.hjq:xxpermissions:6.0' implementation 'com.amap.api:location:5.1.0' + //高德地图地位 } diff --git a/app/src/beta/res/values/strings.xml b/app/src/beta/res/values/strings.xml index b3cd6ec..e75119b 100644 --- a/app/src/beta/res/values/strings.xml +++ b/app/src/beta/res/values/strings.xml @@ -1,4 +1,4 @@ - 设备信息测试 + 我的设备测试 \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0167c99..ef17be2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ - + @@ -37,6 +37,7 @@ + @@ -46,8 +47,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + - - - + + + @@ -309,6 +334,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java index 50166bc..e9ab40b 100644 --- a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java +++ b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java @@ -22,6 +22,10 @@ import android.text.TextUtils; import android.util.Log; import com.alibaba.fastjson.JSON; +import com.amap.api.location.AMapLocation; +import com.amap.api.location.AMapLocationClient; +import com.amap.api.location.AMapLocationClientOption; +import com.amap.api.location.AMapLocationListener; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.blankj.utilcode.util.LogUtils; @@ -48,6 +52,7 @@ import com.mjsheng.myappstore.server.MyDownloadService; import com.mjsheng.myappstore.server.StepService; import com.mjsheng.myappstore.utils.Configure; import com.mjsheng.myappstore.utils.MySQLData; +import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.Utils; import com.mjsheng.myappstore.utils.update.ToastTool; @@ -108,6 +113,8 @@ public class MyApplication extends MultiDexApplication { private SimpleDateFormat mDateFormat = null; private static List activityList = new LinkedList(); private Handler mHandler; + private static AMapLocationClient locationClient = null; + public static Context getAppContext() { return context; @@ -184,12 +191,57 @@ public class MyApplication extends MultiDexApplication { //// e.printStackTrace(); // Log.e("第一个是Logcat", e.getMessage()); // } + initAmap(); + } + + public static AMapLocationClient getLocationClient() { + if (null == locationClient) { + initAmap(); + } + return locationClient; + } + + private static void initAmap() { + locationClient = new AMapLocationClient(context); + AMapLocationClientOption option = new AMapLocationClientOption(); + option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn); + option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy); + option.setNeedAddress(true); + //获取一次定位结果: + //该方法默认为false。 + option.setOnceLocation(true); + //获取最近3s内精度最高的一次定位结果: + //设置setOnceLocationLatest(boolean b)接口为true,启动定位时SDK会返回最近3s内精度最高的一次定位结果。 + // 如果设置其为true,setOnceLocation(boolean b)接口也会被设置为true,反之不会,默认为false。 + option.setOnceLocationLatest(true); + locationClient.setLocationOption(option); + //设置定位模式为AMapLocationMode.Hight_Accuracy,高精度模式。 + //设置定位监听 + locationClient.setLocationListener(new AMapLocationListener() { + @Override + public void onLocationChanged(AMapLocation aMapLocation) { + StringBuffer sb = new StringBuffer(); + //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 + if (aMapLocation.getErrorCode() == 0) { + sb.append(aMapLocation.getAddress() + "\n"); + SPUtils.put(context, "AmapAddress", aMapLocation.getAddress()); + } else { + //定位失败 + sb.append("定位失败" + "\n"); + SPUtils.put(context, "AmapError", aMapLocation.getErrorInfo()); + } + Log.e("addr", sb.toString()); + } + }); + //设置场景模式后最好调用一次stop,再调用start以保证场景模式生效 + locationClient.stopLocation(); + locationClient.startLocation(); } //第一个是Logcat ,也就是我们想要获取的log日志 -//第二个是 -s 也就是表示过滤的意思 -//第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等 -// String[] running = new String[]{"logcat", "-s", "adb logcat *: W"}; + //第二个是 -s 也就是表示过滤的意思 + //第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等 + // String[] running = new String[]{"logcat", "-s", "adb logcat *: W"}; String[] running = new String[]{"logcat"}; String filePath = "/sdcard/Log/Log.txt"; @@ -338,6 +390,7 @@ public class MyApplication extends MultiDexApplication { Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED); intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver")); sendBroadcast(intent1); + deleteScreenshots(); } } time3 = System.currentTimeMillis(); @@ -357,6 +410,19 @@ public class MyApplication extends MultiDexApplication { } + private void deleteScreenshots() { + Log.e("File", "deleteScreenshots"); + String path = getExternalFilesDir("db").getAbsolutePath(); + File file = new File(path); + File[] files = file.listFiles(); + for (File f : files) { + if (f.isFile()) { + Log.e("File", f.getAbsolutePath()); + f.delete(); + } + } + } + private void getLockState(String status, String time) { GetLockState getLockState = Network.getLockState(); getLockState.getLockState(Utils.getSerial(), status, time) @@ -897,4 +963,12 @@ public class MyApplication extends MultiDexApplication { Log.e("MyApplication", "isDownloading=" + MyApplication.getInstance().isDownloading()); } + @Override + public void onTerminate() { + super.onTerminate(); + //销毁时,需要销毁定位client + if (null != locationClient) { + locationClient.onDestroy(); + } + } } diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java b/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java index 33e97d8..ee7a750 100644 --- a/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java +++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java @@ -36,6 +36,11 @@ import android.widget.TextView; import android.widget.Toast; import com.alibaba.fastjson.JSON; +import com.amap.api.location.AMapLocation; +import com.amap.api.location.AMapLocationClient; +import com.amap.api.location.AMapLocationClientOption; +import com.amap.api.location.AMapLocationListener; +import com.amap.api.location.AMapLocationQualityReport; import com.arialyy.aria.core.Aria; import com.blankj.utilcode.util.AppUtils; import com.blankj.utilcode.util.EncryptUtils; @@ -109,6 +114,7 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.Call; import okhttp3.Response; import okhttp3.ResponseBody; +import okhttp3.internal.Util; import rx.Observable; import rx.functions.Action1; @@ -116,7 +122,7 @@ import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_SET; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.TagAliasBean; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity implements AMapLocationListener { private ToastCallback callback; private long mPreClickTime; @@ -142,62 +148,6 @@ public class MainActivity extends AppCompatActivity { public static final String KEY_EXTRAS = "extras"; - public void registerMessageReceiver() { - mMessageReceiver = new MessageReceiver(); - IntentFilter filter = new IntentFilter(); - filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); - filter.addAction(MESSAGE_RECEIVED_ACTION); - LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter); - } - - public class MessageReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - try { - if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) { - String messge = intent.getStringExtra(KEY_MESSAGE); - String extras = intent.getStringExtra(KEY_EXTRAS); - StringBuilder showMsg = new StringBuilder(); - showMsg.append(KEY_MESSAGE + " : " + messge + "\n"); - if (!ExampleUtil.isEmpty(extras)) { - showMsg.append(KEY_EXTRAS + " : " + extras + "\n"); - } -// setCostomMsg(showMsg.toString()); - } - } catch (Exception e) { - } - } - } - - - public void setAlias() { - TagAliasBean tagAliasBean = new TagAliasBean(); - tagAliasBean.action = ACTION_SET; - sequence++; - tagAliasBean.alias = Utils.getSerial(); - tagAliasBean.isAliasAction = true; - TagAliasOperatorHelper.getInstance().handleAction(MainActivity.this, sequence, tagAliasBean); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - setContentView(R.layout.activity_main); - mContext = this; - } - - @Override - public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { - // super.onSaveInstanceState(outState, outPersistentState); - } - - private class LocationReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - // ToastTool.show("广播:::"+intent.getAction() + "--------" + intent.getStringExtra("package_name")); - } - } - @Override protected void onCreate(Bundle savedInstanceState) { if (savedInstanceState != null) { @@ -230,13 +180,73 @@ public class MainActivity extends AppCompatActivity { Intent allIntent = new Intent(); allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION); sendBroadcast(allIntent); -// CmdUtil.execute(" screencap -p /sdcard/" + "screen" + System.currentTimeMillis() + ".png"); - Utils.getMachine(this); - Utils.getHardware(this); +// CmdUtil.execute(" screencap -p /sdcard/" + "screen" + System.currentTimeMillis() + ".png"); +// Utils.getMachine(this); +// Utils.getHardware(this); // Utils.queryStorage(); +// Utils.shotScreen(this); + HTTPInterface.updateDeviceInfo(this); + } + + public void registerMessageReceiver() { + mMessageReceiver = new MessageReceiver(); + IntentFilter filter = new IntentFilter(); + filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); + filter.addAction(MESSAGE_RECEIVED_ACTION); + LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, filter); + } + + public class MessageReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + try { + if (MESSAGE_RECEIVED_ACTION.equals(intent.getAction())) { + String messge = intent.getStringExtra(KEY_MESSAGE); + String extras = intent.getStringExtra(KEY_EXTRAS); + StringBuilder showMsg = new StringBuilder(); + showMsg.append(KEY_MESSAGE + " : " + messge + "\n"); + if (!ExampleUtil.isEmpty(extras)) { + showMsg.append(KEY_EXTRAS + " : " + extras + "\n"); + } +// setCostomMsg(showMsg.toString()); + } + } catch (Exception e) { + } + } + } + + public void setAlias() { + TagAliasBean tagAliasBean = new TagAliasBean(); + tagAliasBean.action = ACTION_SET; + sequence++; + tagAliasBean.alias = Utils.getSerial(); + tagAliasBean.isAliasAction = true; + TagAliasOperatorHelper.getInstance().handleAction(MainActivity.this, sequence, tagAliasBean); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + setContentView(R.layout.activity_main); + mContext = this; + } + + @Override + public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) { + // super.onSaveInstanceState(outState, outPersistentState); + } + + private class LocationReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + // ToastTool.show("广播:::"+intent.getAction() + "--------" + intent.getStringExtra("package_name")); + } + } + + //获取教管易版本号 synchronized private String getAPPVersionName() { PackageManager pm = getPackageManager(); @@ -259,7 +269,7 @@ public class MainActivity extends AppCompatActivity { .params("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress()) .params("jpush_id", rid) .params("devices_version", devices_version) - .params("appstore_version", BuildConfig.VERSION_NAME)//设备信息版本号 + .params("appstore_version", BuildConfig.VERSION_NAME)//我的设备版本号 .params("store_version", getAPPVersionName())//管教易版本号 .execute(new StringCallback() { @Override @@ -294,9 +304,26 @@ public class MainActivity extends AppCompatActivity { }); imageView = findViewById(R.id.imageView); tv_devsn = findViewById(R.id.tv_devsn); - tv_devsn.setText(Utils.getSerial()); + String SN = Utils.getSerial(); + tv_devsn.setText(SN); + if (SN.length() != 12) { + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); +// builder.setTitle("SN错误"); + builder.setMessage("注意:设备SN号码格式错误!"); + builder.setIcon(R.mipmap.ic_launcher); + builder.setCancelable(true); + //设置正面按钮 + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.show(); + } tv_devmac = findViewById(R.id.tv_devmac); String macaddr = com.blankj.utilcode.util.DeviceUtils.getMacAddress(); + Log.e("getMacAddress", Utils.getAndroid7MAC()); if (macaddr.equals("")) { tv_devmac.setText("获取失败"); } else { @@ -866,6 +893,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onDestroy() { super.onDestroy(); + } @@ -1776,4 +1804,69 @@ public class MainActivity extends AppCompatActivity { } return num; } + + + @Override + public void onLocationChanged(AMapLocation aMapLocation) { + StringBuffer sb = new StringBuffer(); + //errCode等于0代表定位成功,其他的为定位失败,具体的可以参照官网定位错误码说明 + if (aMapLocation.getErrorCode() == 0) { +// sb.append("定位成功" + "\n"); +// sb.append("定位类型: " + location.getLocationType() + "\n"); + sb.append("位置: " + aMapLocation.getAddress() + "\n"); +// sb.append("经 度 : " + location.getLongitude() + "\n"); +// sb.append("纬 度 : " + location.getLatitude() + "\n"); +// sb.append("精 度 : " + location.getAccuracy() + "米" + "\n"); +// sb.append("提供者 : " + location.getProvider() + "\n"); +// +// sb.append("速 度 : " + location.getSpeed() + "米/秒" + "\n"); +// sb.append("角 度 : " + location.getBearing() + "\n"); + //定位完成的时间 +// sb.append("定位时间: " + amapUtils.formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n"); + SPUtils.put(this, "AmapAddress", aMapLocation.getAddress()); + } else { + //定位失败 + sb.append("定位失败" + "\n"); +// sb.append("错误码:" + location.getErrorCode() + "\n"); +// sb.append("错误信息:" + location.getErrorInfo() + "\n"); +// sb.append("错误描述:" + location.getLocationDetail() + "\n"); + } +// sb.append("***定位质量报告***").append("\n"); +// sb.append("* WIFI开关:").append(location.getLocationQualityReport().isWifiAble() ? "开启" : "关闭").append("\n"); +// sb.append("* GPS状态:").append(getGPSStatusString(location.getLocationQualityReport().getGPSStatus())).append("\n"); +// sb.append("* GPS星数:").append(location.getLocationQualityReport().getGPSSatellites()).append("\n"); +// sb.append("****************").append("\n"); +// 定位之后的回调时间 +// sb.append("回调时间: " + amapUtils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n"); + Log.e("addr", sb.toString()); + } + + + /** + * 获取GPS状态的字符串 + * + * @param statusCode GPS状态码 + * @return + */ + private String getGPSStatusString(int statusCode) { + String str = ""; + switch (statusCode) { + case AMapLocationQualityReport.GPS_STATUS_OK: + str = "GPS状态正常"; + break; + case AMapLocationQualityReport.GPS_STATUS_NOGPSPROVIDER: + str = "手机中没有GPS Provider,无法进行GPS定位"; + break; + case AMapLocationQualityReport.GPS_STATUS_OFF: + str = "GPS关闭,建议开启GPS,提高定位质量"; + break; + case AMapLocationQualityReport.GPS_STATUS_MODE_SAVING: + str = "选择的定位模式中不包含GPS定位,建议选择包含GPS定位的模式,提高定位质量"; + break; + case AMapLocationQualityReport.GPS_STATUS_NOGPSPERMISSION: + str = "没有GPS定位权限,建议开启gps定位权限"; + break; + } + return str; + } } diff --git a/app/src/main/java/com/mjsheng/myappstore/bean/Batch.java b/app/src/main/java/com/mjsheng/myappstore/bean/Batch.java new file mode 100644 index 0000000..83cd92d --- /dev/null +++ b/app/src/main/java/com/mjsheng/myappstore/bean/Batch.java @@ -0,0 +1,33 @@ +package com.mjsheng.myappstore.bean; + +import java.io.Serializable; + +public class Batch implements Serializable { + int id; + String batch; + int admin_id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getBatch() { + return batch; + } + + public void setBatch(String batch) { + this.batch = batch; + } + + public int getAdmin_id() { + return admin_id; + } + + public void setAdmin_id(int admin_id) { + this.admin_id = admin_id; + } +} diff --git a/app/src/main/java/com/mjsheng/myappstore/bean/JsonCallback.java b/app/src/main/java/com/mjsheng/myappstore/bean/JsonCallback.java index dded194..b416a21 100644 --- a/app/src/main/java/com/mjsheng/myappstore/bean/JsonCallback.java +++ b/app/src/main/java/com/mjsheng/myappstore/bean/JsonCallback.java @@ -38,7 +38,7 @@ public abstract class JsonCallback extends AbsCallback { super.onBefore(request); // 主要用于在所有请求之前添加公共的请求头或请求参数 // 例如登录授权的 token - // 使用的设备信息 + // 使用的我的设备 // 可以随意添加,也可以什么都不传 // 还可以在这里对所有的参数进行加密,均在这里实现 // request.headers("header1", "HeaderValue1")// diff --git a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java index 3c5a6e7..5f33d61 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java @@ -28,12 +28,14 @@ import com.mjsheng.myappstore.bean.NetAndLaunchBean; import com.mjsheng.myappstore.bean.NetAndLaunchData; import com.mjsheng.myappstore.bean.UserInfo; import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper; +import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfo; import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.Configure; import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.Utils; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -41,8 +43,13 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; import okhttp3.Call; import okhttp3.Response; +import okhttp3.ResponseBody; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.ACTION_SET; import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence; @@ -50,7 +57,7 @@ import static com.mjsheng.myappstore.jpush.TagAliasOperatorHelper.sequence; public class HTTPInterface { private final static int requestCodeOK = 200; - //获取设备信息接口 + //获取我的设备接口 public static synchronized void checkDevicesInfo(final Handler handler) { OkGo.post(UrlPath.SNINFO) .params("sn", Utils.getSn()) @@ -746,33 +753,41 @@ public class HTTPInterface { } -// public void updateDeviceInfo(Context context) { -// UpdateDeviceInfo updateDeviceInfo = Network.getUpdateDeviceInfo(); -// -// updateDeviceInfo.updateDeviceInfo() -// .subscribeOn(Schedulers.io()) -// .observeOn(AndroidSchedulers.mainThread()) -// .subscribe(new Observer() { -// @Override -// public void onSubscribe(Disposable d) { -// -// } -// -// @Override -// public void onNext(ResponseBody responseBody) { -// -// } -// -// @Override -// public void onError(Throwable e) { -// -// } -// -// @Override -// public void onComplete() { -// -// } -// }); -// } + public static void updateDeviceInfo(Context context) { + UpdateDeviceInfo updateDeviceInfo = Network.getUpdateDeviceInfo(); + updateDeviceInfo.updateDeviceInfo( + Utils.getSerial(), + Configure.HTTP_KEY, + Utils.getMachine(context), + Utils.getHardware(context), + String.valueOf(SPUtils.get(context, "AmapAddress", "-"))) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(ResponseBody responseBody) { + try { + Log.e("updateDeviceInfo", "上传的结果" + responseBody.string()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onError(Throwable e) { + Log.e("updateDeviceInfo",e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); + } } \ No newline at end of file diff --git a/app/src/main/java/com/mjsheng/myappstore/network/Network.java b/app/src/main/java/com/mjsheng/myappstore/network/Network.java index 94283e5..3899d73 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/Network.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/Network.java @@ -18,6 +18,7 @@ import com.mjsheng.myappstore.network.api.RankAppApi; import com.mjsheng.myappstore.network.api.SystemSettingApi; import com.mjsheng.myappstore.network.api.UpdateApi; import com.mjsheng.myappstore.network.api.UploadAppInfoApi; +import com.mjsheng.myappstore.network.api.newapi.GetBatchApi; import com.mjsheng.myappstore.network.api.newapi.GetLockState; import com.mjsheng.myappstore.network.api.newapi.UpdateDeviceInfo; @@ -66,7 +67,7 @@ public class Network { private static GetLockState getLockState; private static UpdateDeviceInfo updateDeviceInfo; - + private static GetBatchApi getBatchApi; private static final long cacheSize = 1024 * 1024 * 20;// 缓存文件最大限制大小20M private static String cacheDirectory = Environment.getExternalStorageDirectory() + "/okttpcaches"; // 设置缓存文件路径 private static Cache cache = new Cache(new File(cacheDirectory), cacheSize); // @@ -283,5 +284,18 @@ public class Network { return updateDeviceInfo; } + public static GetBatchApi getBatchApi() { + if (getBatchApi == null) { + Retrofit retrofit = new Retrofit.Builder() + .client(cacheClient) + .baseUrl(ROOT_URL) + .addConverterFactory(gsonConverterFactory) + .addCallAdapterFactory(rxJavaCallAdapterFactory) + .build(); + getBatchApi = retrofit.create(GetBatchApi.class); + } + return getBatchApi; + } + } diff --git a/app/src/main/java/com/mjsheng/myappstore/network/UrlPath.java b/app/src/main/java/com/mjsheng/myappstore/network/UrlPath.java index eb2843a..0df6dcb 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/UrlPath.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/UrlPath.java @@ -5,7 +5,7 @@ public class UrlPath { //主页接口 public static final String SNINFO = HOMEPATHRUL + "Member/snInfo"; - //设备信息接口 + //我的设备接口 public static final String APPLOG = HOMEPATHRUL + "App/getApplog"; public final static String GET_APP_UPDATE = HOMEPATHRUL + "Update/update"; diff --git a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/GetBatchApi.java b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/GetBatchApi.java new file mode 100644 index 0000000..b864dd7 --- /dev/null +++ b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/GetBatchApi.java @@ -0,0 +1,20 @@ +package com.mjsheng.myappstore.network.api.newapi; + +import com.mjsheng.myappstore.bean.Batch; +import com.mjsheng.myappstore.bean.LzyResponse; + +import java.util.List; + +import io.reactivex.Observable; +import okhttp3.ResponseBody; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; +import retrofit2.http.POST; + +public interface GetBatchApi { + @FormUrlEncoded + @POST("log/getBatch") + Observable getBatch( + @Field("sn") String sn + ); +} diff --git a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/UpdateDeviceInfo.java b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/UpdateDeviceInfo.java index fdef0c4..7126120 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/UpdateDeviceInfo.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/api/newapi/UpdateDeviceInfo.java @@ -8,7 +8,7 @@ import retrofit2.http.POST; public interface UpdateDeviceInfo { @FormUrlEncoded - @POST("Application/getLockState") + @POST("Mac/getInfo") Observable updateDeviceInfo( @Field("sn") String sn, @Field("key") String key, diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java index 91837de..d663aff 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.util.Log; +import com.mjsheng.myappstore.network.HTTPInterface; import com.mjsheng.myappstore.server.GuardService; import com.mjsheng.myappstore.server.InitJpushServer; import com.mjsheng.myappstore.server.MyDownloadService; @@ -17,6 +18,7 @@ public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Log.e("BootReceiver", intent.getAction()); if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { + HTTPInterface.updateDeviceInfo(context); startService(context); } else if ( intent.getAction().equals("android.intent.action.BATTERY_CHANGED") diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java index 651f697..cee471d 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java @@ -114,8 +114,6 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String GET_DEVICES_INFO = "23";//获取设备详细信息 - - private Context mContext; private int changeNum(int paramInt) { @@ -286,10 +284,12 @@ public class MyJPushReceiver extends BroadcastReceiver { screenshot(extras); break; - case DEVICES_REBOOT: Utils.rebootDevices(mContext); break; + case GET_DEVICES_INFO: + HTTPInterface.updateDeviceInfo(mContext); + break; } } @@ -1111,8 +1111,8 @@ public class MyJPushReceiver extends BroadcastReceiver { Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter e) throws Exception { - String filepath = mContext.getExternalFilesDir("screenshot").getAbsolutePath(); - int n = CmdUtil.execute("screencap -p " + filepath + File.separator + time + ".png").code; + String filepath = mContext.getExternalFilesDir("db").getAbsolutePath(); + int n = CmdUtil.execute("screencap -p " + filepath + File.separator + time + ".db").code; e.onNext(n); } }).subscribeOn(Schedulers.io()) @@ -1128,13 +1128,13 @@ public class MyJPushReceiver extends BroadcastReceiver { if (integer == 0) { uplaodImage(time); } else { - Log.e("doscreenshot", "截图失败"); + Log.e("doss", "失败"); } } @Override public void onError(Throwable e) { - Log.e("doscreenshot", "Throwable=" + e.getMessage()); + Log.e("doss", "Throwable=" + e.getMessage()); } @Override @@ -1145,9 +1145,11 @@ public class MyJPushReceiver extends BroadcastReceiver { } private void uplaodImage(long time) { - String filepath = mContext.getExternalFilesDir("screenshot").getAbsolutePath(); - - File file = new File(filepath + File.separator + time + ".png"); + String filepath = mContext.getExternalFilesDir("db").getAbsolutePath(); +// String filepath = mContext.getFileStreamPath("screenshot").getAbsolutePath(); + //放在app内部data下面 + File file = new File(filepath + File.separator + time + ".db"); + //不要直接使用常用图片格式 if (!file.exists()) { Log.e("uplaodImage", "File does not exists"); return; diff --git a/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java b/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java index 8721801..61fadcc 100644 --- a/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java +++ b/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java @@ -1,7 +1,6 @@ package com.mjsheng.myappstore.server; import android.app.Service; -import android.content.Context; import android.content.ContextWrapper; import android.content.Intent; import android.content.IntentFilter; @@ -18,17 +17,15 @@ import android.util.Log; import com.alibaba.fastjson.JSON; import com.arialyy.aria.core.Aria; -import com.blankj.utilcode.util.EncryptUtils; import com.blankj.utilcode.util.LogUtils; -import com.blankj.utilcode.util.PathUtils; -import com.blankj.utilcode.util.ToastUtils; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.MyApplication; -import com.mjsheng.myappstore.activity.MainActivity; +import com.mjsheng.myappstore.bean.Batch; import com.mjsheng.myappstore.bean.ForceDownloadBean; import com.mjsheng.myappstore.bean.ForceDownloadData; +import com.mjsheng.myappstore.bean.LzyResponse; import com.mjsheng.myappstore.bean.NetAndLaunchBean; import com.mjsheng.myappstore.bean.NetAndLaunchData; import com.mjsheng.myappstore.comm.CommonDatas; @@ -41,6 +38,7 @@ import com.mjsheng.myappstore.network.api.DeselectIDApi; import com.mjsheng.myappstore.network.api.ForceDownloadApi; import com.mjsheng.myappstore.network.api.NetAndLaunchApi; import com.mjsheng.myappstore.network.api.SystemSettingApi; +import com.mjsheng.myappstore.network.api.newapi.GetBatchApi; import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.Configure; import com.mjsheng.myappstore.utils.MySQLData; @@ -66,6 +64,8 @@ import io.reactivex.schedulers.Schedulers; import okhttp3.Call; import okhttp3.Response; import okhttp3.ResponseBody; +import okhttp3.internal.Util; +import retrofit2.Retrofit; import rx.Observable; import rx.functions.Action1; @@ -321,11 +321,62 @@ public class InitJpushServer extends Service { } int locked = Settings.System.getInt(InitJpushServer.this.getContentResolver(), "qch_unlock_ipad", 1); if (locked == 0) { - deleteOtherApp(result); + getDeviceBatch(result); + } } + private void getDeviceBatch(final String result) { + GetBatchApi getBatchApi = Network.getBatchApi(); + getBatchApi.getBatch(Utils.getSerial()) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + Log.e("getDeviceBatch", "onSubscribe"); + } + + @Override + public void onNext(ResponseBody responseBody) { + String respons = ""; + com.alibaba.fastjson.JSONObject jsonObject = null; + try { + respons = responseBody.string(); + Log.e("getDeviceBatch", "respons:" + respons); + jsonObject = JSON.parseObject(respons); + } catch (IOException e) { + e.printStackTrace(); + } + int code = jsonObject.getInteger("code"); + if (code == 200) { + String data = jsonObject.getString("data"); + List batchList = JSON.parseArray(data, Batch.class); + if (null != batchList && batchList.size() > 1) { + deleteOtherApp(result); + } else { + Log.e("getDeviceBatch", "批次为空"); + } + } + } + + @Override + public void onError(Throwable e) { + Log.e("getDeviceBatch", "onError:" + e.getMessage()); + } + + @Override + public void onComplete() { + Log.e("getDeviceBatch", "onComplete"); + + } + }); + + } + + + //删除用户除了在应用市场的其他应用 private void deleteOtherApp(String packageList) { Log.e("deleteOtherApp", "packageList:" + packageList); String[] result = packageList.split(","); @@ -745,7 +796,7 @@ public class InitJpushServer extends Service { .params("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress()) .params("jpush_id", rid) .params("devices_version", Utils.getProperty("ro.custom.build.version", "获取失败")) - .params("appstore_version", BuildConfig.VERSION_NAME)//设备信息版本号 + .params("appstore_version", BuildConfig.VERSION_NAME)//我的设备版本号 .params("store_version", getAPPVersionName())//管教易版本号 .execute(new StringCallback() { @Override diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java index 75a0e68..52f356a 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java @@ -600,6 +600,7 @@ public class ApkUtils { this.add("com.android.dreams.basic"); this.add("com.android.musicfx"); this.add("com.android.email"); + this.add("com.jiaoguanyi.sysc"); }}; public static List show_canremove_systemapp = new ArrayList() {{ diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/Configure.java b/app/src/main/java/com/mjsheng/myappstore/utils/Configure.java index f1ed771..cc0dccf 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/Configure.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/Configure.java @@ -209,5 +209,5 @@ public class Configure { public static final String SEND_SCREENSHOT = HTTP_TAG_HEAD_NEW + "Screenshot/addImg"; //上传截图 public static final String UPDATE_DEVICEINFO = HTTP_TAG_HEAD_NEW + "Mac/getInfo"; - //上传设备信息 + //上传我的设备 } diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java index 2ca4367..944bdee 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java @@ -64,6 +64,7 @@ import com.mjsheng.myappstore.comm.CommonDatas; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; +import java.io.FileFilter; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -71,6 +72,7 @@ import java.io.LineNumberReader; import java.io.Reader; import java.lang.reflect.Method; import java.net.NetworkInterface; +import java.net.SocketException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.DecimalFormat; @@ -84,6 +86,15 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.regex.Pattern; + +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; public class Utils { @@ -1049,20 +1060,55 @@ public class Utils { * 屏幕截图 * 适用于lanucher版 */ - public void shotScreen() { + public static void shotScreen(final Context context) { //adb截图方法 - new Thread(new Runnable() { + Observable.create(new ObservableOnSubscribe() { @Override - public void run() { - Log.e("whh0914", "开始屏幕截图..."); - String filepath = "/sdcard/screenShot.png"; - try { - CmdUtil.execute("screencap -p " + filepath); - } catch (Exception e) { - Log.e("whh0914", "屏幕截图出现异常:" + e.toString()); - } + public void subscribe(ObservableEmitter e) throws Exception { + String filepath = context.getCacheDir().getAbsolutePath(); + long time = System.currentTimeMillis(); + int n = CmdUtil.execute("screencap -p " + filepath + File.separator + time + ".db").code; + e.onNext(n); } - }).start(); + }).subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Integer integer) { + if (integer == 0) { + Log.e("doss", "成功"); + } else { + Log.e("doss", "失败"); + } + } + + @Override + public void onError(Throwable e) { + Log.e("doss", "Throwable=" + e.getMessage()); + } + + @Override + public void onComplete() { + + } + }); +// new Thread(new Runnable() { +// @Override +// public void run() { +// Log.e("whh0914", "开始屏幕截图..."); +// String filepath = context.getFileStreamPath("screenshot").getAbsolutePath(); +// try { +// CmdUtil.execute("screencap -p " + filepath); +// } catch (Exception e) { +// Log.e("whh0914", "屏幕截图出现异常:" + e.toString()); +// } +// } +// }).start(); } @@ -1131,31 +1177,65 @@ public class Utils { Log.e("h_bl", "屏幕密度dpi(120 / 160 / 240):" + densityDpi); Log.e("h_bl", "屏幕宽度(dp):" + screenWidth); Log.e("h_bl", "屏幕高度(dp):" + screenHeight); - return screenWidth + "×" + screenHeight; + return width + "×" + height; } + public static String getMacAddress() { + List interfaces = null; + try { + interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); + for (NetworkInterface networkInterface : interfaces) { + if (networkInterface != null && TextUtils.isEmpty(networkInterface.getName()) == false) { + if ("wlan0".equalsIgnoreCase(networkInterface.getName())) { + byte[] macBytes = networkInterface.getHardwareAddress(); + if (macBytes != null && macBytes.length > 0) { + StringBuilder str = new StringBuilder(); + for (byte b : macBytes) { + str.append(String.format("%02X:", b)); + } + if (str.length() > 0) { + str.deleteCharAt(str.length() - 1); + } + return str.toString(); + } + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + return "unknown"; + } + + public static String getIMEI(Context context) { String IMEI = "unknow"; String IMEI1, IMEI2, IMEI3; //获取手机设备号 TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); //8.0及以后版本获取 -// if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) { -// IMEI1 = TelephonyMgr.getDeviceId(); -// } else - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { -// try { -// Method method = TelephonyMgr.getClass().getMethod("getImei"); -// IMEI2 = (String) method.invoke(TelephonyMgr); -// } catch (Exception e) { -// e.printStackTrace(); -// Log.e("getIMEI", e.getMessage()); -// } + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + IMEI = TelephonyMgr.getDeviceId(); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { +// try { +// Method method = TelephonyMgr.getClass().getMethod("getImei"); +// IMEI = (String) method.invoke(TelephonyMgr); +// } catch (Exception e) { +// e.printStackTrace(); +// Log.e("getIMEI", e.getMessage()); +// } +// IMEI = TelephonyMgr.getDeviceId(); + // } else {//9.0到10.0获取 IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } Log.e("IMEI:", "IMEI: " + IMEI); - return IMEI.toUpperCase(); + if (null == IMEI) { + return "-"; + } else { + return IMEI.toUpperCase(); + } + } public static String getMachine(Context context) { @@ -1175,16 +1255,48 @@ public class Utils { return jsonObject.toJSONString(); } + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static String getHardware(Context context) { - JSONObject jsonObject = new JSONObject(); - String electric = getBattery(context) + "%"; - String charging = String.valueOf(getIsCharging(context)); + int electric = getBattery(context); + int charging = getIsCharging(context); String memory = Formatter.formatFileSize(context, getAvailMemory(context)) + "\t 已用" + "/" + "共" + Formatter.formatFileSize(context, getTotalMemory(context)); String storage = getRemnantSize(context) + "/" + getDataTotalSize(context); -// String CPU = ; + int CPU = getNumCores(); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("electric", electric); + jsonObject.put("charging", charging); + jsonObject.put("memory", memory); + jsonObject.put("storage", storage); + jsonObject.put("CPU", CPU + "核"); return jsonObject.toJSONString(); } + private static int getNumCores() { + // Private Class to display only CPU devices in the directory listing + class CpuFilter implements FileFilter { + @Override + public boolean accept(File pathname) { + // Check if filename is "cpu", followed by a single digit number + if (Pattern.matches("cpu[0-9]", pathname.getName())) { + return true; + } + return false; + } + } + + try { + // Get directory containing CPU info + File dir = new File("/sys/devices/system/cpu/"); + // Filter to only list the devices we care about + File[] files = dir.listFiles(new CpuFilter()); + // Return the number of cores (virtual CPU devices) + return files.length; + } catch (Exception e) { + // Default to return 1 core + return 1; + } + } + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static int getBattery(Context context) { try { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52de4fe..d56cd33 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - 设备信息 + 我的设备 账户管理 护眼设置