(chore) code cleanup

Signed-off-by: androidacy-user <opensource@androidacy.com>
master
androidacy-user 1 year ago
parent f36f77214f
commit 231cc99cb6

@ -119,6 +119,7 @@ public class MainActivity extends FoxActivity implements SwipeRefreshLayout.OnRe
enabledRepos.setLength(enabledRepos.length() - 1); enabledRepos.setLength(enabledRepos.length() - 1);
} }
TrackHelper.track().event("enabled_repos", enabledRepos.toString()).with(MainApplication.getINSTANCE().getTracker()); TrackHelper.track().event("enabled_repos", enabledRepos.toString()).with(MainApplication.getINSTANCE().getTracker());
realm.close();
// log all shared preferences that are present // log all shared preferences that are present
if (!Iof) { if (!Iof) {
Timber.w("You may be running an untrusted build."); Timber.w("You may be running an untrusted build.");

@ -352,6 +352,7 @@ public class SetupActivity extends FoxActivity implements LanguageActivity {
Timber.d("Created magisk_alt_repo"); Timber.d("Created magisk_alt_repo");
} }
realm.commitTransaction(); realm.commitTransaction();
realm.close();
realmDatabasesCreated = true; realmDatabasesCreated = true;
Timber.d("Realm transaction finished"); Timber.d("Realm transaction finished");
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();

@ -434,4 +434,16 @@ public final class AndroidacyActivity extends FoxActivity {
this.downloadMode = false; this.downloadMode = false;
return FileProvider.getUriForFile(this, this.getPackageName() + ".file-provider", this.moduleFile); return FileProvider.getUriForFile(this, this.getPackageName() + ".file-provider", this.moduleFile);
} }
@Override
protected void onDestroy() {
super.onDestroy();
if (webView != null) {
SwipeRefreshLayout parent = (SwipeRefreshLayout) webView.getParent();
parent.removeView(webView);
webView.removeAllViews();
webView.destroy(); // fix memory leak
}
Timber.i("onDestroy for %s", this);
}
} }

@ -117,6 +117,8 @@ public final class ModuleManager extends SyncManager {
moduleInfos.put(module, moduleInfo); moduleInfos.put(module, moduleInfo);
realm.close(); realm.close();
break; break;
} else {
realm.close();
} }
} }
} }

@ -151,6 +151,7 @@ public class CustomRepoManager {
// Set the enabled state to true // Set the enabled state to true
customRepoData.setEnabled(true); customRepoData.setEnabled(true);
customRepoData.updateEnabledState(); customRepoData.updateEnabledState();
realm.close();
return customRepoData; return customRepoData;
} }

@ -344,6 +344,7 @@ public class RepoData extends XRepo {
} catch (Exception e) { } catch (Exception e) {
Timber.e(e, "Error while updating enabled state for repo %s", this.id); Timber.e(e, "Error while updating enabled state for repo %s", this.id);
} }
realm2.close();
this.enabled = (!this.forceHide) && dbEnabled; this.enabled = (!this.forceHide) && dbEnabled;
} }
@ -408,12 +409,16 @@ public class RepoData extends XRepo {
long diff = currentTime - lastUpdate; long diff = currentTime - lastUpdate;
long diffMinutes = diff / (60 * 1000) % 60; long diffMinutes = diff / (60 * 1000) % 60;
Timber.d("Repo " + this.id + " updated: " + diffMinutes + " minutes ago"); Timber.d("Repo " + this.id + " updated: " + diffMinutes + " minutes ago");
realm.close();
return diffMinutes > (BuildConfig.DEBUG ? 15 : 20); return diffMinutes > (BuildConfig.DEBUG ? 15 : 20);
} else { } else {
Timber.d("Repo " + this.id + " should update could not find repo in database"); Timber.d("Repo " + this.id + " should update could not find repo in database");
Timber.d("This is probably an error, please report this to the developer"); Timber.d("This is probably an error, please report this to the developer");
realm.close();
return true; return true;
} }
} else {
realm.close();
} }
return true; return true;
} }

@ -356,6 +356,7 @@ public class RepoUpdater {
Timber.w("Failed to update lastUpdate for repo %s", this.repoData.id); Timber.w("Failed to update lastUpdate for repo %s", this.repoData.id);
} }
}); });
realm2.close();
} else { } else {
success.set(true); // assume we're reading from cache. this may be unsafe but it's better than nothing success.set(true); // assume we're reading from cache. this may be unsafe but it's better than nothing
} }

@ -1416,6 +1416,7 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
findPreference(preferenceName + "_donate").setVisible(false); findPreference(preferenceName + "_donate").setVisible(false);
} }
} }
realm.close();
} else { } else {
Timber.d("Hiding preference " + preferenceName + " because it's data is null"); Timber.d("Hiding preference " + preferenceName + " because it's data is null");
hideRepoData(preferenceName); hideRepoData(preferenceName);

@ -331,8 +331,6 @@ public enum Http {
@SuppressWarnings("resource") @SuppressWarnings("resource")
private static Object doHttpPostRaw(String url, String data, boolean allowCache) throws IOException { private static Object doHttpPostRaw(String url, String data, boolean allowCache) throws IOException {
if (BuildConfig.DEBUG)
Timber.i("POST " + url + " " + data);
Response response; Response response;
response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).post(JsonRequestBody.from(data)).header("Content-Type", "application/json").build()).execute(); response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(new Request.Builder().url(url).post(JsonRequestBody.from(data)).header("Content-Type", "application/json").build()).execute();
if (response.isRedirect()) { if (response.isRedirect()) {
@ -340,7 +338,7 @@ public enum Http {
} }
// 200/204 == success, 304 == cache valid // 200/204 == success, 304 == cache valid
if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) { if (response.code() != 200 && response.code() != 204 && (response.code() != 304 || !allowCache)) {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG_HTTP)
Timber.e("Failed to fetch " + url + ", code: " + response.code() + ", body: " + response.body().string()); Timber.e("Failed to fetch " + url + ", code: " + response.code() + ", body: " + response.body().string());
checkNeedCaptchaAndroidacy(url, response.code()); checkNeedCaptchaAndroidacy(url, response.code());
throw new HttpException(response.code()); throw new HttpException(response.code());
@ -356,8 +354,6 @@ public enum Http {
} }
public static byte[] doHttpGet(String url, ProgressListener progressListener) throws IOException { public static byte[] doHttpGet(String url, ProgressListener progressListener) throws IOException {
if (BuildConfig.DEBUG)
Timber.i("GET %s", url.split("\\?")[0]);
Response response = getHttpClient().newCall(new Request.Builder().url(url).get().build()).execute(); Response response = getHttpClient().newCall(new Request.Builder().url(url).get().build()).execute();
if (response.code() != 200 && response.code() != 204) { if (response.code() != 200 && response.code() != 204) {
Timber.e("Failed to fetch " + url + ", code: " + response.code()); Timber.e("Failed to fetch " + url + ", code: " + response.code());

Loading…
Cancel
Save