mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-29 22:24:27 +02:00
fix(TikTok): Resolve startup app crash
This commit is contained in:
parent
e0de416ea5
commit
18c0fc2a7f
@ -356,7 +356,7 @@ public class Utils {
|
||||
|
||||
public static Context getContext() {
|
||||
if (context == null) {
|
||||
Logger.initializationException(Utils.class, "Context is null, returning null!", null);
|
||||
Logger.initializationException(Utils.class, "Context is not set by extension hook, returning null", null);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
@ -1,37 +1,60 @@
|
||||
package app.revanced.extension.tiktok.spoof.sim;
|
||||
|
||||
import app.revanced.extension.shared.Logger;
|
||||
import app.revanced.extension.shared.Utils;
|
||||
import app.revanced.extension.tiktok.settings.Settings;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class SpoofSimPatch {
|
||||
|
||||
private static final boolean ENABLED = Settings.SIM_SPOOF.get();
|
||||
/**
|
||||
* During app startup native code can be called with no obvious way to set the context.
|
||||
* Cannot check if sim spoofing is enabled or the app will crash since no context is set.
|
||||
*/
|
||||
private static boolean isContextNotSet(String fieldSpoofed) {
|
||||
if (Utils.getContext() != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Logger.initializationException(SpoofSimPatch.class,
|
||||
"Context is not yet set, cannot spoof: " + fieldSpoofed, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getCountryIso(String value) {
|
||||
if (ENABLED) {
|
||||
if (isContextNotSet("countryIso")) return value;
|
||||
|
||||
if (Settings.SIM_SPOOF.get()) {
|
||||
String iso = Settings.SIM_SPOOF_ISO.get();
|
||||
Logger.printDebug(() -> "Spoofing sim ISO from: " + value + " to: " + iso);
|
||||
Logger.printDebug(() -> "Spoofing countryIso from: " + value + " to: " + iso);
|
||||
return iso;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getOperator(String value) {
|
||||
if (ENABLED) {
|
||||
if (isContextNotSet("MCC-MNC")) return value;
|
||||
|
||||
if (Settings.SIM_SPOOF.get()) {
|
||||
String mcc_mnc = Settings.SIMSPOOF_MCCMNC.get();
|
||||
Logger.printDebug(() -> "Spoofing sim MCC-MNC from: " + value + " to: " + mcc_mnc);
|
||||
return mcc_mnc;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static String getOperatorName(String value) {
|
||||
if (ENABLED) {
|
||||
if (isContextNotSet("operatorName")) return value;
|
||||
|
||||
if (Settings.SIM_SPOOF.get()) {
|
||||
String operator = Settings.SIMSPOOF_OP_NAME.get();
|
||||
Logger.printDebug(() -> "Spoofing sim operator from: " + value + " to: " + operator);
|
||||
Logger.printDebug(() -> "Spoofing sim operatorName from: " + value + " to: " + operator);
|
||||
return operator;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user