RikkaApps / Shizuku-API

The API and the developer guide for Shizuku and Sui.
MIT License
964 stars 227 forks source link

请问如何调用非SDK系统API #22

Closed Moderpach closed 1 year ago

Moderpach commented 1 year ago

我尝试以以下方式调用非SDK系统API,但是不起作用。

public static final Singleton<IPowerManager> POWER_MANAGER = new Singleton<IPowerManager>() {
        @Override
        protected IPowerManager create() {
            return IPowerManager.Stub.asInterface(new ShizukuBinderWrapper(SystemServiceHelper.getSystemService(Context.POWER_SERVICE)));
        }
    };
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {

  //这个不是隐藏api,可以访问到值
    HiddenApiBypass.invoke(IPowerManager::class.java, ShizukuSystemServerApi.POWER_MANAGER.get(), "isPowerSaveMode", true);
  //这个是隐藏api,调用后没有反应
    HiddenApiBypass.invoke(IPowerManager::class.java, ShizukuSystemServerApi.POWER_MANAGER.get(), "setPowerSaveModeEnabled", true);
}

请问如果我要调用PowerManager里的隐藏方法我应该如何操作呢?

Moderpach commented 1 year ago

如果使用POWER_MANAGER.get().setPowerSaveModeEnabled(true); 会运行时报错: java.lang.NoSuchMethodError: No interface method setPowerSaveModeEnabled(Z)Z in class Landroid/os/IPowerManager; or its super classes (declaration of 'android.os.IPowerManager' appears in /system/framework/framework.jar!classes2.dex)