正在查看: xDrip+ v04633772025.07.16 应用的 DisplayQRCode.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: xDrip+ v04633772025.07.16 应用的 DisplayQRCode.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.eveningoutpost.dexdrip.utils;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;
import com.eveningoutpost.dexdrip.BaseAppCompatActivity;
import com.eveningoutpost.dexdrip.GcmActivity;
import com.eveningoutpost.dexdrip.databinding.ActivityDisplayQrcodeBinding;
import com.eveningoutpost.dexdrip.models.DesertSync;
import com.eveningoutpost.dexdrip.models.JoH;
import com.eveningoutpost.dexdrip.ui.helpers.BitmapUtil;
import com.eveningoutpost.dexdrip.utilitymodels.Pref;
import com.eveningoutpost.dexdrip.utilitymodels.PrefsViewImpl;
import com.eveningoutpost.dexdrip.utilitymodels.desertsync.RouteTools;
import com.eveningoutpost.dexdrip.xdrip;
import com.google.zxing.WriterException;
import com.google.zxing.integration.android.IntentIntegrator;
import com.squareup.okhttp.FormEncodingBuilder;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.json.JSONObject;
public class DisplayQRCode extends BaseAppCompatActivity {
private static DisplayQRCode mInstance;
private static String send_url;
private ActivityDisplayQrcodeBinding binding;
private final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(xdrip.getAppContext());
private Map<String, String> prefsMap = new HashMap();
private Map<String, byte[]> binaryPrefsMap = new HashMap();
private String mapChecksum = "empty";
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
mInstance = this;
ActivityDisplayQrcodeBinding inflate = ActivityDisplayQrcodeBinding.inflate(getLayoutInflater());
this.binding = inflate;
inflate.setPrefs(new PrefsViewImpl());
this.binding.setViewmodel(new ViewModel());
setContentView(this.binding.getRoot());
JoH.fixActionBar(this);
processIntent(getIntent());
}
@Override
public void onNewIntent(Intent intent) {
processIntent(intent);
}
private void processIntent(Intent intent) {
String action;
if (intent == null || (action = intent.getAction()) == null) {
return;
}
if (action.equals("xdrip_plus_keks_qr")) {
showGKey(null);
} else if (action.equals("xdrip_plus_desert_sync_qr")) {
desertSyncSettings(null);
}
}
@Override
protected void onDestroy() {
mInstance = null;
super.onDestroy();
}
public synchronized void xdripPlusSyncSettings(View view) {
this.prefsMap.put("custom_sync_key", this.prefs.getString("custom_sync_key", ""));
this.prefsMap.put("use_custom_sync_key", Boolean.toString(this.prefs.getBoolean("use_custom_sync_key", false)));
showQRCode();
}
public synchronized void connectionSettings(View view) {
this.prefsMap.clear();
this.prefsMap.put("wifi_recievers_addresses", this.prefs.getString("wifi_recievers_addresses", ""));
this.prefsMap.put("dex_collection_method", this.prefs.getString("dex_collection_method", "BluetoothWixel"));
this.prefsMap.put("highValue", this.prefs.getString("highValue", "170"));
this.prefsMap.put("lowValue", this.prefs.getString("lowValue", "70"));
this.prefsMap.put("units", this.prefs.getString("units", "mgdl"));
this.prefsMap.put("custom_sync_key", this.prefs.getString("custom_sync_key", ""));
this.prefsMap.put("use_custom_sync_key", Boolean.toString(this.prefs.getBoolean("use_custom_sync_key", false)));
showQRCode();
}
public synchronized void alarmSettings(View view) {
this.prefsMap.clear();
this.prefsMap.put("bg_alert_profile", this.prefs.getString("bg_alert_profile", "ascending"));
this.prefsMap.put("smart_snoozing", Boolean.toString(this.prefs.getBoolean("smart_snoozing", true)));
this.prefsMap.put("smart_alerting", Boolean.toString(this.prefs.getBoolean("smart_alerting", true)));
this.prefsMap.put("calibration_notifications", Boolean.toString(this.prefs.getBoolean("calibration_notifications", true)));
showQRCode();
}
public synchronized void desertSyncSettings(View view) {
this.prefsMap.clear();
this.prefsMap.put("desert_sync_enabled", Boolean.toString(true));
this.prefsMap.put("desert_sync_master_ip", RouteTools.getBestInterfaceAddress());
this.prefsMap.put("dex_collection_method", "Follower");
this.prefsMap.put("custom_sync_key", Pref.getString("custom_sync_key", ""));
this.prefsMap.put("use_custom_sync_key", Boolean.toString(Pref.getBoolean("use_custom_sync_key", false)));
this.prefsMap.put("desert_use_https", Boolean.toString(Pref.getBooleanDefaultFalse("desert_use_https")));
this.prefsMap.put(DesertSync.PREF_WEBSERVICE_SECRET, Pref.getString(DesertSync.PREF_WEBSERVICE_SECRET, ""));
showQRCode();
}
public boolean generateKeksBinaryPrefs() {
this.binaryPrefsMap.clear();
this.mapChecksum = "error";
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
for (int i = 1; i < 4; i++) {
String str = "keks_p" + i;
byte[] hexStringToByteArray = JoH.hexStringToByteArray(Pref.getStringDefaultBlank(str));
if (hexStringToByteArray != null && hexStringToByteArray.length != 0) {
String str2 = "b__" + str;
this.binaryPrefsMap.put(str2, hexStringToByteArray);
messageDigest.update(str2.getBytes(StandardCharsets.UTF_8));
messageDigest.update(hexStringToByteArray);
}
Log.d("jamorham qr", "Null or empty at: " + i);
return false;
}
this.mapChecksum = JoH.bytesToHex(messageDigest.digest());
return true;
} catch (Exception e) {
Log.d("jamorham qr", "Got exception making binary prefs map " + e);
return false;
}
}
public synchronized void showGKey(View view) {
showQRCode2("G Key settings\n\n" + Preferences.getMapKeysString(this.binaryPrefsMap).replace("\n", " ") + "\n\nHash: " + this.mapChecksum.substring(0, 16));
}
public static synchronized void uploadBytes(byte[] bArr, final int i) {
synchronized (DisplayQRCode.class) {
PowerManager.WakeLock wakeLock = JoH.getWakeLock("uploadBytes", 1200000);
if (bArr != null && bArr.length > 0) {
final byte[] randomKey = CipherUtils.getRandomKey();
byte[] encryptBytes = CipherUtils.encryptBytes(JoH.compressBytesToBytes(bArr), randomKey);
if (encryptBytes != null && encryptBytes.length > 0) {
Log.d("jamorham qr", "Before: " + bArr.length + " After: " + encryptBytes.length);
final OkHttpClient okHttpClient = new OkHttpClient();
TimeUnit timeUnit = TimeUnit.SECONDS;
okHttpClient.setConnectTimeout(15L, timeUnit);
okHttpClient.setReadTimeout(30L, timeUnit);
okHttpClient.setWriteTimeout(30L, timeUnit);
toast("Preparing");
try {
try {
send_url = xdrip.getAppContext().getString(2131757053) + "/joh-setsw";
String encodeToString = Base64.encodeToString(encryptBytes, 2);
Log.d("jamorham qr", "Upload Body size: " + encodeToString.length());
final RequestBody build = new FormEncodingBuilder().add("data", encodeToString).build();
new Thread(new Runnable() {
@Override
public void run() {
try {
Request build2 = new Request.Builder().header("User-Agent", "Mozilla/5.0 (jamorham)").header("Connection", "close").url(DisplayQRCode.send_url).post(build).build();
Log.i("jamorham qr", "Uploading data");
Response execute = okHttpClient.newCall(build2).execute();
if (!execute.isSuccessful()) {
DisplayQRCode.toast("Error please try again");
} else {
String string = execute.body().string();
Log.d("jamorham qr", "Got success response length: " + string.length() + " " + string);
if (string.length() == 35 && string.startsWith("ID:")) {
int i2 = i;
if (i2 != 1) {
if (i2 != 2) {
DisplayQRCode.toast("Invalid callback option on upload");
} else {
GcmActivity.backfillLink(string.substring(3, 35), JoH.bytesToHex(randomKey));
}
} else if (DisplayQRCode.mInstance != null) {
DisplayQRCode.mInstance.display_final_all_settings_qr_code(string.substring(3, 35), randomKey);
} else {
Log.e("jamorham qr", "mInstance null");
}
} else {
Log.d("jamorham qr", "Got unhandled reply: " + string);
DisplayQRCode.toast(string);
}
}
} catch (Exception e) {
Log.e("jamorham qr", "Got exception in execute: " + e.toString());
e.printStackTrace();
DisplayQRCode.toast("Error with connection");
}
}
}).start();
} catch (Exception e) {
toast(e.getMessage());
Log.e("jamorham qr", "General exception: " + e.toString());
}
} finally {
JoH.releaseWakeLock(wakeLock);
}
} else {
toast("Something went wrong preparing the settings");
}
} else {
toast("Could not read data somewhere");
}
}
}
public void allSettings(View view) {
this.prefsMap.clear();
byte[] preferencesFileAsBytes = SdcardImportExport.getPreferencesFileAsBytes(getApplicationContext());
if (preferencesFileAsBytes != null && preferencesFileAsBytes.length > 0) {
uploadBytes(preferencesFileAsBytes, 1);
} else {
toast("Could not read preferences file");
}
}
public void display_final_all_settings_qr_code(final String str, final byte[] bArr) {
Log.d("jamorham qr", "Displaying final qr code: " + str);
try {
runOnUiThread(new Runnable() {
@Override
public void run() {
DisplayQRCode.this.prefsMap.put(DisplayQRCode.this.getString(2131755125), "t");
DisplayQRCode.this.prefsMap.put("wizard_uuid", str);
DisplayQRCode.this.prefsMap.put("wizard_key", CipherUtils.bytesToHex(bArr));
DisplayQRCode.this.showQRCode();
}
});
} catch (Exception e) {
Log.e("jamorham qr", "Got exception displaying final qrcode: " + e.toString());
}
}
public void showQRCode() {
String jSONObject = new JSONObject(this.prefsMap).toString();
Log.d("jamorham qr", "Serialized: " + jSONObject);
String compressString = JoH.compressString(jSONObject);
Log.d("jamorham qr", "Compressed: " + compressString);
new IntentIntegrator(this).shareText("xdpref:" + compressString);
}
private void showQRCode2(String str) {
byte[] serializeBinaryPrefsMap = QRcodeUtils.serializeBinaryPrefsMap(this.binaryPrefsMap);
Log.d("jamorham qr", "QR bytes: " + serializeBinaryPrefsMap.length);
byte[] compressBytesToBytes = JoH.compressBytesToBytes(serializeBinaryPrefsMap);
Log.d("jamorham qr", "QR bytes: " + compressBytesToBytes.length);
int min = (int) (Math.min(BitmapUtil.getScreenWidth(), BitmapUtil.getScreenHeight()) * (BitmapUtil.getScreenWidth() > BitmapUtil.getScreenHeight() ? 0.8d : 1.0d));
try {
Bitmap createQRCodeBitmap = QRcodeUtils.createQRCodeBitmap(compressBytesToBytes, min, min);
this.binding.getViewmodel().showQr.set(false);
this.binding.getViewmodel().narrative.set(JoH.dateTimeText(JoH.tsl()) + "\n" + Build.MANUFACTURER + " " + Build.MODEL + "\n" + str);
this.binding.getViewmodel().qrbitmap.set(new BitmapDrawable(xdrip.getAppContext().getResources(), createQRCodeBitmap));
this.binding.getViewmodel().showQr.set(true);
} catch (WriterException e) {
Log.e("jamorham qr", "ERROR: " + e);
}
}
public void closeNow(View view) {
try {
mInstance = null;
finish();
} catch (Exception e) {
Log.d("jamorham qr", "Error finishing " + e.toString());
}
}
public static void toast(String str) {
JoH.static_toast_short(str);
}
public class ViewModel {
public final ObservableField<String> narrative;
public final ObservableBoolean showGkey;
public final ObservableBoolean showQr = new ObservableBoolean();
public final ObservableField<Drawable> qrbitmap = new ObservableField<>();
public ViewModel() {
ObservableBoolean observableBoolean = new ObservableBoolean();
this.showGkey = observableBoolean;
this.narrative = new ObservableField<>();
observableBoolean.set(DisplayQRCode.this.generateKeksBinaryPrefs());
}
}
}