fix(Google Photos): Resolve startup crash if MicroG GmsCore does not already have granted permissions

This commit is contained in:
LisoUseInAIKyrios
2025-06-11 19:40:37 +02:00
parent be4a7ef241
commit a93d74d26e
3 changed files with 19 additions and 26 deletions

View File

@ -19,7 +19,8 @@ import app.revanced.extension.shared.settings.preference.LogBufferManager;
* ReVanced specific logger. Logging is done to standard device log (accessible thru ADB),
* and additionally accessible thru {@link LogBufferManager}.
*
* All methods are thread safe.
* All methods are thread safe, and are safe to call even
* if {@link Utils#getContext()} is not available.
*/
public class Logger {
@ -138,6 +139,14 @@ public class Logger {
}
}
private static boolean includeStackTrace() {
return Utils.context != null && DEBUG_STACKTRACE.get();
}
private static boolean shouldShowErrorToast() {
return Utils.context != null && DEBUG_TOAST_ON_ERROR.get();
}
/**
* Logs debug messages under the outer class name of the code calling this method.
* <p>
@ -158,7 +167,7 @@ public class Logger {
*/
public static void printDebug(LogMessage message, @Nullable Exception ex) {
if (DEBUG.get()) {
logInternal(LogLevel.DEBUG, message, ex, DEBUG_STACKTRACE.get(), false);
logInternal(LogLevel.DEBUG, message, ex, includeStackTrace(), false);
}
}
@ -173,7 +182,7 @@ public class Logger {
* Logs information messages using the outer class name of the code calling this method.
*/
public static void printInfo(LogMessage message, @Nullable Exception ex) {
logInternal(LogLevel.INFO, message, ex, DEBUG_STACKTRACE.get(), false);
logInternal(LogLevel.INFO, message, ex, includeStackTrace(), false);
}
/**
@ -194,22 +203,6 @@ public class Logger {
* @param ex exception (optional)
*/
public static void printException(LogMessage message, @Nullable Throwable ex) {
logInternal(LogLevel.ERROR, message, ex, DEBUG_STACKTRACE.get(), DEBUG_TOAST_ON_ERROR.get());
}
/**
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
* Normally this method should not be used.
*/
public static void initializationInfo(LogMessage message) {
logInternal(LogLevel.INFO, message, null, false, false);
}
/**
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
* Normally this method should not be used.
*/
public static void initializationException(LogMessage message, @Nullable Exception ex) {
logInternal(LogLevel.ERROR, message, ex, false, false);
logInternal(LogLevel.ERROR, message, ex, includeStackTrace(), shouldShowErrorToast());
}
}

View File

@ -55,7 +55,7 @@ import app.revanced.extension.shared.settings.preference.ReVancedAboutPreference
public class Utils {
@SuppressLint("StaticFieldLeak")
private static volatile Context context;
static volatile Context context;
private static String versionName;
private static String applicationLabel;
@ -363,15 +363,15 @@ public class Utils {
public static Context getContext() {
if (context == null) {
Logger.initializationException(() -> "Context is not set by extension hook, returning null", null);
Logger.printException(() -> "Context is not set by extension hook, returning null", null);
}
return context;
}
public static void setContext(Context appContext) {
// Intentionally use logger before context is set,
// to expose any bugs in the 'no context available' logger method.
Logger.initializationInfo(() -> "Set context: " + appContext);
// to expose any bugs in the 'no context available' logger code.
Logger.printInfo(() -> "Set context: " + appContext);
// Must initially set context to check the app language.
context = appContext;
@ -554,7 +554,7 @@ public class Utils {
Context currentContext = context;
if (currentContext == null) {
Logger.initializationException(() -> "Cannot show toast (context is null): " + messageToToast, null);
Logger.printException(() -> "Cannot show toast (context is null): " + messageToToast, null);
} else {
Logger.printDebug(() -> "Showing toast: " + messageToToast);
Toast.makeText(currentContext, messageToToast, toastDuration).show();

View File

@ -16,7 +16,7 @@ public class SpoofSimPatch {
return false;
}
Logger.initializationException(() -> "Context is not yet set, cannot spoof: " + fieldSpoofed, null);
Logger.printException(() -> "Context is not yet set, cannot spoof: " + fieldSpoofed, null);
return true;
}