2121
2222import static com .sevtinge .hyperceiler .libhook .utils .hookapi .tool .EzxHelpUtils .deoptimize ;
2323
24+ import android .os .Bundle ;
25+
2426import com .sevtinge .hyperceiler .common .log .XposedLog ;
2527import com .sevtinge .hyperceiler .libhook .base .BaseHook ;
2628
2729import java .lang .reflect .Method ;
30+ import java .util .List ;
2831
2932import io .github .libxposed .api .XposedInterface ;
3033
3336 * https://github.com/Howard20181/HyperOS_FCM_Live/blob/main/HyperFCMLive/src/main/java/io/github/howard20181/hyperos/fcmlive/Hooker.java
3437 */
3538public class GmsDozeFix extends BaseHook {
39+ private static final String GMS_PACKAGE_NAME = "com.google.android.gms" ;
40+
3641 private static final String [] GMS_OBSERVER_METHODS = new String []{
3742 "updateGmsNetWork" ,
3843 "updateGmsAlarm" ,
@@ -49,6 +54,29 @@ public class GmsDozeFix extends BaseHook {
4954
5055 @ Override
5156 public void init () {
57+ hookGmsObserver ();
58+ hookGlobalFeatureConfigureHelper ();
59+ }
60+
61+ private void hookGmsObserver () {
62+ Class <?> netdExecutorClass = findClassIfExists ("com.miui.powerkeeper.utils.NetdExecutor" );
63+ if (netdExecutorClass != null ) {
64+ try {
65+ Method initGmsChainMethod = netdExecutorClass .getDeclaredMethod (
66+ "initGmsChain" , String .class , int .class , String .class );
67+ chain (initGmsChainMethod , chain -> {
68+ Object [] args = chain .getArgs ().toArray ();
69+ args [2 ] = "ACCEPT" ;
70+ return chain .proceed (args );
71+ });
72+ deoptimize (initGmsChainMethod );
73+ } catch (NoSuchMethodException e ) {
74+ XposedLog .w (TAG , getPackageName (), "Skip missing method: NetdExecutor#initGmsChain" , e );
75+ } catch (Throwable t ) {
76+ XposedLog .e (TAG , getPackageName (), "Hook failed in initGmsChain" , t );
77+ }
78+ }
79+
5280 Class <?> gmsObserverClass = findClassIfExists ("com.miui.powerkeeper.utils.GmsObserver" );
5381 if (gmsObserverClass == null ) return ;
5482
@@ -57,6 +85,33 @@ public void init() {
5785 }
5886 }
5987
88+ @ SuppressWarnings ("unchecked" )
89+ private void hookGlobalFeatureConfigureHelper () {
90+ Class <?> helperClass = findClassIfExists (
91+ "com.miui.powerkeeper.provider.GlobalFeatureConfigureHelper" );
92+ if (helperClass == null ) return ;
93+
94+ try {
95+ Method getDozeWhiteListAppsMethod = helperClass .getDeclaredMethod (
96+ "getDozeWhiteListApps" , Bundle .class );
97+ chain (getDozeWhiteListAppsMethod , chain -> {
98+ Object result = chain .proceed ();
99+ if (result instanceof List <?>) {
100+ List <String > whiteList = (List <String >) result ;
101+ if (!whiteList .contains (GMS_PACKAGE_NAME )) {
102+ whiteList .add (GMS_PACKAGE_NAME );
103+ }
104+ }
105+ return result ;
106+ });
107+ } catch (NoSuchMethodException e ) {
108+ XposedLog .w (TAG , getPackageName (),
109+ "Skip missing method: GlobalFeatureConfigureHelper#getDozeWhiteListApps" , e );
110+ } catch (Throwable t ) {
111+ XposedLog .e (TAG , getPackageName (), "Hook failed in getDozeWhiteListApps" , t );
112+ }
113+ }
114+
60115 private void hookObserverMethod (Class <?> observerClass , String methodName ) {
61116 try {
62117 Method method = observerClass .getDeclaredMethod (methodName , boolean .class );
0 commit comments