update:2020.01.10 20:21
fix:修改安装逻辑,优化状态栏逻辑 add:
This commit is contained in:
@@ -19,7 +19,9 @@ import com.lzy.okserver.download.DownloadService;
|
||||
import com.mjsheng.myappstore.Statistics.AppInformation;
|
||||
import com.mjsheng.myappstore.Statistics.StatisticsInfo;
|
||||
import com.mjsheng.myappstore.activity.MainActivity;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.Configure;
|
||||
import com.mjsheng.myappstore.utils.MySQLData;
|
||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||
@@ -304,6 +306,66 @@ public class MyApplication extends MultiDexApplication implements Thread.Uncaugh
|
||||
NetStateChangeReceiver.unregisterReceiver(this);
|
||||
}
|
||||
|
||||
static List<FileData> fileList = new ArrayList<>();
|
||||
|
||||
|
||||
static String packageName = "";
|
||||
|
||||
public void setInstallIngPackageName(String packageNames) {
|
||||
packageName = packageNames;
|
||||
Log.e("fht", "正在安装:" + packageNames);
|
||||
}
|
||||
|
||||
public String getInstallIngPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void addFileData(FileData data) {
|
||||
fileList.add(data);
|
||||
updateList();
|
||||
}
|
||||
|
||||
public void removeDate(String packageName) {
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
for (FileData data : fileList) {
|
||||
if (data.getPackageName().equals(packageName)) {
|
||||
fileList.remove(data);
|
||||
break;
|
||||
} else {
|
||||
Log.e("fht", "not found object");
|
||||
}
|
||||
}
|
||||
}
|
||||
setInstallIngPackageName("");
|
||||
if (fileList.size() > 0) {
|
||||
updateList();
|
||||
} else {
|
||||
Log.e("fht", "fileList为空");
|
||||
setInstallIngPackageName("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateList() {
|
||||
if (getInstallIngPackageName().equals("") || ApkUtils.isAvailable(getAppContext(), packageName)) {
|
||||
if (fileList != null && fileList.size() > 0) {
|
||||
if (!fileList.get(0).getPackageName().equals("") || ApkUtils.isAvailable(getAppContext(), fileList.get(0).getPackageName())) {
|
||||
String s = packageName;
|
||||
ApkUtils.installApp(this, fileList.get(0).getFilePath());
|
||||
setInstallIngPackageName(fileList.get(0).getPackageName());
|
||||
} else {
|
||||
removeDate(fileList.get(0).getPackageName());
|
||||
Log.e("fht", "已安装");
|
||||
setInstallIngPackageName("");
|
||||
}
|
||||
} else {
|
||||
Log.e("fht", "任务为空");
|
||||
}
|
||||
} else {
|
||||
Log.e("fht", "安装中:" + packageName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.BatteryManager;
|
||||
@@ -37,13 +38,19 @@ import com.hjq.permissions.OnPermission;
|
||||
import com.hjq.permissions.Permission;
|
||||
import com.hjq.permissions.XXPermissions;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.cache.CacheMode;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.lzy.okserver.download.DownloadManager;
|
||||
import com.lzy.okserver.download.DownloadService;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.CommonPicBean;
|
||||
import com.mjsheng.myappstore.bean.CommonPicData;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadBean;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadData;
|
||||
import com.mjsheng.myappstore.bean.JsonCallback;
|
||||
import com.mjsheng.myappstore.bean.LzyResponse;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchData;
|
||||
import com.mjsheng.myappstore.bean.UploadAppInfo;
|
||||
@@ -52,6 +59,7 @@ import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
import com.mjsheng.myappstore.network.HTTPInterface;
|
||||
import com.mjsheng.myappstore.network.Network;
|
||||
import com.mjsheng.myappstore.network.api.AppLimitApi;
|
||||
import com.mjsheng.myappstore.network.api.BrankPicApi;
|
||||
import com.mjsheng.myappstore.network.api.DeselectBrowserIDApi;
|
||||
import com.mjsheng.myappstore.network.api.DeselectIDApi;
|
||||
import com.mjsheng.myappstore.network.api.ForceDownloadApi;
|
||||
@@ -70,6 +78,7 @@ import com.mjsheng.myappstore.utils.update.AllDialogShowStrategy;
|
||||
import com.mjsheng.myappstore.utils.update.NotificationDownloadCreator;
|
||||
import com.mjsheng.myappstore.utils.update.OkhttpCheckWorker;
|
||||
import com.mjsheng.myappstore.utils.update.ToastCallback;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
import com.tianma.netdetector.lib.NetStateChangeObserver;
|
||||
import com.tianma.netdetector.lib.NetworkType;
|
||||
|
||||
@@ -79,6 +88,7 @@ import org.lzh.framework.updatepluginlib.UpdateBuilder;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -106,7 +116,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
private DownloadManager downloadManager;
|
||||
public static boolean isForeground = false;
|
||||
private ImageView imageView;
|
||||
private TextView tv_devsn, tv_devmac, tv_version;
|
||||
private TextView tv_devsn, tv_devmac, tv_version;
|
||||
private int DeviceInfo;
|
||||
|
||||
@Override
|
||||
@@ -143,7 +153,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
// }
|
||||
requestPermission();
|
||||
registerMessageReceiver(); // used for receive msg
|
||||
HTTPInterface.checkDevicesInfo(handler);
|
||||
// HTTPInterface.checkDevicesInfo(handler);
|
||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
@@ -162,7 +172,6 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION);
|
||||
sendBroadcast(allIntent);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -172,18 +181,19 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress())
|
||||
.params("jpush_id", rid)
|
||||
.params("appstore_version", Utils.getProperty("ro.custom.build.version","获取失败"))
|
||||
.params("store_version", BuildConfig.VERSION_NAME)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
com.alibaba.fastjson.JSONObject msgObject = JSON.parseObject(s);
|
||||
int code = msgObject.getInteger("code");
|
||||
Log.e("sendMACaddress", msgObject.getString("msg"));
|
||||
Log.e("fht", "sendMACaddress onSuccess"+s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("sendMACaddress", e.getMessage());
|
||||
Log.e("fht", "sendMACaddress onError:"+e.getMessage());
|
||||
|
||||
}
|
||||
});
|
||||
@@ -195,9 +205,9 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
private void initView() {
|
||||
imageView = findViewById(R.id.imageView);
|
||||
tv_devsn = findViewById(R.id.tv_devsn);
|
||||
tv_devsn.setText("设备SN:" + Utils.getSerial());
|
||||
tv_devsn.setText("设备SN\t\t" + Utils.getSerial());
|
||||
tv_devmac = findViewById(R.id.tv_devmac);
|
||||
tv_devmac.setText("设备MAC:" + com.blankj.utilcode.util.DeviceUtils.getMacAddress());
|
||||
tv_devmac.setText("MAC地址\t\t" + com.blankj.utilcode.util.DeviceUtils.getMacAddress());
|
||||
tv_version = findViewById(R.id.version);
|
||||
tv_version.setText("版本:" + BuildConfig.VERSION_NAME);
|
||||
}
|
||||
@@ -206,6 +216,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial());
|
||||
getLockedState();
|
||||
initJpush();//初始化极光推送
|
||||
setJpushTags();
|
||||
// update();//接口更新app
|
||||
sendMACaddress();
|
||||
|
||||
@@ -231,52 +242,6 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
|
||||
|
||||
private String getGrade(String grade) {
|
||||
String s;
|
||||
switch (grade) {
|
||||
case "1":
|
||||
s = "一年级";
|
||||
break;
|
||||
case "2":
|
||||
s = "二年级";
|
||||
break;
|
||||
case "3":
|
||||
s = "三年级";
|
||||
break;
|
||||
case "4":
|
||||
s = "四年级";
|
||||
break;
|
||||
case "5":
|
||||
s = "五年级";
|
||||
break;
|
||||
case "6":
|
||||
s = "六年级";
|
||||
break;
|
||||
case "7":
|
||||
s = "初一";
|
||||
break;
|
||||
case "8":
|
||||
s = "初二";
|
||||
break;
|
||||
case "9":
|
||||
s = "初三";
|
||||
break;
|
||||
case "10":
|
||||
s = "高一";
|
||||
break;
|
||||
case "11":
|
||||
s = "高二";
|
||||
break;
|
||||
case "12":
|
||||
s = "高三";
|
||||
break;
|
||||
default:
|
||||
s = "一年级";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
@@ -441,6 +406,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
Aria.download(this).resumeAllTask();
|
||||
getForceDownload();//强制下载apk
|
||||
resetDevice();//恢复出厂设置
|
||||
checkUpdate();//更新app
|
||||
// fromNetToUpdate();
|
||||
String registrationID = JPushInterface.getRegistrationID(MainActivity.this);
|
||||
Log.e("mjsheng", registrationID + "------------------------");
|
||||
@@ -462,6 +428,49 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
HTTPInterface.checkUpdate(mHandler, "com.jiaoguanyi.store");
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 200:
|
||||
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) msg.obj;
|
||||
installAPK(jsonObject);
|
||||
break;
|
||||
case -200:
|
||||
Log.e("fht", "no update");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private void installAPK(com.alibaba.fastjson.JSONObject jsonObject) {
|
||||
String url = jsonObject.getString("url");
|
||||
int versionCode = jsonObject.getInteger("version_code");
|
||||
String packageName = jsonObject.getString("package");
|
||||
PackageManager pm = getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null || packageInfo.versionCode != versionCode) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(packageName) + ".apk", true)
|
||||
.setExtendField(packageName)
|
||||
.start(); //启动下载}
|
||||
} else {
|
||||
Log.e("fht", "无需更新");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int getBatteryLevel() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);
|
||||
@@ -488,8 +497,93 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
Intent allIntent = new Intent();
|
||||
allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION);
|
||||
sendBroadcast(allIntent);
|
||||
loadHeadImg(Configure.HTTP_TAG_HOME_PAGE_URL);
|
||||
|
||||
|
||||
lazyLoading();
|
||||
|
||||
}
|
||||
|
||||
private void loadHeadImg(String URL) {
|
||||
BrankPicApi brankPicApi = Network.getBrankPicApi();
|
||||
brankPicApi.getBrankPicApi(Configure.HTTP_KEY, Utils.getSerial(), "1")
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Observer<CommonPicBean>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(CommonPicBean projectPicBean) {
|
||||
paraData(projectPicBean);
|
||||
Log.e("mjsheng", "brankPicApi---" + projectPicBean.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Utils.showToast(getApplicationContext(), "网络出错!");
|
||||
Log.e("mjsheng", "brankPicApi---error----" + e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void paraData(CommonPicBean categoryPicBean) {
|
||||
int code = categoryPicBean.getCode();
|
||||
switch (code) {
|
||||
case 200:
|
||||
final List<CommonPicData> data = categoryPicBean.getData();
|
||||
// if (data != null && data.size() > 0) {
|
||||
// List<String> list = new ArrayList<>();
|
||||
// for (int i = 0; i < data.size(); i++) {
|
||||
// list.add(data.get(i).getImg());
|
||||
// }
|
||||
// webBannerAdapter = new WebBannerAdapter(getActivity(), list);
|
||||
// webBannerAdapter.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
|
||||
// @Override
|
||||
// public void onItemClick(int position) {
|
||||
// loadProjectByType(Configure.HTTP_TAG_BRAND_DETAILS_URL, data.get(position).getId(), data.get(position).getName());
|
||||
// }
|
||||
// });
|
||||
// recyclerBanner.setAdapter(webBannerAdapter);
|
||||
// mAdapter = new TopRecyclerViewAdapter(getActivity(), "home", list, new TopRecyclerViewAdapter.HorizontalScrollViewListener() {
|
||||
// @Override
|
||||
// public void onClick(String iconUrl, int position) {
|
||||
// sound.playSoundEffect();
|
||||
// loadProjectByType(Configure.HTTP_TAG_BRAND_DETAILS_URL, data.get(position).getId(), data.get(position).getName());
|
||||
// }
|
||||
// });
|
||||
// mTopRlView.setAdapter(mAdapter);
|
||||
// } else {
|
||||
// // Utils.showToast(getContext(), "数据为空!");
|
||||
// Log.e("mjsheng", "推荐页轮播图为空!");
|
||||
// }
|
||||
break;
|
||||
case -200:
|
||||
paraError(categoryPicBean.getMsg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void paraError(String msg) {
|
||||
switch (msg) {
|
||||
case "没有找到SN码":
|
||||
Utils.showToast(getApplicationContext(), msg);
|
||||
break;
|
||||
default:
|
||||
Utils.showToast(getApplicationContext(), msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
@@ -563,6 +657,57 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
});
|
||||
}
|
||||
|
||||
private void setJpushTags() {
|
||||
OkGo.get(Configure.GET_DEVICES_TAGS)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
Log.e("fht", s);
|
||||
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
com.alibaba.fastjson.JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (code == 200) {
|
||||
String batch = data.getString("batch");
|
||||
if (batch != null && !batch.equals("")) {
|
||||
Set set = new HashSet();
|
||||
set.add(batch);
|
||||
JPushInterface.setTags(MainActivity.this, set, new TagAliasCallback() {
|
||||
@Override
|
||||
public void gotResult(int i, String s, Set<String> set) {
|
||||
if (set == null) {
|
||||
Log.e("initmjsheng", "set is null");
|
||||
} else {
|
||||
Log.e("initmjsheng", "set ---" + set.toString());
|
||||
}
|
||||
Log.e("JPushInterface", s + "---" + i + "---");
|
||||
if (i == 0) {
|
||||
Log.e("JPushInterface", "Tag绑定成功");
|
||||
} else if (i == 6001) {
|
||||
Log.e("JPushInterface", "无效的设置,用户名为空");
|
||||
} else if (i == 6002) {
|
||||
Log.e("JPushInterface", "设置超时,请重试");
|
||||
timerImitate();
|
||||
} else if (i == 6011) {
|
||||
Log.e("JPushInterface", "短时间内操作过于频繁");
|
||||
} else if (i == 996) {
|
||||
Log.e("JPushInterface", "网络连接断开");
|
||||
timerImitate();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("fht", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initJpush() {
|
||||
|
||||
JPushInterface.setAlias(this, Utils.getSerial(), new TagAliasCallback() {
|
||||
@@ -600,6 +745,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
public void call(Long aLong) {
|
||||
Log.e("JPushInterface", "JPushInterface重新加载");
|
||||
initJpush();
|
||||
setJpushTags();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1159,22 +1306,11 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
|
||||
|
||||
//状态栏显示开关
|
||||
int setting_statusbar = changeNum(data.optInt("setting_statusbar"));
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
|
||||
int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 1);
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
sendBroadcast(statusIntent);
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
|
||||
29
app/src/main/java/com/mjsheng/myappstore/bean/FileData.java
Normal file
29
app/src/main/java/com/mjsheng/myappstore/bean/FileData.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.mjsheng.myappstore.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class FileData implements Serializable {
|
||||
private String filePath;
|
||||
private String packageName;
|
||||
|
||||
public FileData(String f, String p) {
|
||||
this.filePath = f;
|
||||
this.packageName = p;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,13 @@ import android.util.Log;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.mjsheng.myappstore.bean.UserInfo;
|
||||
import com.mjsheng.myappstore.utils.Configure;
|
||||
import com.mjsheng.myappstore.utils.SPUtils;
|
||||
import com.mjsheng.myappstore.utils.ToastUtil;
|
||||
import com.mjsheng.myappstore.utils.Utils;
|
||||
@@ -61,7 +63,6 @@ public class HTTPInterface {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
@@ -69,7 +70,7 @@ public class HTTPInterface {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ public class HTTPInterface {
|
||||
Log.e("checkDevicesInfo", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
@@ -155,6 +157,7 @@ public class HTTPInterface {
|
||||
Log.e("checkUpdateByPackage", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
@@ -175,7 +178,7 @@ public class HTTPInterface {
|
||||
int code = object.getInteger("code");
|
||||
String msg = object.getString("msg");
|
||||
LogUtils.e("setAppinstallInfo", msg);
|
||||
if (code ==200) {
|
||||
if (code == 200) {
|
||||
|
||||
} else {
|
||||
|
||||
@@ -239,5 +242,34 @@ public class HTTPInterface {
|
||||
});
|
||||
}
|
||||
|
||||
synchronized public static void checkUpdate(final Handler handler, String packageName) {
|
||||
|
||||
OkGo.<String>post(Configure.CHECK_UPDATE)
|
||||
.params("package", packageName)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, okhttp3.Response response) {
|
||||
JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
String msg = jsonObject.getString("msg");
|
||||
Message message = new Message();
|
||||
if (code == 200) {
|
||||
JSONObject jsonArray = JSON.parseObject(jsonObject.getString("data"));
|
||||
message.what = code;
|
||||
message.obj = jsonArray;
|
||||
handler.sendMessage(message);
|
||||
} else if (code == -200) {
|
||||
handler.sendEmptyMessage(-200);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("onError", e.getMessage());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,6 +74,8 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
|
||||
private final String GET_APP_USEDTIME = "13";
|
||||
|
||||
private final String GET_FORCEDOWNLOADURL = "14";
|
||||
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -111,21 +113,21 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
boolean qch_usb_choose = Settings.System.putString(mContext.getContentResolver(), "qch_usb_choose", setting_usb);
|
||||
Log.e("SystemSetting", "qch_usb_choose---------" + setting_usb);
|
||||
Log.e("SystemSetting", "qch_usb_choose---------" + qch_usb_choose);
|
||||
String usbStatus = "";
|
||||
switch (setting_usb) {
|
||||
case "usb_charge":
|
||||
usbStatus = "qch_action_usb_usb_charge";
|
||||
break;
|
||||
case "usb_mtp":
|
||||
usbStatus = "qch_action_usb_usb_mtp";
|
||||
break;
|
||||
case "usb_midi":
|
||||
usbStatus = "qch_action_usb_usb_midi";
|
||||
break;
|
||||
String usbStatus = "";
|
||||
switch (setting_usb) {
|
||||
case "usb_charge":
|
||||
usbStatus = "qch_action_usb_usb_charge";
|
||||
break;
|
||||
case "usb_mtp":
|
||||
usbStatus = "qch_action_usb_usb_mtp";
|
||||
break;
|
||||
case "usb_midi":
|
||||
usbStatus = "qch_action_usb_usb_midi";
|
||||
break;
|
||||
|
||||
}
|
||||
Intent usbIntent = new Intent(usbStatus);
|
||||
mContext.sendBroadcast(usbIntent);
|
||||
}
|
||||
Intent usbIntent = new Intent(usbStatus);
|
||||
mContext.sendBroadcast(usbIntent);
|
||||
}
|
||||
|
||||
int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));
|
||||
@@ -156,23 +158,11 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
|
||||
//状态栏显示开关
|
||||
int setting_statusbar = changeNum(data.optInt("setting_statusbar"));
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
|
||||
int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 1);
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
mContext.sendBroadcast(statusIntent);
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
@@ -512,7 +502,16 @@ public class MyJPushReceiver extends BroadcastReceiver {
|
||||
String sendType = jsonObject.getString("type");
|
||||
MyApplication.sendAppUsedTime(random, sendType);
|
||||
break;
|
||||
|
||||
case GET_FORCEDOWNLOADURL:
|
||||
com.alibaba.fastjson.JSONObject URI = JSON.parseObject(extras);
|
||||
String versionCode = URI.getString("version_code");
|
||||
String url = URI.getString("url");
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true)
|
||||
.setExtendField("com.jiaoguanyi.store")
|
||||
.start(); //启动下载}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.util.Log;
|
||||
import com.google.gson.Gson;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.bean.AppData;
|
||||
import com.mjsheng.myappstore.bean.UploadAppInfo;
|
||||
import com.mjsheng.myappstore.network.Network;
|
||||
@@ -45,24 +46,24 @@ public class NewAppReceiver extends BroadcastReceiver {
|
||||
allIntent.setAction(Utils.DOWNLOAD_ALLTASK_ACTION);
|
||||
context.sendBroadcast(allIntent);
|
||||
String packageName = intent.getDataString().replace("package:", "");
|
||||
ApkUtils.removeInfo(packageName);
|
||||
MyApplication.getInstance().removeDate(packageName);
|
||||
Log.e(TAG, "安装了:" + packageName + "包名的程序");
|
||||
Log.e("fht", "安装了:" + packageName + "包名的程序");
|
||||
OkGo.post(Configure.HTTP_TAG_DOWNLOAD_URL)
|
||||
.params("key", Configure.HTTP_KEY)
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("package", packageName)
|
||||
.tag(this)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
.params("key", Configure.HTTP_KEY)
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("package", packageName)
|
||||
.tag(this)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
SaveListUtils.getDownLoadList().remove(packageName);//移除下载列表
|
||||
// ToastTool.show("安装成功");
|
||||
if (!packageName.equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !packageName.equals(context.getPackageName())){
|
||||
updateUserApp(context,packageName);
|
||||
if (!packageName.equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !packageName.equals(context.getPackageName())) {
|
||||
updateUserApp(context, packageName);
|
||||
}
|
||||
// 下载管理服务 删除对应任务
|
||||
Intent msgIntent = new Intent(Utils.DOWNLOAD_DELETE_PACKAGENAME_ACTION);
|
||||
@@ -70,9 +71,9 @@ public class NewAppReceiver extends BroadcastReceiver {
|
||||
context.sendBroadcast(msgIntent);
|
||||
|
||||
Intent intent1 = new Intent();
|
||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED)){
|
||||
if (action.equals(Intent.ACTION_PACKAGE_ADDED)) {
|
||||
intent1.setAction(Utils.ACTION_PACKAGE_ADDED);
|
||||
}else {
|
||||
} else {
|
||||
intent1.setAction(Utils.ACTION_PACKAGE_REPLACED);
|
||||
}
|
||||
intent1.putExtra("packageName", packageName);
|
||||
@@ -84,11 +85,11 @@ public class NewAppReceiver extends BroadcastReceiver {
|
||||
String packageName = intent.getDataString().replace("package:", "");
|
||||
Log.e(TAG, "卸载了:" + packageName + "包名的程序");
|
||||
|
||||
if (!packageName.equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !packageName.equals(context.getPackageName())){
|
||||
deletedateUserApp(context,packageName);
|
||||
if (!packageName.equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !packageName.equals(context.getPackageName())) {
|
||||
deletedateUserApp(context, packageName);
|
||||
}
|
||||
Intent intent1 = new Intent();
|
||||
intent1.setAction(Utils.ACTION_PACKAGE_REMOVED);
|
||||
intent1.setAction(Utils.ACTION_PACKAGE_REMOVED);
|
||||
intent1.putExtra("packageName", packageName);
|
||||
context.sendBroadcast(intent1);
|
||||
getAppInfo(context);
|
||||
@@ -164,7 +165,7 @@ public class NewAppReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onNext(ResponseBody responseBody) {
|
||||
try {
|
||||
Log.e("mjhseng", "上传的结果"+responseBody.string());
|
||||
Log.e("mjhseng", "上传的结果" + responseBody.string());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -24,6 +25,8 @@ import com.mjsheng.myappstore.KeepAliveConnection;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
/**
|
||||
* 守护进程 双进程通讯
|
||||
@@ -71,18 +74,16 @@ public class GuardService extends Service {
|
||||
Aria.download(this).register();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
bindService(new Intent(this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(com.arialyy.aria.core.download.DownloadTask task) {
|
||||
Log.e("mjsheng", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent()+ "-------" + task.getExtendField());
|
||||
Log.e("mjsheng", "正在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
|
||||
ToastUtils.showShort("正在下载=--------------::" + task.getExtendField() + "-------" + task.getPercent());
|
||||
}
|
||||
|
||||
@@ -90,10 +91,18 @@ public class GuardService extends Service {
|
||||
void taskComplete(com.arialyy.aria.core.download.DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
String filepath = task.getDownloadPath();
|
||||
String packageName = task.getExtendField();
|
||||
final String packageName = task.getExtendField();
|
||||
Log.e("mjsheng", "downloadPath::" + filepath);
|
||||
Log.e("mjsheng", "extendField::" + packageName);
|
||||
ApkUtils.installApkInSilence(filepath, packageName);
|
||||
String s = Settings.System.getString(getContentResolver(), "qch_app_forbid");
|
||||
String s1 = s;
|
||||
if (s != null && !s.contains(packageName)) {
|
||||
s1 = s + "," + packageName;
|
||||
Settings.System.putString(getContentResolver(), "qch_app_forbid", s1);
|
||||
ApkUtils.installApp(GuardService.this, filepath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@ package com.mjsheng.myappstore.server;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
@@ -18,11 +22,13 @@ import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.activity.MainActivity;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadBean;
|
||||
import com.mjsheng.myappstore.bean.ForceDownloadData;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchBean;
|
||||
import com.mjsheng.myappstore.bean.NetAndLaunchData;
|
||||
import com.mjsheng.myappstore.comm.CommonDatas;
|
||||
import com.mjsheng.myappstore.network.HTTPInterface;
|
||||
import com.mjsheng.myappstore.network.Network;
|
||||
import com.mjsheng.myappstore.network.api.AppLimitApi;
|
||||
import com.mjsheng.myappstore.network.api.DeselectBrowserIDApi;
|
||||
@@ -39,6 +45,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -86,6 +93,56 @@ public class InitJpushServer extends Service {
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
private void setJpushTags() {
|
||||
OkGo.get(Configure.GET_DEVICES_TAGS)
|
||||
.params("sn", Utils.getSerial())
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
Log.e("fht", s);
|
||||
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(s);
|
||||
int code = jsonObject.getInteger("code");
|
||||
com.alibaba.fastjson.JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (code == 200) {
|
||||
String batch = data.getString("batch");
|
||||
if (batch != null && !batch.equals("")) {
|
||||
Set set = new HashSet();
|
||||
set.add(batch);
|
||||
JPushInterface.setTags(InitJpushServer.this, set, new TagAliasCallback() {
|
||||
@Override
|
||||
public void gotResult(int i, String s, Set<String> set) {
|
||||
if (set == null) {
|
||||
Log.e("initmjsheng", "set is null");
|
||||
} else {
|
||||
Log.e("initmjsheng", "set ---" + set.toString());
|
||||
}
|
||||
Log.e("JPushInterface", s + "---" + i + "---");
|
||||
if (i == 0) {
|
||||
Log.e("JPushInterface", "Tag绑定成功");
|
||||
} else if (i == 6001) {
|
||||
Log.e("JPushInterface", "无效的设置,用户名为空");
|
||||
} else if (i == 6002) {
|
||||
Log.e("JPushInterface", "设置超时,请重试");
|
||||
timerImitate();
|
||||
} else if (i == 6011) {
|
||||
Log.e("JPushInterface", "短时间内操作过于频繁");
|
||||
} else if (i == 996) {
|
||||
Log.e("JPushInterface", "网络连接断开");
|
||||
timerImitate();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("fht", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initJpush() {
|
||||
|
||||
@@ -128,8 +185,7 @@ public class InitJpushServer extends Service {
|
||||
public void call(Long aLong) {
|
||||
Log.e("JPushInterface", "JPushInterface重新加载");
|
||||
initJpush();
|
||||
|
||||
|
||||
setJpushTags();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -594,15 +650,19 @@ public class InitJpushServer extends Service {
|
||||
.params("sn", Utils.getSerial())
|
||||
.params("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress())
|
||||
.params("jpush_id", rid)
|
||||
.params("appstore_version", Utils.getProperty("ro.custom.build.version","获取失败"))
|
||||
.params("store_version", BuildConfig.VERSION_NAME)
|
||||
.execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, Response response) {
|
||||
|
||||
com.alibaba.fastjson.JSONObject msgObject = JSON.parseObject(s);
|
||||
Log.e("fht", "sendMACaddress onSuccess"+s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
Log.e("fht", "sendMACaddress onError:"+e.getMessage());
|
||||
}
|
||||
});
|
||||
{
|
||||
@@ -648,6 +708,7 @@ public class InitJpushServer extends Service {
|
||||
getForceDownload();
|
||||
getSystemSetting();//从后台获取功能状态
|
||||
resetDevice();
|
||||
checkUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,6 +729,10 @@ public class InitJpushServer extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
HTTPInterface.checkUpdate(mHandler, "com.jiaoguanyi.store");
|
||||
}
|
||||
|
||||
private void SettingSysData(JSONObject data) {
|
||||
try {
|
||||
int setting_call = changeNum(data.optInt("setting_call"));
|
||||
@@ -696,21 +761,21 @@ public class InitJpushServer extends Service {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
boolean qch_usb_choose = Settings.System.putString(getApplicationContext().getContentResolver(), "qch_usb_choose", setting_usb);
|
||||
Log.e("SystemSetting", "qch_usb_choose---------" + qch_usb_choose);
|
||||
String usbStatus = "";
|
||||
switch (setting_usb) {
|
||||
case "usb_charge":
|
||||
usbStatus = "qch_action_usb_usb_charge";
|
||||
break;
|
||||
case "usb_mtp":
|
||||
usbStatus = "qch_action_usb_usb_mtp";
|
||||
break;
|
||||
case "usb_midi":
|
||||
usbStatus = "qch_action_usb_usb_midi";
|
||||
break;
|
||||
String usbStatus = "";
|
||||
switch (setting_usb) {
|
||||
case "usb_charge":
|
||||
usbStatus = "qch_action_usb_usb_charge";
|
||||
break;
|
||||
case "usb_mtp":
|
||||
usbStatus = "qch_action_usb_usb_mtp";
|
||||
break;
|
||||
case "usb_midi":
|
||||
usbStatus = "qch_action_usb_usb_midi";
|
||||
break;
|
||||
|
||||
}
|
||||
Intent usbIntent = new Intent(usbStatus);
|
||||
sendBroadcast(usbIntent);
|
||||
}
|
||||
Intent usbIntent = new Intent(usbStatus);
|
||||
sendBroadcast(usbIntent);
|
||||
}
|
||||
|
||||
int setting_bluetooth = changeNum(data.optInt("setting_bluetooth"));
|
||||
@@ -738,22 +803,11 @@ public class InitJpushServer extends Service {
|
||||
|
||||
//状态栏显示开关
|
||||
int setting_statusbar = changeNum(data.optInt("setting_statusbar"));
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(getApplicationContext().getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
|
||||
String statusbarStatus = "";
|
||||
switch (setting_statusbar) {
|
||||
case 0:
|
||||
statusbarStatus = "qch_show_statusBar";
|
||||
break;
|
||||
case 1:
|
||||
statusbarStatus = "qch_hide_statusBar";
|
||||
break;
|
||||
|
||||
int oldNum = Settings.System.getInt(getContentResolver(), "qch_hide_statusBar", 1);
|
||||
if (oldNum != setting_statusbar) {
|
||||
boolean qch_hide_statusBar = Settings.System.putInt(getContentResolver(), "qch_hide_statusBar", setting_statusbar);
|
||||
Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar);
|
||||
}
|
||||
Intent statusIntent = new Intent(statusbarStatus);
|
||||
sendBroadcast(statusIntent);
|
||||
|
||||
//摄像头开关
|
||||
int setting_camera = changeNum(data.optInt("setting_camera"));
|
||||
Log.e("SystemSetting", "setting_camera---------" + setting_camera);
|
||||
@@ -856,4 +910,43 @@ public class InitJpushServer extends Service {
|
||||
return num;
|
||||
}
|
||||
|
||||
private Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 200:
|
||||
com.alibaba.fastjson.JSONObject jsonObject = (com.alibaba.fastjson.JSONObject) msg.obj;
|
||||
installAPK(jsonObject);
|
||||
break;
|
||||
case -200:
|
||||
Log.e("fht", "no update");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private void installAPK(com.alibaba.fastjson.JSONObject jsonObject) {
|
||||
String url = jsonObject.getString("url");
|
||||
int versionCode = jsonObject.getInteger("version_code");
|
||||
String packageName = jsonObject.getString("package");
|
||||
PackageManager pm = getPackageManager();
|
||||
PackageInfo packageInfo = null;
|
||||
try {
|
||||
packageInfo = pm.getPackageInfo(packageName, 0);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (packageInfo == null || packageInfo.versionCode != versionCode) {
|
||||
Aria.download(this)
|
||||
.load(url) //读取下载地址
|
||||
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString(packageName) + ".apk",true)
|
||||
.setExtendField(packageName)
|
||||
.start(); //启动下载}
|
||||
} else {
|
||||
Log.e("fht", "无需更新");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -131,22 +131,22 @@ public class MyDownloadService extends Service {
|
||||
|
||||
if (info.getApp_baoming().equals(Utils.YOUNGSYSTEM_APP_TONGBU) || info.getApp_baoming().equals(MyApplication.getAppContext().getPackageName())) {
|
||||
// ApkUtils.install(MyApplication.getAppContext(), new File(downloadInfo.getTargetPath()));
|
||||
ApkUtils.installApkInSilence(downloadInfo.getTargetPath(), info.getApp_baoming());
|
||||
ApkUtils.installApp(MyDownloadService.this, downloadInfo.getTargetPath());
|
||||
Log.e("fht", "updateTask1");
|
||||
// ApkUtils.updateTask(getApplicationContext());
|
||||
|
||||
}
|
||||
if (downloadURL.contains(downloadInfo.getUrl())) {
|
||||
// ApkUtils.install(MyApplication.getAppContext(), new File(downloadInfo.getTargetPath()));
|
||||
if (ApkUtils.getinstallPackage().equals("") || ApkUtils.isAvailable(getApplicationContext(), ApkUtils.getinstallPackage())) {
|
||||
//没有任务或者任务已经安装
|
||||
Log.e("fht", "task package is installed , install new apk ");
|
||||
ApkUtils.installApkInSilence(downloadInfo.getTargetPath(), info.getApp_baoming());
|
||||
} else {
|
||||
//更新正在安装的信息,更新任务列表
|
||||
ApkUtils.setInstallIngPackageName("");
|
||||
ApkUtils.updateTask(allTask, getApplicationContext());
|
||||
}
|
||||
// if (MyApplication.getInstance().getInstallIngPackageName().equals("") || ApkUtils.isAvailable(getApplicationContext(), MyApplication.getInstance().getInstallIngPackageName())) {
|
||||
//没有任务或者任务已经安装
|
||||
Log.e("fht", "task package is installed , install new apk ");
|
||||
ApkUtils.installApkInSilence(downloadInfo.getTargetPath(), info.getApp_baoming());
|
||||
// } else {
|
||||
// //更新正在安装的信息,更新任务列表
|
||||
// MyApplication.getInstance().setInstallIngPackageName("");
|
||||
// MyApplication.getInstance().updateList();
|
||||
// }
|
||||
|
||||
//有bug,会一直回调
|
||||
Log.e("fht", "updateTask2");
|
||||
@@ -208,7 +208,7 @@ public class MyDownloadService extends Service {
|
||||
// 删除标识 下载地址
|
||||
String URL = intent.getStringExtra("URL");
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
if (downloadInfo != null) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
@@ -297,15 +297,7 @@ public class MyDownloadService extends Service {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_DELETE_URL_ACTION.equals(intent.getAction())) {
|
||||
// 删除标识 下载地址
|
||||
String URL = intent.getStringExtra("URL");
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_DELETE_UPDATE_ACTION.equals(intent.getAction())) {
|
||||
// 删除 应用更新包
|
||||
@@ -362,8 +354,6 @@ public class MyDownloadService extends Service {
|
||||
Intent allIntent = new Intent();
|
||||
allIntent.setAction(Utils.DOWNLOAD_ALLSERVICE_ACTION);
|
||||
allIntent.putExtra("allTask", (Serializable) list);
|
||||
Log.e("fht", "allTask updateTask:" + allTask.size());
|
||||
ApkUtils.updateTask(allTask, getApplicationContext());
|
||||
sendBroadcast(allIntent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,19 @@ import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.lzy.okserver.download.DownloadInfo;
|
||||
import com.mjsheng.myappstore.KeepAliveConnection;
|
||||
import com.mjsheng.myappstore.MyApplication;
|
||||
import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.utils.ApkUtils;
|
||||
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* 主进程 双进程通讯
|
||||
*
|
||||
@@ -59,6 +67,18 @@ public class StepService extends Service {
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
try {
|
||||
final String filePath = intent.getStringExtra("filePath");
|
||||
final String packageName = intent.getStringExtra("packageName");
|
||||
Log.e("fht", filePath);
|
||||
Log.e("fht", packageName);
|
||||
FileData fileData = new FileData(filePath, packageName);
|
||||
MyApplication.getInstance().addFileData(fileData);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("fht", e.getMessage());
|
||||
}
|
||||
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@ import android.widget.Toast;
|
||||
import com.lzy.okserver.download.DownloadInfo;
|
||||
import com.lzy.okserver.download.DownloadManager;
|
||||
import com.lzy.okserver.download.DownloadService;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.AppDownloadInfo;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.download.StorageUtils;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
|
||||
@@ -305,11 +307,58 @@ public class ApkUtils {
|
||||
// Log.e("mjsheng", "安装失败");
|
||||
// }
|
||||
// }
|
||||
public interface InstallCallback {
|
||||
void installInfoCallback(String path, String packageName);
|
||||
}
|
||||
|
||||
public static boolean installApp(Context context, String apkPath) {
|
||||
ToastTool.show("正在安装应用...");
|
||||
Process process = null;
|
||||
BufferedReader successResult = null;
|
||||
BufferedReader errorResult = null;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
try {
|
||||
process = new ProcessBuilder("pm", "install", "-i", BuildConfig.APPLICATION_ID, "--user", "0", apkPath).start();
|
||||
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
String s;
|
||||
while ((s = successResult.readLine()) != null) {
|
||||
successMsg.append(s);
|
||||
}
|
||||
while ((s = errorResult.readLine()) != null) {
|
||||
errorMsg.append(s);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if (successResult != null) {
|
||||
successResult.close();
|
||||
}
|
||||
if (errorResult != null) {
|
||||
errorResult.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
Log.e("result", "" + errorMsg.toString());
|
||||
//如果含有“success”认为安装成功
|
||||
Log.e("installApp", successMsg.toString());
|
||||
if (!successMsg.toString().equalsIgnoreCase("success")) {
|
||||
ApkUtils.install(context, new File(apkPath));
|
||||
}
|
||||
return successMsg.toString().equalsIgnoreCase("success");
|
||||
}
|
||||
|
||||
|
||||
public static void installApkInSilence(String installPath, String packageName) {
|
||||
ToastTool.show("正在安装应用...");
|
||||
setInstallIngPackageName(packageName);
|
||||
|
||||
Class<?> pmService;
|
||||
Class<?> activityTherad;
|
||||
Method method;
|
||||
@@ -380,111 +429,5 @@ public class ApkUtils {
|
||||
return uid / PER_USER_RANGE;
|
||||
}
|
||||
|
||||
private static List<AppDownloadInfo> taskList = new ArrayList<>();
|
||||
public static List<DownloadInfo> alltask;
|
||||
|
||||
static String packageName = "";
|
||||
|
||||
public static void setInstallIngPackageName(String packageNames) {
|
||||
packageName = packageNames;
|
||||
Log.e("fht", "正在安装:" + packageNames);
|
||||
}
|
||||
|
||||
public static String getinstallPackage() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public static boolean isInstalling(String packageNames) {
|
||||
Log.e("fht", "isInstalling:" + packageName);
|
||||
return packageName.equals(packageNames);
|
||||
}
|
||||
|
||||
public static DownloadInfo getDownloadInfoByPackageName(String s) {
|
||||
int x = -1;
|
||||
if (alltask != null && alltask.size() > 0) {
|
||||
for (int i = 0; i < alltask.size(); i++) {
|
||||
DownloadInfo downloadInfo = alltask.get(i);
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
if (dateInfo.getApp_baoming().equals(s)) {
|
||||
x = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x != -1) {
|
||||
return alltask.get(x);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static synchronized public void updateTask(List<DownloadInfo> allTask, Context context) {
|
||||
alltask = allTask;
|
||||
Log.e("fht", "updateTask:" + allTask.size());
|
||||
long time1 = System.currentTimeMillis();
|
||||
List<AppDownloadInfo> list = new ArrayList<>();
|
||||
if (allTask.size() > 0) {
|
||||
for (int i = 0; i < allTask.size(); i++) {
|
||||
DownloadInfo downloadInfo = allTask.get(i);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
if (!dateInfo.getApp_baoming().equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !dateInfo.getApp_baoming().equals(context.getPackageName())) {
|
||||
AppDownloadInfo info = new AppDownloadInfo();
|
||||
info.setFileName(downloadInfo.getFileName());
|
||||
info.setProgress(downloadInfo.getProgress());
|
||||
info.setTargetPath(downloadInfo.getTargetPath());
|
||||
info.setUrl(downloadInfo.getUrl());
|
||||
info.setState(downloadInfo.getState());
|
||||
info.setDownloadLength(downloadInfo.getDownloadLength());
|
||||
info.setTotalLength(downloadInfo.getTotalLength());
|
||||
info.setPackageName(dateInfo.getApp_baoming());
|
||||
info.setVersion(dateInfo.getApp_banben());
|
||||
info.setData(dateInfo);
|
||||
list.add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long time2 = System.currentTimeMillis();
|
||||
Log.e("fht", "time:" + (time2 - time1));
|
||||
taskList = list;
|
||||
if ((packageName.equals("") || isAvailable(context, getinstallPackage())) && taskList.size() > 0 && taskList.get(0).getState() == DownloadManager.FINISH) {
|
||||
if (isAvailable(context, taskList.get(0).getPackageName())) {
|
||||
taskList.remove(0);
|
||||
}
|
||||
if (taskList.size() > 0) {
|
||||
ApkUtils.installApkInSilence(taskList.get(0).getTargetPath(), taskList.get(0).getPackageName());
|
||||
Log.e("fht", "updateTask1:" + taskList.get(0).getPackageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
synchronized public static void removeInfo(String packageName) {
|
||||
Log.e("fht", "removeInfo:" + "taskList.size():" + taskList.size());
|
||||
|
||||
int position = -1;
|
||||
for (int i = 0; i < taskList.size(); i++) {
|
||||
if (packageName.equals(taskList.get(i).getPackageName())) {
|
||||
position = i;
|
||||
}
|
||||
}
|
||||
if (position != -1) {
|
||||
removeInfo(taskList.get(position));
|
||||
} else {
|
||||
setInstallIngPackageName("");
|
||||
Log.e("fht", "position == -1");
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public static void removeInfo(AppDownloadInfo info) {
|
||||
taskList.remove(info);
|
||||
if (taskList != null && taskList.size() > 0) {
|
||||
ApkUtils.installApkInSilence(taskList.get(0).getTargetPath(), taskList.get(0).getPackageName());
|
||||
Log.e("fht", "removeInfo:" + taskList.get(0).getPackageName());
|
||||
} else {
|
||||
setInstallIngPackageName("");
|
||||
Log.e("fht", "任务为空");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -186,4 +186,8 @@ public class Configure {
|
||||
|
||||
public static final String SEND_USEDTIME= HTTP_TAG_HEAD_NEW + "Applog/getAppLog";
|
||||
|
||||
public static final String CHECK_UPDATE= HTTP_TAG_HEAD_NEW + "Silent/silent";
|
||||
//更新接口
|
||||
public static final String GET_DEVICES_TAGS= HTTP_TAG_HEAD_NEW + "Sn/getSnTag";
|
||||
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.NetworkInterface;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -103,6 +104,7 @@ public class Utils {
|
||||
public static final int COUNT_ONE_PAGE2 = 10;
|
||||
public static final String YOUNGSYSTEM_APP_TONGBU = "com.school.app.syn"; // 小学系统 同步教材app
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String number[] = {
|
||||
"1", "2", "3", "4", "5", "6", "7",
|
||||
@@ -154,7 +156,6 @@ public class Utils {
|
||||
// 积分记录 达人标准次数记录
|
||||
|
||||
|
||||
|
||||
// MD5 设备地址标识
|
||||
public static String getMAC(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 如果当前设备系统大于等于6.0 使用下面的方法
|
||||
@@ -715,15 +716,16 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
public static String transferLongToDate(Long millSec){
|
||||
public static String transferLongToDate(Long millSec) {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Date date= new Date(millSec);
|
||||
Date date = new Date(millSec);
|
||||
|
||||
return sdf.format(date);
|
||||
|
||||
}
|
||||
|
||||
public static String getSn() {
|
||||
return Build.SERIAL;
|
||||
}
|
||||
@@ -783,7 +785,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//判断是否为系统应用
|
||||
public static boolean isSystemApp(Context context, String pkgName) {
|
||||
boolean isSystemApp = false;
|
||||
@@ -856,5 +857,18 @@ public class Utils {
|
||||
// return bgBitmap;
|
||||
}
|
||||
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, "unknown"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user