update:2020.05.28
fix:去掉应用安装权限申请 add:升级apk覆盖安装推送和接口
This commit is contained in:
@@ -10,6 +10,7 @@ import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -46,6 +47,7 @@ import org.lzh.framework.updatepluginlib.model.CheckEntity;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -490,6 +492,74 @@ public class MyApplication extends MultiDexApplication {
|
||||
|
||||
}
|
||||
|
||||
private static long totalTime;
|
||||
private static int totalTimes;
|
||||
|
||||
synchronized public static void setAPPUsage() {
|
||||
StatisticsInfo statisticsInfo = new StatisticsInfo(getAppContext());
|
||||
totalTime = statisticsInfo.getTotalTime();//全部时间
|
||||
totalTimes = statisticsInfo.getTotalTimes();//全部次数
|
||||
}
|
||||
|
||||
|
||||
synchronized public static void setAPPUsage(List<String> lists) {
|
||||
StatisticsInfo statisticsInfo = new StatisticsInfo(getAppContext());
|
||||
List<AppInformation> list = null;
|
||||
List<AppInformation> localAppList = new ArrayList<>();
|
||||
|
||||
totalTime = statisticsInfo.getTotalTime();//全部时间
|
||||
totalTimes = statisticsInfo.getTotalTimes();//全部次数
|
||||
|
||||
list = statisticsInfo.getShowList();
|
||||
if (list != null && list.size() > 0) {
|
||||
for (AppInformation appInformation : list) {
|
||||
if (lists.indexOf(appInformation.getPackageName()) != -1) {
|
||||
localAppList.add(appInformation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
synchronized public void getWhitePackageList() {
|
||||
OkGo.post(Configure.SEND_APP_USAGE)
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("key", Configure.HTTP_KEY)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
String data = jsonObject.getString("data");
|
||||
if (code == 200) {
|
||||
com.alibaba.fastjson.JSONObject resultJson = JSON.parseObject(data);
|
||||
String result = resultJson.getString("result");
|
||||
if (!TextUtils.isEmpty(result)) {
|
||||
String[] list = result.split(",");
|
||||
List<String> allList = new ArrayList<>(Arrays.asList(list));
|
||||
setAPPUsage(allList);
|
||||
}
|
||||
} else {
|
||||
setAPPUsage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void catchException() {
|
||||
Thread.setDefaultUncaughtExceptionHandler(
|
||||
new Thread.UncaughtExceptionHandler() {
|
||||
|
||||
@@ -364,6 +364,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
private void initData() {
|
||||
Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial());
|
||||
getLockedState();
|
||||
MyApplication.getInstance().getWhitePackageList();
|
||||
initJpush();//初始化极光推送
|
||||
HTTPInterface.setJpushTags(this);
|
||||
// update();//接口更新app
|
||||
@@ -422,7 +423,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
// Permission.READ_SMS,
|
||||
// Permission.RECEIVE_SMS,
|
||||
// Permission.SEND_SMS,
|
||||
Permission.REQUEST_INSTALL_PACKAGES,
|
||||
// Permission.REQUEST_INSTALL_PACKAGES,//不用请求也可以安装
|
||||
Permission.READ_EXTERNAL_STORAGE,
|
||||
Permission.WRITE_EXTERNAL_STORAGE,
|
||||
// Permission.READ_PHONE_STATE
|
||||
@@ -621,6 +622,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
sendBroadcast(allIntent);
|
||||
loadHeadImg(Configure.HTTP_TAG_HOME_PAGE_URL);
|
||||
lazyLoading();
|
||||
MyApplication.getInstance().getWhitePackageList();
|
||||
|
||||
}
|
||||
|
||||
@@ -1150,15 +1152,38 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
ForceDownloadData forceDownloadData = data.get(i);
|
||||
String app_package = forceDownloadData.getApp_package();
|
||||
String app_url = forceDownloadData.getApp_url();
|
||||
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url);
|
||||
int app_version_code = forceDownloadData.getApp_version_code();
|
||||
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code);
|
||||
if (data.get(i).getApp_package().equals("com.jiaoguanyi.store")) {
|
||||
continue;//为自身的跳过下载
|
||||
}
|
||||
if (!list.contains(app_package)) {
|
||||
list.add(app_package);
|
||||
}
|
||||
|
||||
if (!AppUtils.isAppInstalled(app_package)) {
|
||||
PackageManager pm = getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(app_package, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "forceDownload=" + e.getMessage());
|
||||
}
|
||||
if (packageInfo != null) {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = packageInfo.versionCode;
|
||||
}
|
||||
if (app_version_code > appVersionCode) {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
Aria.download(this)
|
||||
.load(app_url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
|
||||
.setExtendField(app_package)
|
||||
.create(); //启动下载}
|
||||
}
|
||||
} else {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
// if (!SaveListUtils.isDownLoading(app_package)) {
|
||||
Aria.download(this)
|
||||
|
||||
@@ -14,6 +14,7 @@ public class ForceDownloadData {
|
||||
|
||||
private String app_package;
|
||||
private String app_url;
|
||||
private int app_version_code;
|
||||
|
||||
public String getApp_package() {
|
||||
return app_package;
|
||||
@@ -31,6 +32,14 @@ public class ForceDownloadData {
|
||||
this.app_url = app_url;
|
||||
}
|
||||
|
||||
public int getApp_version_code() {
|
||||
return app_version_code;
|
||||
}
|
||||
|
||||
public void setApp_version_code(int app_version_code) {
|
||||
this.app_version_code = app_version_code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ForceDownloadData{" +
|
||||
|
||||
@@ -342,6 +342,7 @@ public class HTTPInterface {
|
||||
}
|
||||
|
||||
synchronized public static void setHomepagtag(final Context context) {
|
||||
//7.0setPackage不加没有问题,.setPackage("com.android.settings"),10.0需要加上,待底层修改后
|
||||
OkGo.post(Configure.SET_HOMEPAG_TAG)
|
||||
.params("key", Configure.HTTP_KEY)
|
||||
.params("sn", Utils.getSerial())
|
||||
@@ -349,48 +350,52 @@ public class HTTPInterface {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
// try {
|
||||
JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == 200) {
|
||||
String data = jsonObject.getString("data");
|
||||
JSONObject jsondata = JSON.parseObject(data);
|
||||
//主页
|
||||
String homepagURL = jsondata.getString("homepage");
|
||||
Intent homepag = new Intent("qch_app_brower_homepage")
|
||||
JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
if (code == 200) {
|
||||
String data = jsonObject.getString("data");
|
||||
JSONObject jsondata = JSON.parseObject(data);
|
||||
//主页
|
||||
String homepagURL = jsondata.getString("homepage");
|
||||
Intent homepag = new Intent("qch_app_brower_homepage")
|
||||
.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
if (homepagURL != null && !homepagURL.equals("")) {
|
||||
homepag.putExtra("homepage", homepagURL);
|
||||
} else {
|
||||
homepag.putExtra("homepage", "Invalid");
|
||||
}
|
||||
context.sendBroadcast(homepag);
|
||||
|
||||
//书签
|
||||
String labelpage = jsondata.getString("labelpage");
|
||||
Intent websiteBookMark = new Intent("qch_app_brower_website")
|
||||
.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
if (labelpage != null && !labelpage.equals("")) {
|
||||
websiteBookMark.putExtra("websiteBookMark", labelpage);
|
||||
} else {
|
||||
websiteBookMark.putExtra("websiteBookMark", "Invalid");
|
||||
}
|
||||
context.sendBroadcast(websiteBookMark);
|
||||
|
||||
// .setPackage("com.android.browser")
|
||||
;
|
||||
if (homepagURL != null && !homepagURL.equals("")) {
|
||||
homepag.putExtra("homepage", homepagURL);
|
||||
} else {
|
||||
Intent intent1 = new Intent("qch_app_brower_homepage")
|
||||
.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
intent1.putExtra("homepage", "Invalid");
|
||||
context.sendBroadcast(intent1);
|
||||
Intent intent2 = new Intent("qch_app_brower_website")
|
||||
.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
intent2.putExtra("websiteBookMark", "Invalid");
|
||||
context.sendBroadcast(intent2);
|
||||
homepag.putExtra("homepage", "Invalid");
|
||||
}
|
||||
context.sendBroadcast(homepag);
|
||||
|
||||
//书签
|
||||
String labelpage = jsondata.getString("labelpage");
|
||||
Intent websiteBookMark = new Intent("qch_app_brower_website")
|
||||
.setPackage("com.android.settings")
|
||||
// .setPackage("com.android.browser")
|
||||
;
|
||||
if (labelpage != null && !labelpage.equals("")) {
|
||||
websiteBookMark.putExtra("websiteBookMark", labelpage);
|
||||
} else {
|
||||
websiteBookMark.putExtra("websiteBookMark", "Invalid");
|
||||
}
|
||||
context.sendBroadcast(websiteBookMark);
|
||||
|
||||
} else {
|
||||
Intent intent1 = new Intent("qch_app_brower_homepage")
|
||||
.setPackage("com.android.settings")
|
||||
// .setPackage("com.android.browser")
|
||||
;
|
||||
intent1.putExtra("homepage", "Invalid");
|
||||
context.sendBroadcast(intent1);
|
||||
Intent intent2 = new Intent("qch_app_brower_website")
|
||||
.setPackage("com.android.settings")
|
||||
// .setPackage("com.android.browser")
|
||||
;
|
||||
intent2.putExtra("websiteBookMark", "Invalid");
|
||||
context.sendBroadcast(intent2);
|
||||
}
|
||||
// } catch (Exception e) {
|
||||
// Log.e("fht", "setHomepagtag" + e.getMessage());
|
||||
//// ToastUtil.show("数据错误");
|
||||
@@ -434,7 +439,8 @@ public class HTTPInterface {
|
||||
packageList = packageList.substring(0, packageList.length() - 1);
|
||||
//去掉多余的,
|
||||
Log.e("setAppinsideWeb ", "packageList:" + packageList);
|
||||
Intent qch_app_website = new Intent("qch_app_website").setPackage("com.android.settings");
|
||||
Intent qch_app_website = new Intent("qch_app_website")
|
||||
.setPackage("com.android.settings");
|
||||
qch_app_website.putExtra("package_name", packageList);
|
||||
context.sendBroadcast(qch_app_website);
|
||||
} else {
|
||||
@@ -445,7 +451,8 @@ public class HTTPInterface {
|
||||
strings = strings.substring(0, strings.length() - 1);
|
||||
//去掉多余的;
|
||||
Log.e("setAppinsideWeb ", "strings:" + strings);
|
||||
Intent intent = new Intent("qch_app_inside_website").setPackage("com.android.settings");
|
||||
Intent intent = new Intent("qch_app_inside_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("websitelist", strings);
|
||||
context.sendBroadcast(intent);
|
||||
} else {
|
||||
@@ -474,13 +481,15 @@ public class HTTPInterface {
|
||||
}
|
||||
|
||||
private static void sendAllweb(Context context) {
|
||||
Intent intent = new Intent("qch_app_website").setPackage("com.android.settings");
|
||||
Intent intent = new Intent("qch_app_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("package_name", "Invalid");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private static void sendwebUrl(Context context) {
|
||||
Intent intent = new Intent("qch_app_inside_website").setPackage("com.android.settings");
|
||||
Intent intent = new Intent("qch_app_inside_website")
|
||||
.setPackage("com.android.settings");
|
||||
intent.putExtra("websitelist", "Invalid");
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
@@ -518,7 +527,7 @@ public class HTTPInterface {
|
||||
Log.e("fht", "setBrowserList" + msg);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
Log.e("fht", "setBrowserList" +e.getMessage());
|
||||
Log.e("fht", "setBrowserList" + e.getMessage());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.content.Context;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -293,22 +296,46 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
}
|
||||
try {
|
||||
JSONObject jSONObject = new JSONObject(s);
|
||||
s = jSONObject.optString("app_package");
|
||||
String str = jSONObject.optString("app_url");
|
||||
Log.e("mymjsheng", "app_package::" + s);
|
||||
Log.e("mymjsheng", "app_url::" + str);
|
||||
SaveListUtils.addList(s);
|
||||
String app_package = jSONObject.optString("app_package");
|
||||
String app_url = jSONObject.optString("app_url");
|
||||
int app_version_code = jSONObject.optInt("app_version_code");
|
||||
Log.e("mymjsheng", "app_package::" + app_package);
|
||||
Log.e("mymjsheng", "app_url::" + app_url);
|
||||
SaveListUtils.addList(app_package);
|
||||
SaveListUtils.sendForceAPP(mContext);
|
||||
if (!AppUtils.isAppInstalled(s)) {
|
||||
if (!SaveListUtils.isDownLoading(s)) {
|
||||
(Aria.download(this)
|
||||
.load(str)
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(s) + ".apk").setExtendField(s))
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(app_package, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null) {
|
||||
if (!SaveListUtils.isDownLoading(app_url)) {
|
||||
Aria.download(this)
|
||||
.load(app_url)
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(s) + ".apk").setExtendField(app_package)
|
||||
.create();
|
||||
}
|
||||
} else {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = packageInfo.versionCode;
|
||||
}
|
||||
if (app_version_code > appVersionCode) {
|
||||
if (!SaveListUtils.isDownLoading(app_url)) {
|
||||
Aria.download(this)
|
||||
.load(app_url)
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(s) + ".apk").setExtendField(app_package)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "doDownloadAndInstall:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
@@ -90,7 +91,6 @@ public class InitJpushServer extends Service {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// 初始化 JPush
|
||||
@@ -139,7 +139,7 @@ public class InitJpushServer extends Service {
|
||||
|
||||
|
||||
//重新设置jpush
|
||||
synchronized private void timerImitate() {
|
||||
synchronized private void timerImitate() {
|
||||
Observable.timer(15000, TimeUnit.MILLISECONDS)
|
||||
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
|
||||
.subscribe(new Action1<Long>() {
|
||||
@@ -418,21 +418,47 @@ public class InitJpushServer extends Service {
|
||||
ForceDownloadData forceDownloadData = data.get(i);
|
||||
String app_package = forceDownloadData.getApp_package();
|
||||
String app_url = forceDownloadData.getApp_url();
|
||||
int app_version_code = forceDownloadData.getApp_version_code();
|
||||
Log.e("fht ", "packageName=" + app_package + ",URL= " + app_url + ",app_version_code=" + app_version_code);
|
||||
if (data.get(i).getApp_package().equals("com.jiaoguanyi.appstore")) {
|
||||
continue;//为自身的跳过下载
|
||||
}
|
||||
if (!list.contains(app_package)) {
|
||||
list.add(app_package);
|
||||
}
|
||||
if (!AppUtils.isAppInstalled(app_package)) {
|
||||
if (!SaveListUtils.isDownLoading(app_package)) {
|
||||
PackageManager pm = getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(app_package, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
Log.e("fht", "forceDownload=" + e.getMessage());
|
||||
}
|
||||
if (packageInfo != null) {
|
||||
long appVersionCode;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
appVersionCode = packageInfo.getLongVersionCode();
|
||||
} else {
|
||||
appVersionCode = packageInfo.versionCode;
|
||||
}
|
||||
if (app_version_code > appVersionCode) {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
Aria.download(this)
|
||||
.load(app_url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk")
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
|
||||
.setExtendField(app_package)
|
||||
.create(); //启动下载}
|
||||
SaveListUtils.addDownLoadList(app_package);
|
||||
}
|
||||
} else {
|
||||
Log.e("fht ", "download URL " + app_url);
|
||||
// if (!SaveListUtils.isDownLoading(app_package)) {
|
||||
Aria.download(this)
|
||||
.load(app_url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(app_package) + ".apk", true)
|
||||
.setExtendField(app_package)
|
||||
.create(); //启动下载}
|
||||
// SaveListUtils.addDownLoadList(app_package);
|
||||
// }
|
||||
}
|
||||
}
|
||||
SaveListUtils.setList(list);
|
||||
@@ -682,6 +708,7 @@ public class InitJpushServer extends Service {
|
||||
HTTPInterface.setBrowserList(InitJpushServer.this);//浏览器网址管控
|
||||
HTTPInterface.setAppinsideWeb(InitJpushServer.this);//app内部网页管控
|
||||
HTTPInterface.setHomepagtag(InitJpushServer.this);//设置主页和标签
|
||||
MyApplication.getInstance().getWhitePackageList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,4 +197,6 @@ public class Configure {
|
||||
public static final String SET_APPINSIDEWEB = HTTP_TAG_HEAD_NEW + "Appground";
|
||||
//浏览器黑白名单地址
|
||||
public static final String SET_BROWSER_LIST = HTTP_TAG_HEAD_NEW + "browser";
|
||||
|
||||
public static final String SEND_APP_USAGE = HTTP_TAG_HEAD_NEW + "firmware/index";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user