OpenDelta: Get rid of more reflection
Just... Why.... Ew. Also minor improvement to some random code
This commit is contained in:
parent
0daa4ad9ef
commit
8c51aa3565
|
@ -30,7 +30,6 @@ import android.os.SystemProperties;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -72,32 +71,14 @@ public class Config {
|
||||||
private final String url_api_history;
|
private final String url_api_history;
|
||||||
private final String android_version;
|
private final String android_version;
|
||||||
|
|
||||||
/*
|
|
||||||
* Using reflection voodoo instead calling the hidden class directly, to
|
|
||||||
* dev/test outside of AOSP tree
|
|
||||||
*/
|
|
||||||
private String getProperty(Context context, String key) {
|
|
||||||
try {
|
|
||||||
Class<?> SystemProperties = context.getClassLoader().loadClass(
|
|
||||||
"android.os.SystemProperties");
|
|
||||||
Method get = SystemProperties.getMethod("get", String.class, String.class);
|
|
||||||
return (String) get.invoke(null, new Object[] { key, ""});
|
|
||||||
} catch (Exception e) {
|
|
||||||
// A lot of voodoo could go wrong here, return failure instead of
|
|
||||||
// crash
|
|
||||||
Logger.ex(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Config(Context context) {
|
private Config(Context context) {
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
|
|
||||||
property_version = getProperty(context,
|
property_version = SystemProperties.get(
|
||||||
res.getString(R.string.property_version));
|
res.getString(R.string.property_version));
|
||||||
property_device = getProperty(context,
|
property_device = SystemProperties.get(
|
||||||
res.getString(R.string.property_device));
|
res.getString(R.string.property_device));
|
||||||
filename_base = String.format(Locale.ENGLISH,
|
filename_base = String.format(Locale.ENGLISH,
|
||||||
res.getString(R.string.filename_base), property_version);
|
res.getString(R.string.filename_base), property_version);
|
||||||
|
@ -124,7 +105,7 @@ public class Config {
|
||||||
url_api_history = String.format(
|
url_api_history = String.format(
|
||||||
res.getString(R.string.url_api_history),
|
res.getString(R.string.url_api_history),
|
||||||
url_branch_name, property_device, property_device);
|
url_branch_name, property_device, property_device);
|
||||||
android_version = getProperty(context,
|
android_version = SystemProperties.get(
|
||||||
res.getString(R.string.android_version));
|
res.getString(R.string.android_version));
|
||||||
filename_base_prefix = String.format(Locale.ENGLISH,
|
filename_base_prefix = String.format(Locale.ENGLISH,
|
||||||
res.getString(R.string.filename_base), android_version);
|
res.getString(R.string.filename_base), android_version);
|
||||||
|
|
|
@ -24,11 +24,6 @@ package eu.chainfire.opendelta;
|
||||||
|
|
||||||
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
@ -67,6 +62,11 @@ import android.widget.Toolbar;
|
||||||
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission;
|
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
private static final int PERMISSIONS_REQUEST_MANAGE_EXTERNAL_STORAGE = 0;
|
private static final int PERMISSIONS_REQUEST_MANAGE_EXTERNAL_STORAGE = 0;
|
||||||
private static final int PERMISSIONS_REQUEST_NOTIFICATION = 1;
|
private static final int PERMISSIONS_REQUEST_NOTIFICATION = 1;
|
||||||
|
@ -287,10 +287,11 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(String state, Float progress,
|
public void update(String stateP, Float progress,
|
||||||
Long current, Long total, String filename,
|
Long current, Long total, String filename,
|
||||||
Long ms, int errorCode) {
|
Long ms, int errorCode) {
|
||||||
mHandler.post(() -> {
|
mHandler.post(() -> {
|
||||||
|
String state = stateP;
|
||||||
String title = "";
|
String title = "";
|
||||||
String sub = "";
|
String sub = "";
|
||||||
String sub2 = "";
|
String sub2 = "";
|
||||||
|
@ -324,41 +325,40 @@ public class MainActivity extends Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't try this at home
|
// don't try this at home
|
||||||
if (state != null) {
|
if (state == null) state = State.ACTION_NONE;
|
||||||
title = tryGetResourceString("state_" + state);
|
title = tryGetResourceString("state_" + state);
|
||||||
// check for first start until check button has been pressed
|
// check for first start until check button has been pressed
|
||||||
// use a special title then - but only once
|
// use a special title then - but only once
|
||||||
if (State.ACTION_NONE.equals(state)
|
if (State.ACTION_NONE.equals(state)
|
||||||
&& !mPrefs.getBoolean(SettingsActivity.PREF_START_HINT_SHOWN, false)) {
|
&& !mPrefs.getBoolean(SettingsActivity.PREF_START_HINT_SHOWN, false)) {
|
||||||
title = getString(R.string.last_checked_never_title_new);
|
title = getString(R.string.last_checked_never_title_new);
|
||||||
}
|
|
||||||
// don't spill for progress
|
|
||||||
if (!State.isProgressState(state)) {
|
|
||||||
Logger.d("onReceive state = " + state);
|
|
||||||
} else if (state.equals(mState)) {
|
|
||||||
// same progress state as before.
|
|
||||||
// save a lot of time by only updating progress
|
|
||||||
disableDataSpeed = State.ACTION_AB_FLASH.equals(state);
|
|
||||||
final ProgressGenerator pgen = new ProgressGenerator(
|
|
||||||
localCurrent,
|
|
||||||
localTotal,
|
|
||||||
localMS,
|
|
||||||
progress,
|
|
||||||
disableDataSpeed,
|
|
||||||
filename
|
|
||||||
);
|
|
||||||
mSub.setText(pgen.sub);
|
|
||||||
mSub.setSelected(true); // allow scrolling
|
|
||||||
mSub2.setText(pgen.sub2);
|
|
||||||
mProgressPercent.setText(pgen.progressPercent);
|
|
||||||
mProgressCurrent = Math.round(pgen.localCurrent);
|
|
||||||
mProgressMax = Math.round(pgen.localTotal);
|
|
||||||
mProgressEnabled = true;
|
|
||||||
handleProgressBar();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mState = state;
|
|
||||||
}
|
}
|
||||||
|
// don't spill for progress
|
||||||
|
if (!State.isProgressState(state)) {
|
||||||
|
Logger.d("onReceive state = " + state);
|
||||||
|
} else if (state.equals(mState)) {
|
||||||
|
// same progress state as before.
|
||||||
|
// save a lot of time by only updating progress
|
||||||
|
disableDataSpeed = State.ACTION_AB_FLASH.equals(state);
|
||||||
|
final ProgressGenerator pgen = new ProgressGenerator(
|
||||||
|
localCurrent,
|
||||||
|
localTotal,
|
||||||
|
localMS,
|
||||||
|
progress,
|
||||||
|
disableDataSpeed,
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
mSub.setText(pgen.sub);
|
||||||
|
mSub.setSelected(true); // allow scrolling
|
||||||
|
mSub2.setText(pgen.sub2);
|
||||||
|
mProgressPercent.setText(pgen.progressPercent);
|
||||||
|
mProgressCurrent = Math.round(pgen.localCurrent);
|
||||||
|
mProgressMax = Math.round(pgen.localTotal);
|
||||||
|
mProgressEnabled = true;
|
||||||
|
handleProgressBar();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mState = state;
|
||||||
|
|
||||||
mProgress.setIndeterminate(false);
|
mProgress.setIndeterminate(false);
|
||||||
String flashImage = null;
|
String flashImage = null;
|
||||||
|
|
|
@ -22,30 +22,6 @@
|
||||||
|
|
||||||
package eu.chainfire.opendelta;
|
package eu.chainfire.opendelta;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.StringBuilder;
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.nio.channels.FileChannel;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
@ -73,6 +49,28 @@ import android.os.SystemClock;
|
||||||
import android.os.UpdateEngine;
|
import android.os.UpdateEngine;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.lang.StringBuilder;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class UpdateService extends Service implements OnSharedPreferenceChangeListener {
|
public class UpdateService extends Service implements OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public static void start(Context context) {
|
public static void start(Context context) {
|
||||||
|
|
Loading…
Reference in New Issue