Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52c24b37 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Move DeviceIdle to the JS apex

Test: atest cts/tests/tests/batterysaving/src/android/os/cts/deviceidle/DeviceIdleTest.java
Bug: 137763703
Change-Id: I836350c09f45f95afbf90b562ab1ceed75526498
parent 903102c4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ filegroup {
        "java/android/app/job/IJobCallback.aidl",
        "java/android/app/job/IJobScheduler.aidl",
        "java/android/app/job/IJobService.aidl",
        "java/android/os/IDeviceIdleController.aidl",
    ],
    path: "java",
}
+18 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package android.app;
import android.content.Context;
import android.os.DeviceIdleManager;
import android.os.IDeviceIdleController;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;

/**
 * This class needs to be pre-loaded by zygote.  This is where the device idle manager wrapper
@@ -27,10 +30,25 @@ import android.os.IDeviceIdleController;
 * @hide
 */
public class DeviceIdleFrameworkInitializer {
    private static IDeviceIdleController sIDeviceIdleController;

    static {
        SystemServiceRegistry.registerCachedService(
                Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class,
                (context, b) -> new DeviceIdleManager(
                        context.getOuterContext(), IDeviceIdleController.Stub.asInterface(b)));
        PowerManager.setIsIgnoringBatteryOptimizationsCallback((packageName) -> {
            // No need for synchronization on sIDeviceIdleController; worst case
            // we just initialize it twice.
            if (sIDeviceIdleController == null) {
                sIDeviceIdleController = IDeviceIdleController.Stub.asInterface(
                        ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
            }
            try {
                return sIDeviceIdleController.isPowerSaveWhitelistApp(packageName);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        });
    }
}
Loading