Skip to content

Commit e57829f

Browse files
refactor
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent a7b04a2 commit e57829f

10 files changed

Lines changed: 27 additions & 22 deletions

File tree

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ public byte[] getKey() {
581581
//noinspection BusyWait
582582
Thread.sleep(100);
583583
} catch (InterruptedException ignored) {
584-
// silence is bliss
584+
Thread.currentThread().interrupt();
585585
}
586586
}
587587
// attempt to read the existingKey property
@@ -607,7 +607,9 @@ public byte[] getKey() {
607607
}
608608
// create a securely generated random asymmetric RSA key
609609
byte[] realmKey = new byte[Realm.ENCRYPTION_KEY_LENGTH];
610-
new SecureRandom().nextBytes(realmKey);
610+
do {
611+
new SecureRandom().nextBytes(realmKey);
612+
} while (realmKey[0] == 0);
611613
// create a cipher that uses AES encryption -- we'll use this to encrypt our key
612614
Cipher cipher;
613615
try {

app/src/main/java/com/fox2code/mmm/SetupActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected void onCreate(Bundle savedInstanceState) {
204204
try {
205205
Thread.sleep(250);
206206
} catch (InterruptedException e) {
207-
e.printStackTrace();
207+
Thread.currentThread().interrupt();
208208
}
209209
// Log the changes
210210
Timber.d("Setup finished. Preferences: %s", prefs.getAll());
@@ -218,7 +218,7 @@ protected void onCreate(Bundle savedInstanceState) {
218218
try {
219219
pendingIntent.send();
220220
} catch (PendingIntent.CanceledException e) {
221-
e.printStackTrace();
221+
Timber.e(e);
222222
}
223223
android.os.Process.killProcess(android.os.Process.myPid());
224224
});

app/src/main/java/com/fox2code/mmm/UpdateActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.File;
2525
import java.io.FileOutputStream;
2626
import java.io.IOException;
27+
import java.util.Arrays;
2728
import java.util.Objects;
2829

2930
import io.noties.markwon.Markwon;
@@ -223,7 +224,7 @@ public void downloadUpdate() throws JSONException {
223224
});
224225
}
225226
// convert to JSON
226-
JSONObject latestJSON = new JSONObject(new String(lastestJSON));
227+
JSONObject latestJSON = new JSONObject(Arrays.toString(lastestJSON));
227228
String changelog = latestJSON.getString("body");
228229
// set changelog text. changelog could be markdown, so we need to convert it to HTML
229230
MaterialTextView changelogTextView = findViewById(R.id.update_changelog);

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyRepoData.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.security.MessageDigest;
3535
import java.security.NoSuchAlgorithmException;
3636
import java.util.ArrayList;
37+
import java.util.Arrays;
3738
import java.util.Iterator;
3839
import java.util.List;
3940
import java.util.Objects;
@@ -154,7 +155,7 @@ public boolean isValidToken(String token) throws IOException {
154155
try {
155156
byte[] resp = Http.doHttpGet("https://" + this.host + "/auth/me?token=" + token + "&device_id=" + deviceId + "&client_id=" + BuildConfig.ANDROIDACY_CLIENT_ID, false);
156157
// response is JSON
157-
JSONObject jsonObject = new JSONObject(new String(resp));
158+
JSONObject jsonObject = new JSONObject(Arrays.toString(resp));
158159
memberLevel = jsonObject.getString("role");
159160
JSONArray memberPermissions = jsonObject.getJSONArray("permissions");
160161
// set role and permissions on userInfo property
@@ -251,7 +252,7 @@ protected boolean prepare() {
251252
try {
252253
Timber.i("Requesting new token...");
253254
// POST json request to https://production-api.androidacy.com/auth/register
254-
token = new String(Http.doHttpPost("https://" + this.host + "/auth/register?client_id=" + BuildConfig.ANDROIDACY_CLIENT_ID, "{\"device_id\":\"" + deviceId + "\"}", false));
255+
token = Arrays.toString(Http.doHttpPost("https://" + this.host + "/auth/register?client_id=" + BuildConfig.ANDROIDACY_CLIENT_ID, "{\"device_id\":\"" + deviceId + "\"}", false));
255256
// Parse token
256257
try {
257258
JSONObject jsonObject = new JSONObject(token);

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.fox2code.mmm.utils.io.net.Http;
1010

1111
import java.io.IOException;
12+
import java.util.Arrays;
1213
import java.util.Objects;
1314

1415
public enum AndroidacyUtil {
@@ -132,6 +133,6 @@ public static String getMarkdownFromAPI(String url) {
132133
if (md == null) {
133134
return null;
134135
}
135-
return new String(md);
136+
return Arrays.toString(md);
136137
}
137138
}

app/src/main/java/com/fox2code/mmm/background/BackgroundUpdateChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void doCheck(Context context) {
206206
postNotificationForAppUpdate(context);
207207
}
208208
} catch (Exception e) {
209-
e.printStackTrace();
209+
Timber.e("Failed to check for app update");
210210
}
211211
}
212212
// remove checking notification

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ private void doInstall(File file, boolean noExtensions, boolean rootless) {
312312
return;
313313
}
314314
this.installerTerminal.enableAnsi();
315-
// Extract customize.sh manually in rootless mode because unzip might not exists
316315
try (ZipFile zipFile = new ZipFile(file)) {
317316
ZipArchiveEntry zipEntry = zipFile.getEntry("customize.sh");
318317
if (zipEntry != null) {

app/src/main/java/com/fox2code/mmm/repo/CustomRepoManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.json.JSONObject;
1010

1111
import java.nio.charset.StandardCharsets;
12+
import java.util.Arrays;
1213

1314
import io.realm.Realm;
1415
import io.realm.RealmConfiguration;
@@ -74,7 +75,7 @@ public CustomRepoData addRepo(String repo) {
7475
// parse json
7576
JSONObject jsonObject;
7677
try {
77-
jsonObject = new JSONObject(new String(json));
78+
jsonObject = new JSONObject(Arrays.toString(json));
7879
} catch (Exception e) {
7980
Timber.e(e, "Failed to parse json from repo");
8081
return null;

app/src/main/java/com/fox2code/mmm/settings/SettingsActivity.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.os.Looper;
2121
import android.provider.Settings;
2222
import android.text.Editable;
23+
import android.text.InputType;
2324
import android.text.TextWatcher;
2425
import android.view.View;
2526
import android.view.ViewGroup;
@@ -648,6 +649,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
648649
materialTextView.setText(localModuleInfo.name);
649650
layout.addView(materialTextView);
650651
EditText editText = new EditText(this.requireContext());
652+
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
651653
editText.setLayoutParams(params);
652654
editText.setHint(R.string.background_update_check_excludes_version_hint);
653655
// stringset uses id:version, we show version for name
@@ -907,9 +909,10 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
907909
Timber.d("Version clicks: %d", ref.versionClicks);
908910
// if it's been 3 clicks, toast "yer a wizard, harry" or "keep tapping to enter hogwarts"
909911
if (ref.versionClicks == 3) {
910-
// pick 1 or 2
911-
int random = new Random().nextInt(2) + 1;
912-
Toast.makeText(p.getContext(), random == 1 ? R.string.yer_a_wizard_harry : R.string.keep_tapping_to_enter_hogwarts, Toast.LENGTH_SHORT).show();
912+
// random choice of 1 or 2
913+
Random rand = new Random();
914+
int n = rand.nextInt(2) + 1;
915+
Toast.makeText(p.getContext(), n == 1 ? R.string.yer_a_wizard_harry : R.string.keep_tapping_to_enter_hogwarts, Toast.LENGTH_SHORT).show();
913916
}
914917
if (ref.versionClicks == 7) {
915918
ref.versionClicks = 0;

app/src/main/java/com/fox2code/mmm/utils/io/net/WebkitCookieManagerProxy.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.HashMap;
1212
import java.util.List;
1313
import java.util.Map;
14-
import java.util.Objects;
1514

1615
import okhttp3.Cookie;
1716
import okhttp3.CookieJar;
@@ -41,15 +40,13 @@ public void put(URI uri, Map<String, List<String>> responseHeaders)
4140
String url = uri.toString();
4241

4342
// go over the headers
44-
for (String headerKey : responseHeaders.keySet()) {
43+
for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) {
4544
// ignore headers which aren't cookie related
46-
if ((headerKey == null)
47-
|| !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey
48-
.equalsIgnoreCase("Set-Cookie")))
45+
if ((entry.getKey() == null)
46+
|| !(entry.getKey().equalsIgnoreCase("Set-Cookie2") || entry
47+
.getKey().equalsIgnoreCase("Set-Cookie")))
4948
continue;
50-
51-
// process each of the headers
52-
for (String headerValue : Objects.requireNonNull(responseHeaders.get(headerKey))) {
49+
for (String headerValue : entry.getValue()) {
5350
webkitCookieManager.setCookie(url, headerValue);
5451
}
5552
}

0 commit comments

Comments
 (0)