(misc) work on custom repos

Signed-off-by: androidacy-user <opensource@androidacy.com>
master
androidacy-user 1 year ago
parent d4218e5a9d
commit a268013b0d

@ -160,7 +160,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// get the caller of this method
StackTraceElement caller = stackTrace[3];
Timber.d("Shared prefs file: %s, caller: %s:%d", name, caller.getMethodName(), caller.getLineNumber());
Timber.d("Shared prefs file: %s, caller: %s:%d in %s", name, caller.getFileName(), caller.getLineNumber(), caller.getMethodName());
// add the caller to an array. if the last 3 callers are the same, then we are in a loop, log at error level
callers.add(name + ":" + caller.getLineNumber() + ":" + caller.getMethodName());
// get the last 3 callers

@ -62,8 +62,8 @@ public final class AndroidacyRepoData extends RepoData {
// Avoid spamming requests to Androidacy
private long androidacyBlockade = 0;
public AndroidacyRepoData(File cacheRoot, SharedPreferences cachedPreferences, boolean testMode) {
super(testMode ? RepoManager.ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT : RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT, cacheRoot, cachedPreferences);
public AndroidacyRepoData(File cacheRoot, boolean testMode) {
super(testMode ? RepoManager.ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT : RepoManager.ANDROIDACY_MAGISK_REPO_ENDPOINT, cacheRoot);
this.defaultName = "Androidacy Modules Repo";
this.defaultWebsite = RepoManager.ANDROIDACY_MAGISK_REPO_HOMEPAGE;
this.defaultSupport = "https://t.me/androidacy_discussions";

@ -244,7 +244,7 @@ public class AndroidacyWebAPI {
}
checksum = Hashes.checkSumFormat(checksum);
if (checksum == null || checksum.isEmpty()) {
Timber.w("Androidacy WebView didn't provided a checksum!");
Timber.w("Androidacy didn't provided a checksum!");
} else if (!Hashes.checkSumValid(checksum)) {
this.forceQuitRaw("Androidacy didn't provided a valid checksum");
return;

@ -75,6 +75,7 @@ public class InstallerActivity extends FoxActivity {
private boolean warnReboot;
private PowerManager.WakeLock wakeLock;
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
this.warnReboot = false;
@ -151,6 +152,9 @@ public class InstallerActivity extends FoxActivity {
this.progressIndicator = findViewById(R.id.progress_bar);
this.rebootFloatingButton = findViewById(R.id.install_terminal_reboot_fab);
this.cancelFloatingButton = findViewById(R.id.back_installer);
// disable both
this.rebootFloatingButton.setEnabled(false);
this.cancelFloatingButton.setEnabled(false);
this.installerTerminal = new InstallerTerminal(installTerminal = findViewById(R.id.install_terminal), this.isLightTheme(), foreground, mmtReborn);
(horizontalScroller != null ? horizontalScroller : installTerminal).setBackground(new ColorDrawable(background));
installTerminal.setItemAnimator(null);
@ -530,7 +534,8 @@ public class InstallerActivity extends FoxActivity {
Shell.cmd(reboot_cmd).submit();
}
});
this.rebootFloatingButton.setVisibility(View.VISIBLE);
this.rebootFloatingButton.setEnabled(true);
this.cancelFloatingButton.setEnabled(true);
// handle back button
this.cancelFloatingButton.setOnClickListener(_view -> this.forceBackPressed());
if (message != null && !message.isEmpty()) this.installerTerminal.addLine(message);

@ -1,7 +1,5 @@
package com.fox2code.mmm.repo;
import android.content.SharedPreferences;
import com.fox2code.mmm.utils.io.net.Http;
import org.json.JSONException;
@ -15,8 +13,8 @@ public final class CustomRepoData extends RepoData {
boolean loadedExternal;
String override;
CustomRepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
super(url, cacheRoot, cachedPreferences);
CustomRepoData(String url, File cacheRoot) {
super(url, cacheRoot);
}
@Override

@ -3,12 +3,15 @@ package com.fox2code.mmm.repo;
import android.content.SharedPreferences;
import com.fox2code.mmm.MainApplication;
import com.fox2code.mmm.utils.io.Hashes;
import com.fox2code.mmm.utils.io.PropUtils;
import com.fox2code.mmm.utils.io.net.Http;
import com.fox2code.mmm.utils.realm.ReposList;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import timber.log.Timber;
@ -118,6 +121,7 @@ public class CustomRepoManager {
} catch (Exception e) {
submitModule = null;
}
String id = "repo_" + Hashes.hashSha256(repo.getBytes(StandardCharsets.UTF_8));
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name("ReposList.realm").encryptionKey(MainApplication.getINSTANCE().getKey()).allowQueriesOnUiThread(true).allowWritesOnUiThread(true).directory(MainApplication.getINSTANCE().getDataDirWithPath("realms")).schemaVersion(1).build();
Realm realm = Realm.getInstance(realmConfiguration);
int finalI = i;
@ -127,7 +131,7 @@ public class CustomRepoManager {
String finalSubmitModule = submitModule;
realm.executeTransaction(realm1 -> {
// find the matching entry for repo_0, repo_1, etc.
ReposList reposList = realm1.where(ReposList.class).equalTo("id", "repo_" + finalI).findFirst();
ReposList reposList = realm1.where(ReposList.class).equalTo("id", "repo_" + id).findFirst();
if (reposList == null) {
reposList = realm1.createObject(ReposList.class, "repo_" + finalI);
}
@ -144,7 +148,13 @@ public class CustomRepoManager {
customReposCount++;
this.dirty = true;
CustomRepoData customRepoData = (CustomRepoData) this.repoManager.addOrGet(repo);
customRepoData.override = "custom_repo_" + i;
customRepoData.override = "repo_" + id;
customRepoData.id = id;
customRepoData.website = website;
customRepoData.support = support;
customRepoData.donate = donate;
customRepoData.submitModule = submitModule;
customRepoData.name = name;
// Set the enabled state to true
customRepoData.setEnabled(true);
customRepoData.updateEnabledState();

@ -1,6 +1,5 @@
package com.fox2code.mmm.repo;
import android.content.SharedPreferences;
import android.net.Uri;
import androidx.annotation.NonNull;
@ -38,11 +37,11 @@ import timber.log.Timber;
public class RepoData extends XRepo {
public final JSONObject supportedProperties = new JSONObject();
private final Object populateLock = new Object();
public String url;
public String id;
public File cacheRoot;
public SharedPreferences cachedPreferences;
public HashMap<String, RepoModule> moduleHashMap;
public JSONObject metaDataCache;
public long lastUpdate;
@ -72,7 +71,7 @@ public class RepoData extends XRepo {
//installedVersionCode=<int> (only if installed)
private boolean forceHide, enabled; // Cache for speed
public RepoData(String url, File cacheRoot, SharedPreferences cachedPreferences) {
public RepoData(String url, File cacheRoot) {
// setup supportedProperties
try {
supportedProperties.put("id", "");
@ -100,7 +99,6 @@ public class RepoData extends XRepo {
this.url = url;
this.id = RepoManager.internalIdOfUrl(url);
this.cacheRoot = cacheRoot;
this.cachedPreferences = cachedPreferences;
// metadata cache is a realm database from ModuleListCache
this.metaDataCache = null;
this.moduleHashMap = new HashMap<>();

@ -351,8 +351,7 @@ public final class RepoManager extends SyncManager {
private RepoData addRepoData(String url, String fallBackName) {
String id = internalIdOfUrl(url);
File cacheRoot = new File(this.mainApplication.getDataDir(), "repos/" + id);
SharedPreferences sharedPreferences = MainApplication.getPreferences("mmm_" + id);
RepoData repoData = id.startsWith("repo_") ? new CustomRepoData(url, cacheRoot, sharedPreferences) : new RepoData(url, cacheRoot, sharedPreferences);
RepoData repoData = id.startsWith("repo_") ? new CustomRepoData(url, cacheRoot) : new RepoData(url, cacheRoot);
if (fallBackName != null && !fallBackName.isEmpty()) {
repoData.defaultName = fallBackName;
if (repoData instanceof CustomRepoData) {
@ -374,8 +373,7 @@ public final class RepoManager extends SyncManager {
private AndroidacyRepoData addAndroidacyRepoData() {
// cache dir is actually under app data
File cacheRoot = this.mainApplication.getDataDirWithPath("realms/repos/androidacy_repo");
SharedPreferences sharedPreferences = MainApplication.getPreferences("mmm_androidacy_repo");
AndroidacyRepoData repoData = new AndroidacyRepoData(cacheRoot, sharedPreferences, MainApplication.isAndroidacyTestMode());
AndroidacyRepoData repoData = new AndroidacyRepoData(cacheRoot, MainApplication.isAndroidacyTestMode());
this.repoData.put(ANDROIDACY_MAGISK_REPO_ENDPOINT, repoData);
this.repoData.put(ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT, repoData);
return repoData;

@ -9,15 +9,14 @@
tools:context=".installer.InstallerActivity">
<HorizontalScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/install_horizontal_scroller"
android:background="@color/black"
android:overScrollMode="never"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/bottom_nav_installer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent" android:layout_height="0dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/install_terminal"
android:background="@null"
@ -40,6 +39,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:id="@+id/bottom_nav_installer"
app:layout_constraintTop_toBottomOf="@id/install_horizontal_scroller"
app:menu="@menu/bottom_nav_install" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save