Add custom API key support

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/192/head
androidacy-user 2 years ago
parent e181fd1c93
commit cf9fe3d51f

@ -74,8 +74,8 @@ public final class AndroidacyRepoData extends RepoData {
long time = System.currentTimeMillis();
if (this.androidacyBlockade > time) return false;
this.androidacyBlockade = time + 30_000L;
// Get token from androidacy_token shared preference
String token = this.cachedPreferences.getString("androidacy_token", null);
// Get token from androidacy_api_token shared preference
String token = this.cachedPreferences.getString("androidacy_api_token", null);
if (token != null) {
try {
Http.doHttpGet("https://" + this.host + "/auth/me?token=" + token, true);
@ -89,7 +89,7 @@ public final class AndroidacyRepoData extends RepoData {
Log.w(TAG, "Invalid token, resetting...");
// Remove saved preference
SharedPreferences.Editor editor = this.cachedPreferences.edit();
editor.remove("androidacy_token");
editor.remove("androidacy_api_token");
editor.apply();
this.token = token = null;
}
@ -97,12 +97,16 @@ public final class AndroidacyRepoData extends RepoData {
if (token == null) {
try {
Log.i(TAG, "Refreshing token...");
// POST request to https://production-api.androidacy.com/auth/register
token = new String(Http.doHttpPost(
"https://" + this.host + "/auth/register",
"foxmmm=true", true), StandardCharsets.UTF_8);
// Parse token
JSONObject jsonObject = new JSONObject(token);
token = jsonObject.getString("token");
// Save token to shared preference
SharedPreferences.Editor editor = this.cachedPreferences.edit();
editor.putString("androidacy_token", token);
editor.putString("androidacy_api_token", token);
editor.apply();
} catch (Exception e) {
if ("Received error code: 419".equals(e.getMessage()) ||

@ -36,7 +36,7 @@ public final class RepoManager {
"https://cdn.jsdelivr.net/gh/Magisk-Modules-Alt-Repo/json@main/modules.json";
public static final String ANDROIDACY_MAGISK_REPO_ENDPOINT =
"https://api.androidacy.com/magisk/repo";
"https://production-api.androidacy.com/magisk/repo";
public static final String ANDROIDACY_TEST_MAGISK_REPO_ENDPOINT =
"https://staging-api.androidacy.com/magisk/repo";
public static final String ANDROIDACY_MAGISK_REPO_HOMEPAGE =

@ -270,6 +270,12 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
"https://github.com/Fox2Code/FoxMagiskModuleManager");
return true;
});
// Add a listener to pref_androidacy_repo_api_key to update the api key in shared preferences
findPreference("pref_androidacy_repo_api_key").setOnPreferenceChangeListener((preference, newValue) -> {
MainApplication.getSharedPreferences().edit()
.putString("androidacy_api_token", String.valueOf(newValue)).apply();
return true;
});
findPreference("pref_support").setOnPreferenceClickListener(p -> {
devModeStep = 0;
IntentHelper.openUrl(p.getContext(), "https://t.me/Fox2Code_Chat");

@ -93,4 +93,5 @@
<string name="repo_enabled">Repozitář povolen</string>
<string name="repo_disabled">Repozitář zakázán</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -103,4 +103,5 @@
<string name="uninstall">Deinstallieren</string>
<string name="config">Konfig</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -144,4 +144,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">Μεταφράστηκε απο Tha_14</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -128,4 +128,5 @@
<string name="restore_module_list">Restaurar módulos</string>
<string name="require_internet">Esta operación requiere una conexión a Internet.</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -88,4 +88,5 @@
<string name="repo_enabled">Hoidla lubatud</string>
<string name="repo_disabled">Hoidla keelatud</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -128,4 +128,5 @@
<string name="restore_module_list">Restaurer les modules</string>
<string name="require_internet">Cette opération requière une connexion internet</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -94,4 +94,5 @@
<string name="repo_enabled">Repo diaktifkan</string>
<string name="repo_disabled">Repo dinonaktifkan</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -149,4 +149,5 @@
<!-- Sostituisci con il tuo nome utente durante la traduzione -->
<string name="language_translated_by">Traduzione di tugaia56</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -41,4 +41,5 @@
<string name="dev_mode_enabled">開発者モードが有効です</string>
<string name="force_english_pref">Force English language</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -95,4 +95,5 @@
<string name="repo_enabled">Pakkebrønn på</string>
<string name="repo_disabled">Pakkebrønn av</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -147,4 +147,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">Tłumaczenie: Daviteusz</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -149,4 +149,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">Traduzido por mi007d e DanGLES3</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -138,4 +138,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">Tradus de Fox2Code</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -124,4 +124,5 @@
<string name="restore_module_list">Восстановить модули</string>
<string name="require_internet">Для этого действия потребуется подключение к Интернету</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -93,4 +93,5 @@
<string name="repo_enabled">Repozitár povolený</string>
<string name="repo_disabled">Repozitár zakázaný</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -147,4 +147,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">Alprnn357 tarafından çevrildi</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -123,4 +123,5 @@
<string name="restore_module_list">Khôi phục mô-đun</string>
<string name="require_internet">Quá trình này yêu cầu kết nối internet</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -150,4 +150,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">由ender-zhao翻译</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -140,4 +140,5 @@
<!-- Replace with your own username when translating -->
<string name="language_translated_by">由 OrStudio.tw(@crcky5322) 提供美妙的翻譯</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
</resources>

@ -154,4 +154,6 @@
<string name="language_translated_by">Translated by Fox2Code</string>
<string name="crash_reporting">Automatically report bugs and performance to the developers</string>
<string name="crash_reporting_desc">If you disable this, the developer will not get automatic bug reports, and this may make troubleshooting harder</string>
<string name="api_key">Androidacy API Key</string>
<string name="api_key_summary">Use a custom API key for Androidacy</string>
</resources>

@ -59,6 +59,13 @@
app:icon="@drawable/ic_baseline_upload_file_24"
app:title="@string/submit_modules"
app:singleLineTitle="false" />
<!-- Allow user to set custom API key for Androidacy repo -->
<EditTextPreference
app:key="pref_androidacy_repo_api_key"
app:icon="@drawable/ic_baseline_security_24"
app:title="@string/api_key"
app:summary="@string/api_key_summary"
app:singleLineTitle="false" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:key="pref_androidacy_test_mode"

Loading…
Cancel
Save