XPJ v3.0.6版本的 MD5 值为:c31c0f1861a74a2223b50f64fc02b761
以下内容为反编译后的 ApkDownInstall.java 源代码,内容仅作参考
package com.aweproject.apkupdata;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.support.v4.content.FileProvider;
import android.util.Log;
import com.aweproject.BuildConfig;
import com.aweproject.MainApplication;
import com.facebook.react.animated.InterpolationAnimatedNode;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
public class ApkDownInstall {
private String downloadUrl;
private String URL_DOWNLOAD_UPDATE_JSON = "https://www.openl.cn/aas/apk.json";
private final String[] PERMISSIONS_STORAGE = {"android.permission.WRITE_EXTERNAL_STORAGE"};
private final int REQUEST_CODE_EXTERNAL_STORAGE = 1;
public ApkDownInstall(String str) {
this.downloadUrl = "";
this.downloadUrl = str;
}
public void checkVersionUpdate(OnUpdateListener onUpdateListener) {
performUpdate(onUpdateListener);
}
private void performUpdate(final OnUpdateListener onUpdateListener) {
try {
new OkHttpClient.Builder().connectTimeout(3L, TimeUnit.SECONDS).readTimeout(10L, TimeUnit.SECONDS).build().newCall(new Request.Builder().url(this.downloadUrl).addHeader("Accept-Encoding", InterpolationAnimatedNode.EXTRAPOLATE_TYPE_IDENTITY).build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException iOException) {
onUpdateListener.onCancelUpdate();
}
@Override
public void onResponse(Call call, Response response) {
if (response == null) {
onUpdateListener.onCancelUpdate();
return;
}
ResponseBody body = response.body();
if (body == null) {
onUpdateListener.onCancelUpdate();
return;
}
long contentLength = body.contentLength();
if (contentLength != -1) {
new UpdateFile(false, ApkDownInstall.this.downloadUrl, contentLength);
onUpdateListener.onUpdate();
} else {
onUpdateListener.onCancelUpdate();
}
}
});
} catch (Exception unused) {
onUpdateListener.onCancelUpdate();
}
}
public void updateByApkOrPatch(final OnUpdateListener onUpdateListener) {
try {
final String str = (Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + BuildConfig.FLAVOR.toUpperCase()) + File.separator + "apk";
if (!new File(str).exists()) {
new File(str).mkdirs();
}
new Thread(new Runnable() {
@Override
public void run() {
Log.e("DownloadUpdateDialog", "开始下载");
final PowerManager.WakeLock newWakeLock = ((PowerManager) MainApplication.getInstance().getApplicationContext().getSystemService("power")).newWakeLock(10, "flag_download_update_file");
newWakeLock.acquire();
DownloadUtils.download(ApkDownInstall.this.downloadUrl, str, "update.apk", new OnDownloadListener() {
@Override
public void onDownloadSuccess(File file) {
if (newWakeLock.isHeld()) {
newWakeLock.release();
}
Log.e("DownloadUpdateDialog", "成功下载" + file.toString());
onUpdateListener.onProgress(100.0f);
ApkDownInstall.install(MainApplication.getInstance().getApplicationContext(), file);
}
@Override
public void onDownloadProgress(float f) {
onUpdateListener.onProgress(f);
Log.e("DownloadUpdateDialog", "进度" + f);
}
@Override
public void onDownloadFailure(Exception exc) {
if (newWakeLock.isHeld()) {
newWakeLock.release();
}
onUpdateListener.onCancelUpdate();
Log.e("DownloadUpdateDialog", "下载失败" + exc.toString());
}
});
}
}).start();
} catch (Exception unused) {
}
}
public static void install(Context context, File file) {
try {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
if (Build.VERSION.SDK_INT >= 24) {
intent.setFlags(268435456);
Uri uriForFile = FileProvider.getUriForFile(context, MainApplication.getInstance().getPackageName() + ".fileprovider", file);
intent.setDataAndType(uriForFile, "application/vnd.android.package-archive");
Iterator<ResolveInfo> it = MainApplication.getInstance().getPackageManager().queryIntentActivities(intent, 65536).iterator();
while (it.hasNext()) {
String str = it.next().activityInfo.packageName;
MainApplication.getInstance().grantUriPermission(str, uriForFile, 2);
MainApplication.getInstance().grantUriPermission(str, uriForFile, 1);
}
} else {
Uri fromFile = Uri.fromFile(file);
intent.setFlags(268435456);
intent.setDataAndType(fromFile, "application/vnd.android.package-archive");
}
context.startActivity(intent);
Process.killProcess(Process.myPid());
} catch (Exception e) {
Log.i("xxxx", "install exception:" + e.toString());
}
}
}