正在查看: xDrip+ v04633772025.07.16 应用的 UpdateActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 UpdateActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utilitymodels;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Switch;
import android.widget.TextView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import com.eveningoutpost.dexdrip.BaseAppCompatActivity;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.models.UserError;
import com.eveningoutpost.dexdrip.xdrip;
import java.io.File;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
public class UpdateActivity extends BaseAppCompatActivity {
private static String CHECKSUM = "";
private static String DOWNLOAD_URL = "";
private static int FILE_SIZE = -1;
private static String MESSAGE = "";
private static boolean downloading = false;
private static OkHttpClient httpClient = null;
private static String lastDigest = "";
public static long last_check_time;
private static int newversion;
private static SharedPreferences prefs;
private static int versionnumber;
private File dest_file;
private ScrollView mScrollView;
private ProgressBar progressBar;
private TextView progressText;
private TextView updateMessageText;
public static void checkForAnUpdate(Context context) {
checkForAnUpdate(context, false);
}
public static void checkForAnUpdate(final Context context, final boolean z) {
String str;
if (prefs == null) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
}
if (last_check_time == -1 || prefs.getBoolean("auto_update_download", true)) {
if (last_check_time == 0) {
last_check_time = prefs.getLong("last_update_check_time", 0L);
}
if (JoH.tsl() - last_check_time <= 172600000) {
return;
}
last_check_time = JoH.tsl();
prefs.edit().putLong("last_update_check_time", last_check_time).apply();
String string = prefs.getString("update_channel", "beta");
Log.i("jamorham update", "Checking for a software update, channel: " + string);
if (context.getString(2131755147).equals("xDrip+")) {
str = "";
} else {
str = context.getString(2131755147).replaceAll("[^a-zA-Z0-9]", "");
Log.d("jamorham update", "Using subversion: " + str);
}
StringBuilder sb = new StringBuilder();
sb.append(context.getString(PersistentStore.incrementLong("UP_LOAD_BALANCER") % 2 == 1 ? 2131756156 : 2131757053));
sb.append("/update-check/");
sb.append(string);
sb.append(str);
final String sb2 = sb.toString();
DOWNLOAD_URL = "";
newversion = 0;
new Thread(new Runnable() {
@Override
public final void run() {
UpdateActivity.lambda$checkForAnUpdate$0(context, sb2, z);
}
}).start();
}
}
public static void lambda$checkForAnUpdate$0(android.content.Context r9, java.lang.String r10, boolean r11) {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity.lambda$checkForAnUpdate$0(android.content.Context, java.lang.String, boolean):void");
}
public static void forceUpdateCheckNow() {
JoH.static_toast_long(xdrip.gs(2131755319));
last_check_time = -2L;
checkForAnUpdate(xdrip.getAppContext());
}
public static boolean testAndSetNightly(boolean z) {
boolean matches = Pref.getString("update_channel", "").matches("nightly");
if (!matches && z) {
Pref.setString("update_channel", "nightly");
forceUpdateCheckNow();
}
return matches;
}
public static String getDownloadFolder() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
}
private static void getVersionInformation(Context context) {
if (versionnumber == 0) {
versionnumber = 2125071614;
}
}
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
setContentView(2131492949);
JoH.fixActionBar(this);
this.progressText = (TextView) findViewById(2131296866);
this.progressBar = (ProgressBar) findViewById(2131296860);
this.progressText.setVisibility(4);
this.progressBar.setVisibility(4);
this.mScrollView = (ScrollView) findViewById(2131297158);
this.updateMessageText = (TextView) findViewById(2131297161);
Switch r5 = (Switch) findViewById(2131296371);
r5.setChecked(prefs.getBoolean("auto_update_download", true));
r5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
UpdateActivity.prefs.edit().putBoolean("auto_update_download", z).commit();
Log.d("jamorham update", "Auto Updates IsChecked:" + z);
}
});
CheckBox checkBox = (CheckBox) findViewById(2131296683);
checkBox.setChecked(prefs.getBoolean("use_internal_downloader", true));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
UpdateActivity.prefs.edit().putBoolean("use_internal_downloader", z).commit();
Log.d("jamorham update", "Use internal downloader IsChecked:" + z);
}
});
((TextView) findViewById(2131297160)).setText(getString(2131755882) + Integer.toString(newversion) + "\n" + getString(2131755957) + Integer.toString(versionnumber));
TextView textView = (TextView) findViewById(2131297159);
StringBuilder sb = new StringBuilder();
sb.append(getString(2131756945));
sb.append(JoH.ucFirst(prefs.getString("update_channel", "beta")));
textView.setText(sb.toString());
this.updateMessageText.setText(MESSAGE);
}
public void closeActivity(View view) {
downloading = false;
finish();
}
private boolean checkPermissions() {
if (ContextCompat.checkSelfPermission(getApplicationContext(), "android.permission.WRITE_EXTERNAL_STORAGE") == 0) {
return true;
}
ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE"}, 105);
return false;
}
@Override
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
if (i == 105) {
if (iArr.length > 0 && iArr[0] == 0) {
downloadNow(null);
} else {
JoH.static_toast_long(this, "Cannot download without storage permission");
}
}
}
public void downloadNow(View view) {
if (DOWNLOAD_URL.length() > 0) {
if (prefs.getBoolean("use_internal_downloader", true)) {
if (checkPermissions()) {
if (downloading) {
JoH.static_toast_long(this, "Already downloading!");
} else {
downloading = true;
JoH.static_toast_long(this, "Attempting background download...");
this.mScrollView.post(new Runnable() {
@Override
public void run() {
UpdateActivity.this.mScrollView.fullScroll(130);
}
});
new AsyncDownloader().executeOnExecutor(xdrip.executor, new Void[0]);
}
} else {
JoH.static_toast_long(this, "Need permission to download file");
}
} else {
viewIntentDownload(DOWNLOAD_URL);
finish();
}
} else {
Log.e("jamorham update", "Download button pressed but no download URL");
}
PersistentStore.setBoolean("xdrip-update-notification-pending", false);
JoH.cancelNotification(2005);
}
public void viewIntentDownload(String str) {
startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str + "&rr=" + JoH.tsl())));
}
private class AsyncDownloader extends AsyncTask<Void, Long, Boolean> {
private final String URL;
private final OkHttpClient client;
private String filename;
private final OkHttpClient.Builder okbuilder;
private AsyncDownloader() {
this.URL = UpdateActivity.DOWNLOAD_URL + "&rr=" + JoH.tsl();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
TimeUnit timeUnit = TimeUnit.SECONDS;
OkHttpClient.Builder followSslRedirects = builder.connectTimeout(15L, timeUnit).readTimeout(30L, timeUnit).writeTimeout(30L, timeUnit).followRedirects(true).followSslRedirects(true);
this.okbuilder = followSslRedirects;
this.client = OkHttpWrapper.enableTls12OnPreLollipop(followSslRedirects).build();
}
@Override
public java.lang.Boolean doInBackground(java.lang.Void... r17) {
throw new UnsupportedOperationException("Method not decompiled: com.eveningoutpost.dexdrip.utilitymodels.UpdateActivity.AsyncDownloader.doInBackground(java.lang.Void[]):java.lang.Boolean");
}
@Override
public void onProgressUpdate(Long... lArr) {
UpdateActivity.this.progressText.setVisibility(0);
UpdateActivity.this.progressBar.setVisibility(0);
UpdateActivity.this.progressBar.setMax(lArr[1].intValue());
UpdateActivity.this.progressBar.setProgress(lArr[0].intValue());
long longValue = lArr[0].longValue() / 1024;
long longValue2 = lArr[1].longValue() / 1024;
if (lArr[1].longValue() > 0) {
UpdateActivity.this.progressText.setText(String.format("%d / %d KB", Long.valueOf(longValue), Long.valueOf(longValue2)));
} else {
UpdateActivity.this.progressText.setText(String.format("%d KB", Long.valueOf(longValue)));
}
}
@Override
public void onPostExecute(Boolean bool) {
UpdateActivity.this.progressText.setText(bool.booleanValue() ? "Downloaded" : "Failed");
boolean unused = UpdateActivity.downloading = false;
if (bool.booleanValue()) {
String str = this.filename;
if (str == null || str.length() <= 5 || UpdateActivity.this.dest_file == null) {
return;
}
if (UpdateActivity.CHECKSUM.length() == 0 || UpdateActivity.lastDigest.length() == 0 || UpdateActivity.CHECKSUM.equals(UpdateActivity.lastDigest)) {
try {
try {
((DownloadManager) UpdateActivity.this.getSystemService("download")).addCompletedDownload(this.filename, "xDrip+ update version " + UpdateActivity.newversion, false, "application/vnd.android.package-archive", UpdateActivity.getDownloadFolder() + "/" + this.filename, UpdateActivity.FILE_SIZE, true);
} catch (Exception e) {
Log.e("jamorham update", "Download manager error: " + e);
}
Intent intent = new Intent("android.intent.action.VIEW");
intent.setFlags(268435456);
intent.setDataAndType(FileProvider.getUriForFile(UpdateActivity.this.getApplicationContext(), "com.eveningoutpost.dexdrip.provider", UpdateActivity.this.dest_file), "application/vnd.android.package-archive");
intent.addFlags(1);
UserError.Log.d("jamorham update", "Attempting to install application");
UpdateActivity.this.startActivity(intent);
UpdateActivity.this.finish();
return;
} catch (Exception e2) {
Log.e("jamorham update", "Got exception trying to install apk: " + e2);
JoH.static_toast_long(UpdateActivity.this.getApplicationContext(), "Update is in your downloads folder");
return;
}
}
Log.e("jamorham update", "Checksum doesn't match: " + UpdateActivity.lastDigest + " vs " + UpdateActivity.CHECKSUM);
try {
UpdateActivity.this.dest_file.delete();
} catch (Exception e3) {
Log.e("jamorham update", "Got exception deleting corrupt file: " + e3);
}
JoH.static_toast_long("File appears corrupt!");
UpdateActivity.this.finish();
return;
}
JoH.static_toast_long(UpdateActivity.this.getApplicationContext(), "Failed!");
try {
if (UpdateActivity.this.dest_file == null || !UpdateActivity.this.dest_file.exists()) {
return;
}
UpdateActivity.this.dest_file.delete();
} catch (Exception e4) {
Log.e("jamorham update", "Got exception deleting existing file: " + e4);
}
}
}
public static void clearLastCheckTime() {
Pref.setLong("last_update_check_time", 0L);
}
}