(misc) work on custom repos

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/27/head
androidacy-user 3 years ago
parent d4218e5a9d
commit a268013b0d

@ -160,7 +160,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
// get the caller of this method // get the caller of this method
StackTraceElement caller = stackTrace[3]; 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 // 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()); callers.add(name + ":" + caller.getLineNumber() + ":" + caller.getMethodName());
// get the last 3 callers // get the last 3 callers

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

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

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

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

@ -3,12 +3,15 @@ package com.fox2code.mmm.repo;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import com.fox2code.mmm.MainApplication; 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.PropUtils;
import com.fox2code.mmm.utils.io.net.Http; import com.fox2code.mmm.utils.io.net.Http;
import com.fox2code.mmm.utils.realm.ReposList; import com.fox2code.mmm.utils.realm.ReposList;
import org.json.JSONObject; import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import io.realm.Realm; import io.realm.Realm;
import io.realm.RealmConfiguration; import io.realm.RealmConfiguration;
import timber.log.Timber; import timber.log.Timber;
@ -118,6 +121,7 @@ public class CustomRepoManager {
} catch (Exception e) { } catch (Exception e) {
submitModule = null; 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(); 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); Realm realm = Realm.getInstance(realmConfiguration);
int finalI = i; int finalI = i;
@ -127,7 +131,7 @@ public class CustomRepoManager {
String finalSubmitModule = submitModule; String finalSubmitModule = submitModule;
realm.executeTransaction(realm1 -> { realm.executeTransaction(realm1 -> {
// find the matching entry for repo_0, repo_1, etc. // 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) { if (reposList == null) {
reposList = realm1.createObject(ReposList.class, "repo_" + finalI); reposList = realm1.createObject(ReposList.class, "repo_" + finalI);
} }
@ -144,7 +148,13 @@ public class CustomRepoManager {
customReposCount++; customReposCount++;
this.dirty = true; this.dirty = true;
CustomRepoData customRepoData = (CustomRepoData) this.repoManager.addOrGet(repo); 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 // Set the enabled state to true
customRepoData.setEnabled(true); customRepoData.setEnabled(true);
customRepoData.updateEnabledState(); customRepoData.updateEnabledState();

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

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

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