Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit cf9fe3d

Browse files
Add custom API key support
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent e181fd1 commit cf9fe3d

File tree

28 files changed

+47
-5
lines changed

28 files changed

+47
-5
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected boolean prepare() {
7474
long time = System.currentTimeMillis();
7575
if (this.androidacyBlockade > time) return false;
7676
this.androidacyBlockade = time + 30_000L;
77-
// Get token from androidacy_token shared preference
78-
String token = this.cachedPreferences.getString("androidacy_token", null);
77+
// Get token from androidacy_api_token shared preference
78+
String token = this.cachedPreferences.getString("androidacy_api_token", null);
7979
if (token != null) {
8080
try {
8181
Http.doHttpGet("https://" + this.host + "/auth/me?token=" + token, true);
@@ -89,20 +89,24 @@ protected boolean prepare() {
8989
Log.w(TAG, "Invalid token, resetting...");
9090
// Remove saved preference
9191
SharedPreferences.Editor editor = this.cachedPreferences.edit();
92-
editor.remove("androidacy_token");
92+
editor.remove("androidacy_api_token");
9393
editor.apply();
9494
this.token = token = null;
9595
}
9696
}
9797
if (token == null) {
9898
try {
9999
Log.i(TAG, "Refreshing token...");
100+
// POST request to https://production-api.androidacy.com/auth/register
100101
token = new String(Http.doHttpPost(
101102
"https://" + this.host + "/auth/register",
102103
"foxmmm=true", true), StandardCharsets.UTF_8);
104+
// Parse token
105+
JSONObject jsonObject = new JSONObject(token);
106+
token = jsonObject.getString("token");
103107
// Save token to shared preference
104108
SharedPreferences.Editor editor = this.cachedPreferences.edit();
105-
editor.putString("androidacy_token", token);
109+
editor.putString("androidacy_api_token", token);
106110
editor.apply();
107111
} catch (Exception e) {
108112
if ("Received error code: 419".equals(e.getMessage()) ||

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public final class RepoManager {
3636
"https://cdn.jsdelivr.net/gh/Magisk-Modules-Alt-Repo/json@main/modules.json";
3737

3838
public static final String ANDROIDACY_MAGISK_REPO_ENDPOINT =
39-
"https://api.androidacy.com/magisk/repo";
39+
"https://production-api.androidacy.com/magisk/repo";
4040
public static final String ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT =
4141
"https://staging-api.androidacy.com/magisk/repo";
4242
public static final String ANDROIDACY_MAGISK_REPO_HOMEPAGE =

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
270270
"https://github.com/Fox2Code/FoxMagiskModuleManager");
271271
return true;
272272
});
273+
// Add a listener to pref_androidacy_repo_api_key to update the api key in shared preferences
274+
findPreference("pref_androidacy_repo_api_key").setOnPreferenceChangeListener((preference, newValue) -> {
275+
MainApplication.getSharedPreferences().edit()
276+
.putString("androidacy_api_token", String.valueOf(newValue)).apply();
277+
return true;
278+
});
273279
findPreference("pref_support").setOnPreferenceClickListener(p -> {
274280
devModeStep = 0;
275281
IntentHelper.openUrl(p.getContext(), "https://t.me/Fox2Code_Chat");

app/src/main/res/values-cs/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@
9393
<string name="repo_enabled">Repozitář povolen</string>
9494
<string name="repo_disabled">Repozitář zakázán</string>
9595
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
96+
<string name="api_key">Androidacy API Key</string>
9697
</resources>

app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,5 @@
103103
<string name="uninstall">Deinstallieren</string>
104104
<string name="config">Konfig</string>
105105
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
106+
<string name="api_key">Androidacy API Key</string>
106107
</resources>

app/src/main/res/values-el/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,5 @@
144144
<!-- Replace with your own username when translating -->
145145
<string name="language_translated_by">Μεταφράστηκε απο Tha_14</string>
146146
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
147+
<string name="api_key">Androidacy API Key</string>
147148
</resources>

app/src/main/res/values-es-rMX/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@
128128
<string name="restore_module_list">Restaurar módulos</string>
129129
<string name="require_internet">Esta operación requiere una conexión a Internet.</string>
130130
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
131+
<string name="api_key">Androidacy API Key</string>
131132
</resources>

app/src/main/res/values-et/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@
8888
<string name="repo_enabled">Hoidla lubatud</string>
8989
<string name="repo_disabled">Hoidla keelatud</string>
9090
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
91+
<string name="api_key">Androidacy API Key</string>
9192
</resources>

app/src/main/res/values-fr/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,5 @@
128128
<string name="restore_module_list">Restaurer les modules</string>
129129
<string name="require_internet">Cette opération requière une connexion internet</string>
130130
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
131+
<string name="api_key">Androidacy API Key</string>
131132
</resources>

app/src/main/res/values-id/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@
9494
<string name="repo_enabled">Repo diaktifkan</string>
9595
<string name="repo_disabled">Repo dinonaktifkan</string>
9696
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
97+
<string name="api_key">Androidacy API Key</string>
9798
</resources>

0 commit comments

Comments
 (0)