Skip to content

Commit 45b5a51

Browse files
author
LisoUseInAIKyrios
authored
feat(YouTube - GmsCore support): Show troubleshooting in app text if the user recently changed their account details (#4879)
1 parent 8abf176 commit 45b5a51

File tree

6 files changed

+143
-4
lines changed

6 files changed

+143
-4
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import java.net.MalformedURLException;
2121
import java.net.URL;
2222

23-
/**
24-
* @noinspection unused
25-
*/
23+
@SuppressWarnings("unused")
2624
public class GmsCoreSupport {
2725
private static final String PACKAGE_NAME_YOUTUBE = "com.google.android.youtube";
2826
private static final String PACKAGE_NAME_YOUTUBE_MUSIC = "com.google.android.apps.youtube.music";
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package app.revanced.extension.youtube.patches;
2+
3+
import static app.revanced.extension.shared.StringRef.sf;
4+
5+
import app.revanced.extension.shared.Logger;
6+
import app.revanced.extension.shared.Utils;
7+
8+
@SuppressWarnings("unused")
9+
public class AccountCredentialsInvalidTextPatch {
10+
11+
/**
12+
* Injection point.
13+
*/
14+
public static String getOfflineNetworkErrorString(String original) {
15+
try {
16+
if (Utils.isNetworkConnected()) {
17+
Logger.printDebug(() -> "Network appears to be online, but app is showing offline error");
18+
return '\n' + sf("microg_offline_account_login_error").toString();
19+
}
20+
21+
Logger.printDebug(() -> "Network is offline");
22+
} catch (Exception ex) {
23+
Logger.printException(() -> "getOfflineNetworkErrorString failure", ex);
24+
}
25+
26+
return original;
27+
}
28+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package app.revanced.patches.youtube.misc.gms
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
4+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
5+
import app.revanced.patcher.patch.bytecodePatch
6+
import app.revanced.patcher.patch.resourcePatch
7+
import app.revanced.patches.all.misc.resources.addResources
8+
import app.revanced.patches.all.misc.resources.addResourcesPatch
9+
import app.revanced.patches.shared.misc.mapping.get
10+
import app.revanced.patches.shared.misc.mapping.resourceMappings
11+
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
12+
import app.revanced.util.getReference
13+
import app.revanced.util.indexOfFirstInstructionOrThrow
14+
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
15+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
16+
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
17+
18+
private const val EXTENSION_CLASS_DESCRIPTOR =
19+
"Lapp/revanced/extension/youtube/patches/AccountCredentialsInvalidTextPatch;"
20+
21+
internal var ic_offline_no_content_upside_down = -1L
22+
private set
23+
internal var offline_no_content_body_text_not_offline_eligible = -1L
24+
private set
25+
26+
private val accountCredentialsInvalidTextResourcePatch = resourcePatch {
27+
execute {
28+
ic_offline_no_content_upside_down = resourceMappings[
29+
"drawable",
30+
"ic_offline_no_content_upside_down"
31+
]
32+
33+
offline_no_content_body_text_not_offline_eligible = resourceMappings[
34+
"string",
35+
"offline_no_content_body_text_not_offline_eligible"
36+
]
37+
}
38+
}
39+
40+
internal val accountCredentialsInvalidTextPatch = bytecodePatch {
41+
dependsOn(
42+
sharedExtensionPatch,
43+
accountCredentialsInvalidTextResourcePatch,
44+
addResourcesPatch
45+
)
46+
47+
execute {
48+
addResources("youtube", "misc.gms.accountCredentialsInvalidTextPatch")
49+
50+
// If the user recently changed their account password,
51+
// the app can show "You're offline. Check your internet connection."
52+
// even when the internet is available. For this situation
53+
// YouTube + MicroG shows an offline error message.
54+
//
55+
// Change the error text to inform the user to uninstall and reinstall MicroG.
56+
// The user can also fix this by deleting the MicroG account but
57+
// MicroG accounts look almost identical to Google device accounts
58+
// and it's more foolproof to instead uninstall/reinstall.
59+
arrayOf(
60+
specificNetworkErrorViewControllerFingerprint,
61+
loadingFrameLayoutControllerFingerprint
62+
).forEach { fingerprint ->
63+
fingerprint.method.apply {
64+
val resourceIndex = indexOfFirstLiteralInstructionOrThrow(
65+
offline_no_content_body_text_not_offline_eligible
66+
)
67+
val getStringIndex = indexOfFirstInstructionOrThrow(resourceIndex) {
68+
val reference = getReference<MethodReference>()
69+
reference?.name == "getString"
70+
}
71+
val register = getInstruction<OneRegisterInstruction>(getStringIndex + 1).registerA
72+
73+
addInstructions(
74+
getStringIndex + 2,
75+
"""
76+
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getOfflineNetworkErrorString(Ljava/lang/String;)Ljava/lang/String;
77+
move-result-object v$register
78+
"""
79+
)
80+
}
81+
}
82+
}
83+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package app.revanced.patches.youtube.misc.gms
2+
3+
import app.revanced.patcher.fingerprint
4+
import app.revanced.util.containsLiteralInstruction
5+
import com.android.tools.smali.dexlib2.AccessFlags
6+
7+
internal val specificNetworkErrorViewControllerFingerprint = fingerprint {
8+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
9+
returns("V")
10+
parameters()
11+
custom { method, _ ->
12+
method.containsLiteralInstruction(ic_offline_no_content_upside_down)
13+
&& method.containsLiteralInstruction(offline_no_content_body_text_not_offline_eligible)
14+
}
15+
}
16+
17+
// It's not clear if this second class is ever used and it may be dead code,
18+
// but it the layout image/text is identical to the network error fingerprint above.
19+
internal val loadingFrameLayoutControllerFingerprint = fingerprint {
20+
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
21+
returns("V")
22+
parameters("L")
23+
custom { method, _ ->
24+
method.containsLiteralInstruction(ic_offline_no_content_upside_down)
25+
&& method.containsLiteralInstruction(offline_no_content_body_text_not_offline_eligible)
26+
}
27+
}

patches/src/main/kotlin/app/revanced/patches/youtube/misc/gms/GmsCoreSupportPatch.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ private fun gmsCoreSupportResourcePatch(
6868
)
6969
},
7070
) {
71-
dependsOn(settingsPatch, addResourcesPatch)
71+
dependsOn(settingsPatch, addResourcesPatch, accountCredentialsInvalidTextPatch)
7272
}

patches/src/main/resources/addresources/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,9 @@ Enabling this can unlock higher video qualities"</string>
13791379
<string name="microg_settings_title">GmsCore Settings</string>
13801380
<string name="microg_settings_summary">Settings for GmsCore</string>
13811381
</patch>
1382+
<patch id="misc.gms.accountCredentialsInvalidTextPatch">
1383+
<string name="microg_offline_account_login_error">If you recently changed your account login details, then uninstall and reinstall MicroG.</string>
1384+
</patch>
13821385
<patch id="misc.links.bypassURLRedirectsPatch">
13831386
<string name="revanced_bypass_url_redirects_title">Bypass URL redirects</string>
13841387
<string name="revanced_bypass_url_redirects_summary_on">URL redirects are bypassed</string>

0 commit comments

Comments
 (0)