some missed enc prefs

Signed-off-by: androidacy-user <opensource@androidacy.com>
pull/299/head
androidacy-user 1 year ago
parent b000ed778f
commit acfb2caf7d

@ -64,8 +64,7 @@ public class CrashHandler extends FoxActivity {
stacktrace = stacktrace.replace(",", "\n ");
crashDetails.setText(getString(R.string.crash_full_stacktrace, stacktrace));
}
SharedPreferences preferences = getSharedPreferences("sentry", MODE_PRIVATE);
// get lastEventId from intent
SharedPreferences preferences = MainApplication.getPreferences("sentry");
String lastEventId = getIntent().getStringExtra("lastEventId");
Timber.d("CrashHandler.onCreate: lastEventId=%s, crashReportingEnabled=%s", lastEventId, crashReportingEnabled);
if (lastEventId == null && crashReportingEnabled) {

@ -263,14 +263,12 @@ public final class AndroidacyActivity extends FoxActivity {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (BuildConfig.DEBUG) {
switch (consoleMessage.messageLevel()) {
case TIP -> Timber.v(consoleMessage.message());
case LOG -> Timber.i(consoleMessage.message());
case WARNING -> Timber.w(consoleMessage.message());
case ERROR -> Timber.e(consoleMessage.message());
case DEBUG -> Timber.d(consoleMessage.message());
}
switch (consoleMessage.messageLevel()) {
case TIP -> Timber.tag("JSLog").i(consoleMessage.message());
case LOG -> Timber.tag("JSLog").d(consoleMessage.message());
case WARNING -> Timber.tag("JSLog").w(consoleMessage.message());
case ERROR -> Timber.tag("JSLog").e(consoleMessage.message());
default -> Timber.tag("JSLog").v(consoleMessage.message());
}
return true;
}

@ -1,7 +1,6 @@
package com.fox2code.mmm.androidacy;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@ -18,9 +17,9 @@ import com.fox2code.mmm.manager.ModuleInfo;
import com.fox2code.mmm.repo.RepoData;
import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.repo.RepoModule;
import com.fox2code.mmm.utils.io.PropUtils;
import com.fox2code.mmm.utils.io.net.Http;
import com.fox2code.mmm.utils.io.net.HttpException;
import com.fox2code.mmm.utils.io.PropUtils;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.topjohnwu.superuser.Shell;
@ -55,7 +54,6 @@ public final class AndroidacyRepoData extends RepoData {
@SuppressWarnings("unused")
public final String ClientID = BuildConfig.ANDROIDACY_CLIENT_ID;
public final SharedPreferences cachedPreferences = MainApplication.getPreferences("androidacy");
private final boolean testMode;
private final String host;
public String[][] userInfo = new String[][]{{"role", null}, {"permissions", null}};
@ -158,7 +156,7 @@ public final class AndroidacyRepoData extends RepoData {
if (e.getErrorCode() == 401) {
Timber.w("Invalid token, resetting...");
// Remove saved preference
SharedPreferences.Editor editor = MainApplication.getINSTANCE().getSharedPreferences("androidacy", 0).edit();
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit();
editor.remove("pref_androidacy_api_token");
editor.apply();
return false;
@ -170,14 +168,14 @@ public final class AndroidacyRepoData extends RepoData {
Timber.w("Invalid token, resetting...");
Timber.w(e);
// Remove saved preference
SharedPreferences.Editor editor = MainApplication.getINSTANCE().getSharedPreferences("androidacy", 0).edit();
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit();
editor.remove("pref_androidacy_api_token");
editor.apply();
return false;
}
}
@SuppressLint("RestrictedApi")
@SuppressLint({"RestrictedApi", "BinaryOperationInTimber"})
@Override
protected boolean prepare() {
// If ANDROIDACY_CLIENT_ID is not set or is empty, disable this repo and return
@ -223,17 +221,18 @@ public final class AndroidacyRepoData extends RepoData {
this.androidacyBlockade = time + 30_000L;
try {
if (token == null) {
token = this.cachedPreferences.getString("pref_androidacy_api_token", null);
token = MainApplication.getPreferences("androidacy").getString("pref_androidacy_api_token", null);
if (token != null && !this.isValidToken(token)) {
Timber.i("Token expired or invalid, requesting new one...");
token = null;
} else {
Timber.i("Using cached token");
}
} else if (!this.isValidToken(token)) {
if (BuildConfig.DEBUG) {
throw new IllegalStateException("Invalid token: " + token);
}
Timber.i("Token expired, requesting new one...");
token = null;
} else {
Timber.i("Using validated cached token");
}
} catch (
IOException e) {
@ -244,6 +243,7 @@ public final class AndroidacyRepoData extends RepoData {
return false;
}
if (token == null) {
Timber.i("Token is null, requesting new one...");
try {
Timber.i("Requesting new token...");
// POST json request to https://production-api.androidacy.com/auth/register
@ -251,8 +251,10 @@ public final class AndroidacyRepoData extends RepoData {
// Parse token
try {
JSONObject jsonObject = new JSONObject(token);
Timber.d("Token: %s", token);
// log last four of token, replacing the rest with asterisks
token = jsonObject.getString("token");
//noinspection SuspiciousRegexArgument
Timber.d("Token: %s", token.substring(0, token.length() - 4).replaceAll(".", "*") + token.substring(token.length() - 4));
memberLevel = jsonObject.getString("role");
} catch (
JSONException e) {
@ -271,11 +273,13 @@ public final class AndroidacyRepoData extends RepoData {
Handler handler = new Handler(mainLooper);
handler.post(() -> Toast.makeText(MainApplication.getINSTANCE(), R.string.androidacy_failed_to_validate_token, Toast.LENGTH_LONG).show());
return false;
} else {
// Save token to shared preference
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit();
editor.putString("pref_androidacy_api_token", token);
editor.apply();
Timber.i("Token saved to shared preference");
}
// Save token to shared preference
SharedPreferences.Editor editor = MainApplication.getINSTANCE().getSharedPreferences("androidacy", Context.MODE_PRIVATE).edit();
editor.putString("pref_androidacy_api_token", token);
editor.apply();
} catch (
Exception e) {
if (HttpException.shouldTimeout(e)) {

@ -311,7 +311,7 @@ public final class RepoManager extends SyncManager {
builder.setPositiveButton(android.R.string.ok, null);
if (repoUpdaters[finalI].repoData instanceof AndroidacyRepoData) {
builder.setNeutralButton(R.string.reset_api_key, (dialog, which) -> {
SharedPreferences.Editor editor = MainApplication.getINSTANCE().getSharedPreferences("androidacy", 0).edit();
SharedPreferences.Editor editor = MainApplication.getPreferences("androidacy").edit();
editor.putString("androidacy_api_key", "");
editor.apply();
Toast.makeText(context, R.string.api_key_removed, Toast.LENGTH_SHORT).show();

@ -28,7 +28,6 @@ import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
@ -73,7 +72,6 @@ import com.fox2code.rosettax.LanguageActivity;
import com.fox2code.rosettax.LanguageSwitcher;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.internal.TextWatcherAdapter;
import com.google.android.material.navigation.NavigationBarView;
import com.google.android.material.snackbar.BaseTransientBottomBar;
import com.google.android.material.snackbar.Snackbar;
@ -1118,7 +1116,6 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
if (initial) { // Custom repo add button part.
preference = findPreference("pref_custom_add_repo_button");
if (preference == null) return;
int finalCUSTOM_REPO_ENTRIES = CUSTOM_REPO_ENTRIES;
preference.setOnPreferenceClickListener(preference1 -> {
final Context context = this.requireContext();
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
@ -1188,14 +1185,8 @@ public class SettingsActivity extends FoxActivity implements LanguageActivity {
}
@Override
public CharSequence fixText(CharSequence charSequence) {
return charSequence;
}
});
input.addTextChangedListener(new TextWatcherAdapter() {
@Override
public void onTextChanged(@NonNull CharSequence charSequence, int i, int i1, int i2) {
positiveButton.setEnabled(customRepoManager.canAddRepo(charSequence.toString()) && customRepoManager.getRepoCount() < finalCUSTOM_REPO_ENTRIES);
public CharSequence fixText(CharSequence invalidText) {
return null;
}
});
positiveButton.setEnabled(false);

Loading…
Cancel
Save