Skip to content

Commit a93d74d

Browse files
fix(Google Photos): Resolve startup crash if MicroG GmsCore does not already have granted permissions
1 parent be4a7ef commit a93d74d

File tree

3 files changed

+19
-26
lines changed

3 files changed

+19
-26
lines changed

extensions/shared/library/src/main/java/app/revanced/extension/shared/Logger.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
* ReVanced specific logger. Logging is done to standard device log (accessible thru ADB),
2020
* and additionally accessible thru {@link LogBufferManager}.
2121
*
22-
* All methods are thread safe.
22+
* All methods are thread safe, and are safe to call even
23+
* if {@link Utils#getContext()} is not available.
2324
*/
2425
public class Logger {
2526

@@ -138,6 +139,14 @@ private static void logInternal(LogLevel logLevel, LogMessage message, @Nullable
138139
}
139140
}
140141

142+
private static boolean includeStackTrace() {
143+
return Utils.context != null && DEBUG_STACKTRACE.get();
144+
}
145+
146+
private static boolean shouldShowErrorToast() {
147+
return Utils.context != null && DEBUG_TOAST_ON_ERROR.get();
148+
}
149+
141150
/**
142151
* Logs debug messages under the outer class name of the code calling this method.
143152
* <p>
@@ -158,7 +167,7 @@ public static void printDebug(LogMessage message) {
158167
*/
159168
public static void printDebug(LogMessage message, @Nullable Exception ex) {
160169
if (DEBUG.get()) {
161-
logInternal(LogLevel.DEBUG, message, ex, DEBUG_STACKTRACE.get(), false);
170+
logInternal(LogLevel.DEBUG, message, ex, includeStackTrace(), false);
162171
}
163172
}
164173

@@ -173,7 +182,7 @@ public static void printInfo(LogMessage message) {
173182
* Logs information messages using the outer class name of the code calling this method.
174183
*/
175184
public static void printInfo(LogMessage message, @Nullable Exception ex) {
176-
logInternal(LogLevel.INFO, message, ex, DEBUG_STACKTRACE.get(), false);
185+
logInternal(LogLevel.INFO, message, ex, includeStackTrace(), false);
177186
}
178187

179188
/**
@@ -194,22 +203,6 @@ public static void printException(LogMessage message) {
194203
* @param ex exception (optional)
195204
*/
196205
public static void printException(LogMessage message, @Nullable Throwable ex) {
197-
logInternal(LogLevel.ERROR, message, ex, DEBUG_STACKTRACE.get(), DEBUG_TOAST_ON_ERROR.get());
198-
}
199-
200-
/**
201-
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
202-
* Normally this method should not be used.
203-
*/
204-
public static void initializationInfo(LogMessage message) {
205-
logInternal(LogLevel.INFO, message, null, false, false);
206-
}
207-
208-
/**
209-
* Logging to use if {@link BaseSettings#DEBUG} or {@link Utils#getContext()} may not be initialized.
210-
* Normally this method should not be used.
211-
*/
212-
public static void initializationException(LogMessage message, @Nullable Exception ex) {
213-
logInternal(LogLevel.ERROR, message, ex, false, false);
206+
logInternal(LogLevel.ERROR, message, ex, includeStackTrace(), shouldShowErrorToast());
214207
}
215208
}

extensions/shared/library/src/main/java/app/revanced/extension/shared/Utils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
public class Utils {
5656

5757
@SuppressLint("StaticFieldLeak")
58-
private static volatile Context context;
58+
static volatile Context context;
5959

6060
private static String versionName;
6161
private static String applicationLabel;
@@ -363,15 +363,15 @@ public static void restartApp(@NonNull Context context) {
363363

364364
public static Context getContext() {
365365
if (context == null) {
366-
Logger.initializationException(() -> "Context is not set by extension hook, returning null", null);
366+
Logger.printException(() -> "Context is not set by extension hook, returning null", null);
367367
}
368368
return context;
369369
}
370370

371371
public static void setContext(Context appContext) {
372372
// Intentionally use logger before context is set,
373-
// to expose any bugs in the 'no context available' logger method.
374-
Logger.initializationInfo(() -> "Set context: " + appContext);
373+
// to expose any bugs in the 'no context available' logger code.
374+
Logger.printInfo(() -> "Set context: " + appContext);
375375
// Must initially set context to check the app language.
376376
context = appContext;
377377

@@ -554,7 +554,7 @@ private static void showToast(@NonNull String messageToToast, int toastDuration)
554554
Context currentContext = context;
555555

556556
if (currentContext == null) {
557-
Logger.initializationException(() -> "Cannot show toast (context is null): " + messageToToast, null);
557+
Logger.printException(() -> "Cannot show toast (context is null): " + messageToToast, null);
558558
} else {
559559
Logger.printDebug(() -> "Showing toast: " + messageToToast);
560560
Toast.makeText(currentContext, messageToToast, toastDuration).show();

extensions/tiktok/src/main/java/app/revanced/extension/tiktok/spoof/sim/SpoofSimPatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private static boolean isContextNotSet(String fieldSpoofed) {
1616
return false;
1717
}
1818

19-
Logger.initializationException(() -> "Context is not yet set, cannot spoof: " + fieldSpoofed, null);
19+
Logger.printException(() -> "Context is not yet set, cannot spoof: " + fieldSpoofed, null);
2020
return true;
2121
}
2222

0 commit comments

Comments
 (0)