DownloadEntry修改为DownloadEntity
This commit is contained in:
@ -35,6 +35,7 @@ import com.android.volley.VolleyError;
|
||||
import com.gh.base.AppController;
|
||||
import com.gh.base.BaseFragmentActivity;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.constant.Constants;
|
||||
import com.gh.common.util.DataUtils;
|
||||
import com.gh.common.util.DialogUtils;
|
||||
import com.gh.common.util.FileUtils;
|
||||
@ -45,22 +46,27 @@ import com.gh.common.util.PlatformUtils;
|
||||
import com.gh.common.util.RandomUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.common.util.SpeedUtils;
|
||||
import com.gh.common.util.TimestampUtils;
|
||||
import com.gh.common.util.Utils;
|
||||
import com.gh.download.DataWatcher;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadEntity;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.download.DownloadStatus;
|
||||
import com.gh.gamecenter.db.info.ConcernInfo;
|
||||
import com.gh.gamecenter.db.info.GameInfo;
|
||||
import com.gh.gamecenter.db.info.SuspectedGameInfo;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.AppEntity;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.entity.GameUpdateEntity;
|
||||
import com.gh.gamecenter.eventbus.EBDownloadStatus;
|
||||
import com.gh.gamecenter.eventbus.EBPackage;
|
||||
import com.gh.gamecenter.eventbus.EBPutUrl;
|
||||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||||
import com.gh.gamecenter.eventbus.EBSkip;
|
||||
import com.gh.gamecenter.eventbus.EBTopStatus;
|
||||
import com.gh.gamecenter.eventbus.EBUISwitch;
|
||||
import com.gh.gamecenter.game.Game1Fragment;
|
||||
import com.gh.gamecenter.game.GameFragment;
|
||||
import com.gh.gamecenter.manager.ConcernManager;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
@ -84,6 +90,8 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
@ -102,8 +110,7 @@ import de.greenrobot.event.EventBus;
|
||||
* @update 2015-8-11
|
||||
* @des 项目的主Activity,3个Fragment都嵌入在这里。
|
||||
*/
|
||||
public class MainActivity extends BaseFragmentActivity implements
|
||||
OnClickListener {
|
||||
public class MainActivity extends BaseFragmentActivity implements OnClickListener {
|
||||
|
||||
public static ArrayMap<String, String> uninstallMap;
|
||||
public static String searchHint;
|
||||
@ -134,127 +141,89 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
// 黄壮华 添加观察者 修改2015/8/15
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntry downloadEntry) {
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
// 链接被劫持
|
||||
if (DownloadStatus.hijack.equals(downloadEntry.getStatus())) {
|
||||
// 删除任务
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntry.getUrl());
|
||||
// 弹出提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("hijack"));
|
||||
//记录链接被劫持
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("url", downloadEntry.getUrl());
|
||||
map.put("game", downloadEntry.getName());
|
||||
map.put("platform", downloadEntry.getMeta().get("platform"));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(MainActivity.this, "hijack", map);
|
||||
if (DownloadStatus.hijack.equals(downloadEntity.getStatus())) {
|
||||
processHijack(downloadEntity);
|
||||
return;
|
||||
}
|
||||
if (downloadEntry.getName().contains("光环助手") && isShowDownload) {
|
||||
app_tv_speed.setText(String.format("%s(剩%s)",
|
||||
SpeedUtils.getSpeed(downloadEntry.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(), downloadEntry.getSpeed() * 1024)));
|
||||
app_pb_progress.setProgress((int) (downloadEntry
|
||||
.getPercent() * 10));
|
||||
app_tv_percent.setText(downloadEntry.getPercent() + "%");
|
||||
if (DownloadStatus.done.equals(downloadEntry.getStatus())) {
|
||||
DownloadManager.getInstance(getApplicationContext())
|
||||
.cancel(downloadEntry.getUrl(), false);
|
||||
dialog.dismiss();
|
||||
isShowDownload = false;
|
||||
}
|
||||
if (downloadEntity.getName().contains("光环助手") && isShowDownload) {
|
||||
processGhAssistDownload(downloadEntity);
|
||||
}
|
||||
if (DownloadStatus.done.equals(downloadEntry.getStatus())) {
|
||||
if (downloadEntry.getName().contains("光环助手")) {
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
if (downloadEntity.getName().contains("光环助手")) {
|
||||
DataUtils.onEvent(MainActivity.this, "软件更新", "下载完成");
|
||||
startActivity(PackageUtils
|
||||
.getInstallIntent(downloadEntry.getPath()));
|
||||
startActivity(PackageUtils.getInstallIntent(downloadEntity.getPath()));
|
||||
if (appEntity != null && appEntity.isIs_force()) {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
|
||||
Map<String, Object> kv = new HashMap<>();
|
||||
kv.put("版本", downloadEntry.getMeta().get("platform"));
|
||||
kv.put("版本", downloadEntity.getPlatform());
|
||||
kv.put("状态", "下载完成");
|
||||
|
||||
String isUpdate = downloadEntry.getMeta().get("isUpdate");
|
||||
String entrance = downloadEntry.getMeta().get("entrance");
|
||||
if (isUpdate != null && "true".equals(isUpdate)) {
|
||||
String entrance = downloadEntity.getEntrance();
|
||||
if (downloadEntity.isUpdate()) {
|
||||
DataUtils.onEvent(MainActivity.this, "游戏更新",
|
||||
downloadEntry.getName(), kv);
|
||||
downloadEntity.getName(), kv);
|
||||
} else {
|
||||
DataUtils.onEvent(MainActivity.this, "游戏下载",
|
||||
downloadEntry.getName(), kv);
|
||||
downloadEntity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<>();
|
||||
kv2.put("版本",
|
||||
downloadEntry.getMeta().get("platform"));
|
||||
kv2.put("版本", downloadEntity.getPlatform());
|
||||
kv2.put("状态", "下载完成");
|
||||
kv2.put("位置", entrance + "-完成");
|
||||
DataUtils.onEvent(MainActivity.this, "游戏下载位置",
|
||||
downloadEntry.getName(), kv2);
|
||||
downloadEntity.getName(), kv2);
|
||||
}
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("下载", "下载完成");
|
||||
kv6.put("版本",
|
||||
downloadEntry.getMeta().get("platform"));
|
||||
kv6.put("版本", downloadEntity.getPlatform());
|
||||
DataUtils.onEvent(MainActivity.this, "插件化",
|
||||
downloadEntry.getName(), kv6);
|
||||
downloadEntity.getName(), kv6);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("game", downloadEntry.getName());
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
map.put("game", downloadEntity.getName());
|
||||
if (downloadEntity.isPluggable()) {
|
||||
map.put("method", "插件化");
|
||||
} else {
|
||||
map.put("method", "正常");
|
||||
}
|
||||
map.put("platform",
|
||||
PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
downloadEntry.getMeta()
|
||||
.get("platform")));
|
||||
map.put("platform", PlatformUtils.getInstance(getApplicationContext())
|
||||
.getPlatformName(downloadEntity.getPlatform()));
|
||||
map.put("status", "完成");
|
||||
map.put("location",
|
||||
downloadEntry.getMeta().get("location"));
|
||||
map.put("location", downloadEntity.getLocation());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils
|
||||
.getConnectedType(MainActivity.this));
|
||||
map.put("createdOn",
|
||||
System.currentTimeMillis() / 1000);
|
||||
map.put("network", NetworkUtils.getConnectedType(MainActivity.this));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(MainActivity.this, "download", map);
|
||||
|
||||
entryMap.put(PackageUtils.getPackageNameByPath(
|
||||
getApplicationContext(),
|
||||
downloadEntry.getPath()), downloadEntry
|
||||
downloadEntity.getPath()), downloadEntity
|
||||
.getUrl());
|
||||
|
||||
if (RunningUtils
|
||||
.isApplicationBroughtToBackground(getApplicationContext())) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (RunningUtils.isApplicationBroughtToBackground(getApplicationContext())) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
NotificationManager nManager = (NotificationManager) getSystemService(
|
||||
Context.NOTIFICATION_SERVICE);
|
||||
|
||||
String path = downloadEntry.getPath();
|
||||
String path = downloadEntity.getPath();
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("path", path);
|
||||
intent.setAction("com.gh.gamecenter.UNINSTALL");
|
||||
PendingIntent pendingIntent = PendingIntent
|
||||
.getBroadcast(MainActivity.this, 0,
|
||||
intent,
|
||||
.getBroadcast(MainActivity.this, 0, intent,
|
||||
PendingIntent.FLAG_ONE_SHOT);
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
downloadEntry.getMeta()
|
||||
.get("platform"));
|
||||
String title = downloadEntry.getName()
|
||||
+ " - " + platform;
|
||||
.getInstance(getApplicationContext())
|
||||
.getPlatformName(downloadEntity.getPlatform());
|
||||
String title = downloadEntity.getName() + " - " + platform;
|
||||
|
||||
Notification notification = new NotificationCompat.Builder(
|
||||
MainActivity.this)
|
||||
@ -271,46 +240,42 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
((int) System.currentTimeMillis() / 1000),
|
||||
notification);
|
||||
|
||||
uninstallMap.put(PackageUtils
|
||||
.getPackageNameByPath(
|
||||
getApplicationContext(),
|
||||
path), path);
|
||||
uninstallMap.put(PackageUtils.getPackageNameByPath(
|
||||
getApplicationContext(), path), path);
|
||||
}
|
||||
} else {
|
||||
String platform = PlatformUtils.getInstance(
|
||||
getApplicationContext())
|
||||
.getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
downloadEntity.getPlatform());
|
||||
if (platform != null) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin", downloadEntry
|
||||
.getPath()));
|
||||
if (downloadEntity.isPluggable()) {
|
||||
EventBus.getDefault().post(new EBShowDialog("plugin",
|
||||
downloadEntity.getPath()));
|
||||
} else if (platform.equals("官方版")) {
|
||||
toast(downloadEntry.getName() + " - 下载完成");
|
||||
toast(downloadEntity.getName() + " - 下载完成");
|
||||
} else {
|
||||
toast(downloadEntry.getName()
|
||||
+ " - " + platform + " - 下载完成");
|
||||
toast(downloadEntity.getName() + " - " + platform + " - 下载完成");
|
||||
}
|
||||
} else {
|
||||
toast(downloadEntry.getName() + " - 下载完成");
|
||||
toast(downloadEntity.getName() + " - 下载完成");
|
||||
}
|
||||
if (downloadEntry.getMeta().get("isPlugin") == null) {
|
||||
if (downloadEntity.isPluggable()) {
|
||||
if (sp.getBoolean("autoinstall", true)) {
|
||||
if (FileUtils.isEmptyFile(downloadEntry.getPath())) {
|
||||
if (FileUtils.isEmptyFile(downloadEntity.getPath())) {
|
||||
toast("解析包错误");
|
||||
} else {
|
||||
PackageManager manager = new PackageManager(
|
||||
getApplicationContext());
|
||||
if (manager.launchSetup(downloadEntry.getPath())) {
|
||||
if (manager.launchSetup(downloadEntity.getPath())) {
|
||||
startActivity(PackageUtils
|
||||
.getInstallIntent(downloadEntry
|
||||
.getInstallIntent(downloadEntity
|
||||
.getPath()));
|
||||
} else {
|
||||
// 记录自动弹出卸载框
|
||||
// 弹出卸载提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("delete", downloadEntry
|
||||
.getPath()));
|
||||
EventBus.getDefault().post(new EBShowDialog("delete",
|
||||
downloadEntity.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -319,22 +284,45 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
|
||||
// 统计下载完成
|
||||
uploadData(downloadEntry.getMeta().get("gameId"),
|
||||
downloadEntry.getMeta().get("platform"));
|
||||
uploadData(downloadEntity.getGameId(), downloadEntity.getPlatform());
|
||||
}
|
||||
} else {
|
||||
Utils.log("It is already done!");
|
||||
DataUtils.onEvent(
|
||||
MainActivity.this,
|
||||
"多次弹框数据",
|
||||
downloadEntry.getName()
|
||||
+ "-"
|
||||
+ downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
DataUtils.onEvent(MainActivity.this, "多次弹框数据",
|
||||
downloadEntity.getName() + "-" + downloadEntity.getPlatform());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void processGhAssistDownload(DownloadEntity downloadEntity) {
|
||||
app_tv_speed.setText(String.format("%s(剩%s)",
|
||||
SpeedUtils.getSpeed(downloadEntity.getSpeed()),
|
||||
SpeedUtils.getRemainTime(downloadEntity.getSize(),
|
||||
downloadEntity.getProgress(), downloadEntity.getSpeed() * 1024)));
|
||||
app_pb_progress.setProgress((int) (downloadEntity.getPercent() * 10));
|
||||
app_tv_percent.setText(downloadEntity.getPercent() + "%");
|
||||
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
|
||||
DownloadManager.getInstance(getApplicationContext())
|
||||
.cancel(downloadEntity.getUrl(), false);
|
||||
dialog.dismiss();
|
||||
isShowDownload = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void processHijack(DownloadEntity downloadEntity) {
|
||||
// 删除任务
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(downloadEntity.getUrl());
|
||||
// 弹出提示框
|
||||
EventBus.getDefault().post(new EBShowDialog("hijack"));
|
||||
//记录链接被劫持
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("url", downloadEntity.getUrl());
|
||||
map.put("game", downloadEntity.getName());
|
||||
map.put("platform", downloadEntity.getPlatform());
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(MainActivity.this, "hijack", map);
|
||||
}
|
||||
|
||||
/*
|
||||
* 黄壮华 按连续按返回键两次才退出应用
|
||||
*/
|
||||
@ -367,6 +355,7 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// 初始化gameMap
|
||||
DownloadManager.getInstance(this).initGameMap();
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
@ -411,6 +400,7 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
// 初始化PlatformUtils
|
||||
PlatformUtils.getInstance(getApplicationContext());
|
||||
|
||||
// 添加观察者
|
||||
DownloadManager.getInstance(this).addObserver(dataWatcher);
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
@ -433,12 +423,198 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
//检查是否存在更新的dex包
|
||||
checkHotfix();
|
||||
// //检查是否存在更新的dex包
|
||||
// checkHotfix();
|
||||
|
||||
// 检查游戏更新
|
||||
checkGameUpdate();
|
||||
|
||||
// 检查可插件化游戏
|
||||
checkGamePlugin();
|
||||
|
||||
Log.e("TD_CHANNEL_ID", (String) PackageUtils.getMetaData(this, getPackageName(), "TD_CHANNEL_ID"));
|
||||
}
|
||||
|
||||
private void checkGameUpdate() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
for (ConcernInfo info : infos) {
|
||||
for (String packageName : info.getPackageNames().keySet()) {
|
||||
if (info.getPackageNames().get(packageName)) {
|
||||
list.add(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Comparator<String> comparator = new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String lhs, String rhs) {
|
||||
return lhs.compareTo(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
Collections.sort(list, comparator);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
String packages;
|
||||
PackageManager.clearUpdateList();
|
||||
for (int i = 0, sizei = (list.size() / 10) + 1; i < sizei; i++) {
|
||||
builder.delete(0, builder.length());
|
||||
for (int j = i * 10, sizej = (i + 1) * 10 > list.size() ? list
|
||||
.size() : (i + 1) * 10; j < sizej; j++) {
|
||||
builder.append(list.get(j));
|
||||
builder.append("-");
|
||||
}
|
||||
if (builder.length() != 0) {
|
||||
packages = builder.substring(0, builder.length() - 1);
|
||||
JsonArrayExtendedRequest request = new JsonArrayExtendedRequest(
|
||||
Config.HOST + "v1d45/support/package/update?package="
|
||||
// Config.HOST + "v1d45/support/package/latest?package="
|
||||
+ packages, new Response.Listener<JSONArray>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(JSONArray response) {
|
||||
|
||||
Utils.log("getUpdateList=" + response.toString());
|
||||
if (response.length() != 0) {
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<ArrayList<GameUpdateEntity>>() {}.getType();
|
||||
ArrayList<GameUpdateEntity> games = gson.fromJson(response.toString(), listType);
|
||||
GameUpdateEntity gameUpdateEntity;
|
||||
for (int i = 0; i < games.size(); i++) {
|
||||
gameUpdateEntity = games.get(i);
|
||||
// 判断是否gh_version是否相同
|
||||
String gh_version = (String) PackageUtils
|
||||
.getMetaData(MainActivity.this, gameUpdateEntity.getPackageName(), "gh_version");
|
||||
if (gh_version != null) {
|
||||
gh_version = gh_version.substring(2);
|
||||
// 判断gh_version是否相同
|
||||
if (gh_version.equals(gameUpdateEntity.getGhVersion())) {
|
||||
// 判断version是否相同
|
||||
String version = PackageUtils
|
||||
.getVersionByPackage(MainActivity.this, gameUpdateEntity.getPackageName());
|
||||
if (version != null && version.equals(gameUpdateEntity.getVersion())) {
|
||||
// 版本相同,无需显示插件更新,继续查看是否有可更新的游戏包
|
||||
games.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
games.get(i).setPluggable(true);
|
||||
}
|
||||
}
|
||||
PackageManager.addUpdateList(games);
|
||||
|
||||
EventBus.getDefault().post(new EBDownloadStatus("update"));
|
||||
}
|
||||
}
|
||||
}, new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, MainActivity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int count;
|
||||
|
||||
private void addCount() {
|
||||
synchronized (MainActivity.class) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkGamePlugin() {
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
final int size = infos.size();
|
||||
final List<GameEntity> list = new ArrayList<>();
|
||||
count = 0;
|
||||
for (ConcernInfo info : infos) {
|
||||
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
||||
TimestampUtils.addTimestamp(Config.HOST + "v1d45/game/"
|
||||
+ info.getId() + "/digest", Constants.GAME_CD),
|
||||
new Response.Listener<JSONObject>() {
|
||||
@Override
|
||||
public void onResponse(JSONObject response) {
|
||||
Gson gson = new Gson();
|
||||
GameEntity gameEntity = gson.fromJson(response.toString(), GameEntity.class);
|
||||
list.add(gameEntity);
|
||||
addCount();
|
||||
if (count == size) {
|
||||
processPluginData(list);
|
||||
}
|
||||
}
|
||||
},
|
||||
new Response.ErrorListener() {
|
||||
@Override
|
||||
public void onErrorResponse(VolleyError error) {
|
||||
addCount();
|
||||
if (count == size) {
|
||||
processPluginData(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
AppController.addToRequestQueue(request, Game1Fragment.class);
|
||||
}
|
||||
}
|
||||
|
||||
private void processPluginData(List<GameEntity> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ConcernManager concernManager = new ConcernManager(this);
|
||||
PackageManager mPackageManager = new PackageManager(this);
|
||||
List<ConcernInfo> infos = concernManager.getInstalledGame();
|
||||
HashMap<String, Boolean> map;
|
||||
GameEntity gameEntity;
|
||||
for (ConcernInfo info : infos) {
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
gameEntity = list.get(i);
|
||||
if (gameEntity.getId().equals(info.getId())
|
||||
&& gameEntity.getTag() != null && gameEntity.getTag().size() != 0
|
||||
&& gameEntity.getApk() != null) {
|
||||
map = info.getPackageNames();
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key) && !mPackageManager.isSignature(key)) {
|
||||
for (ApkEntity apkEntity : gameEntity.getApk()) {
|
||||
if (apkEntity.getPackageName().equals(key)) {
|
||||
GameUpdateEntity gameUpdateEntity = new GameUpdateEntity();
|
||||
gameUpdateEntity.setId(gameEntity.getId());
|
||||
gameUpdateEntity.setIcon(gameEntity.getIcon());
|
||||
gameUpdateEntity.setName(gameEntity.getName());
|
||||
gameUpdateEntity.setPackageName(apkEntity.getPackageName());
|
||||
gameUpdateEntity.setSize(apkEntity.getSize());
|
||||
gameUpdateEntity.setVersion(apkEntity.getVersion());
|
||||
gameUpdateEntity.setGhVersion(apkEntity.getGhVersion());
|
||||
gameUpdateEntity.setUrl(apkEntity.getUrl());
|
||||
gameUpdateEntity.setPlatform(apkEntity.getPlatform());
|
||||
gameUpdateEntity.setEtag(apkEntity.getEtag());
|
||||
gameUpdateEntity.setPluggable(true);
|
||||
gameUpdateEntity.setTag(gameEntity.getTag());
|
||||
gameUpdateEntity.setBrief(gameEntity.getBrief());
|
||||
|
||||
PackageManager.addUpdate(gameUpdateEntity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
GameManager manager = new GameManager(this);
|
||||
manager.addOrUpdate(gameEntity.getApk(), gameEntity.getId(),
|
||||
gameEntity.getName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
EventBus.getDefault().post(new EBDownloadStatus("plugin"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@ -850,27 +1026,23 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
|
||||
String path = FileUtils.getDownloadPath(MainActivity.this, "光环助手V"
|
||||
+ appEntity.getVersion() + "_" + md5 + ".apk");
|
||||
|
||||
File file = new File(path);
|
||||
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
DownloadEntry downloadEntry = new DownloadEntry();
|
||||
downloadEntry.setUrl(appEntity.getUrl());
|
||||
downloadEntry.setName("光环助手V" + appEntity.getVersion());
|
||||
downloadEntry.setPath(path);
|
||||
HashMap<String, String> meta = new HashMap<>();
|
||||
meta.put("platform", "官方版");
|
||||
downloadEntry.setMeta(meta);
|
||||
DownloadEntity downloadEntity = new DownloadEntity();
|
||||
downloadEntity.setUrl(appEntity.getUrl());
|
||||
downloadEntity.setName("光环助手V" + appEntity.getVersion());
|
||||
downloadEntity.setPath(path);
|
||||
downloadEntity.setPlatform("官方版");
|
||||
|
||||
DownloadManager.getInstance(getApplicationContext()).cancel(
|
||||
downloadEntry.getUrl(), false);
|
||||
downloadEntity.getUrl(), false);
|
||||
|
||||
DownloadManager.getInstance(getApplicationContext()).pauseAll();
|
||||
|
||||
DownloadManager.getInstance(getApplicationContext()).add(downloadEntry);
|
||||
DownloadManager.getInstance(getApplicationContext()).add(downloadEntity);
|
||||
}
|
||||
|
||||
// 获取META-INF中的plugin_update 文件,判断是否从游戏插件中下载的app,是则获取游戏id,启动游戏更新,下载该游戏
|
||||
@ -1107,13 +1279,12 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
if (url != null) {
|
||||
entryMap.remove(packageName);
|
||||
|
||||
DownloadEntry downloadEntry = DownloadManager.getInstance(
|
||||
DownloadEntity downloadEntity = DownloadManager.getInstance(
|
||||
getApplicationContext()).get(url);
|
||||
if (downloadEntry != null
|
||||
&& downloadEntry.getMeta().get("isPlugin") != null) {
|
||||
if (downloadEntity != null && downloadEntity.isPluggable()) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "安装完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
|
||||
DataUtils.onEvent(this, "插件化", downloadEntity.getName(), kv6);
|
||||
}
|
||||
|
||||
// 删除数据库 和 文件
|
||||
@ -1122,14 +1293,13 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
}
|
||||
} else if ("卸载".equals(busFour.getType())) {
|
||||
try {
|
||||
for (DownloadEntry downloadEntry : DownloadManager.getInstance(
|
||||
for (DownloadEntity downloadEntity : DownloadManager.getInstance(
|
||||
getApplicationContext()).getAll()) {
|
||||
if (downloadEntry.getMeta().get("isPlugin") != null
|
||||
&& downloadEntry.getMeta().get("package_name")
|
||||
.equals(packageName)) {
|
||||
if (downloadEntity.isPluggable()
|
||||
&& packageName.equals(downloadEntity.getPackageName())) {
|
||||
Map<String, Object> kv6 = new HashMap<>();
|
||||
kv6.put("安装或卸载", "卸载完成");
|
||||
DataUtils.onEvent(this, "插件化", downloadEntry.getName(), kv6);
|
||||
DataUtils.onEvent(this, "插件化", downloadEntity.getName(), kv6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1181,7 +1351,7 @@ public class MainActivity extends BaseFragmentActivity implements
|
||||
int index = -1;
|
||||
for (int i = 0, size = list.size(); i < size; i++) {
|
||||
game = list.get(i);
|
||||
if (!game.isPlugin()) {
|
||||
if (!game.isPluggable()) {
|
||||
continue;
|
||||
}
|
||||
if (game.getPackageName().equals(packageName)) {
|
||||
|
||||
Reference in New Issue
Block a user