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

Commit e40aa2d1 authored by Michael Sun's avatar Michael Sun Committed by Gerrit Code Review
Browse files

Merge "Update to use new android.system.suspend.control AIDL interface"

parents 20a9e59e d523796e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -447,7 +447,6 @@ java_library {
    name: "framework-internal-utils",
    static_libs: [
        "apex_aidl_interface-java",
        "suspend_control_aidl_interface-java",
        "framework-protos",
        "updatable-driver-protos",
        "android.hidl.base-V1.0-java",
@@ -481,6 +480,7 @@ java_library {
        "android.hardware.vibrator-V1.2-java",
        "android.hardware.vibrator-V1.3-java",
        "android.system.keystore2-java",
        "android.system.suspend.control.internal-java",
        "devicepolicyprotosnano",

        "com.android.sysprop.apex",
+7 −6
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.StrictMode;
import android.os.SystemClock;
import android.system.suspend.ISuspendControlService;
import android.system.suspend.WakeLockInfo;
import android.system.suspend.internal.ISuspendControlServiceInternal;
import android.system.suspend.internal.WakeLockInfo;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
@@ -66,7 +66,7 @@ public class KernelWakelockReader {

    private final String[] mProcWakelocksName = new String[3];
    private final long[] mProcWakelocksData = new long[3];
    private ISuspendControlService mSuspendControlService = null;
    private ISuspendControlServiceInternal mSuspendControlService = null;
    private byte[] mKernelWakelockBuffer = new byte[32 * 1024];

    /**
@@ -155,11 +155,12 @@ public class KernelWakelockReader {
    /**
     * Attempt to wait for suspend_control service if not immediately available.
     */
    private ISuspendControlService waitForSuspendControlService() throws ServiceNotFoundException {
        final String name = "suspend_control";
    private ISuspendControlServiceInternal waitForSuspendControlService()
            throws ServiceNotFoundException {
        final String name = "suspend_control_internal";
        final int numRetries = 5;
        for (int i = 0; i < numRetries; i++) {
            mSuspendControlService = ISuspendControlService.Stub.asInterface(
            mSuspendControlService = ISuspendControlServiceInternal.Stub.asInterface(
                                        ServiceManager.getService(name));
            if (mSuspendControlService != null) {
                return mSuspendControlService;
+2 −2
Original line number Diff line number Diff line
@@ -16,14 +16,14 @@

package com.android.internal.os;

import android.system.suspend.internal.WakeLockInfo;

import androidx.test.filters.SmallTest;

import junit.framework.TestCase;

import java.nio.charset.Charset;

import android.system.suspend.WakeLockInfo;

public class KernelWakelockReaderTest extends TestCase {
    /**
     * Helper class that builds the mock Kernel module file /d/wakeup_sources.
+2 −1
Original line number Diff line number Diff line
@@ -162,9 +162,10 @@ cc_defaults {
        "android.frameworks.schedulerservice@1.0",
        "android.frameworks.sensorservice@1.0",
        "android.frameworks.stats@1.0",
        "android.system.suspend.control-cpp",
        "android.system.suspend.control.internal-cpp",
        "android.system.suspend@1.0",
        "service.incremental",
        "suspend_control_aidl_interface-cpp",
    ],

    static_libs: [
+17 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <android/hardware/power/Mode.h>
#include <android/system/suspend/1.0/ISystemSuspend.h>
#include <android/system/suspend/ISuspendControlService.h>
#include <android/system/suspend/internal/ISuspendControlServiceInternal.h>
#include <nativehelper/JNIHelp.h>
#include "jni.h"

@@ -355,6 +356,8 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t

static sp<ISystemSuspend> gSuspendHal = nullptr;
static sp<ISuspendControlService> gSuspendControl = nullptr;
static sp<system::suspend::internal::ISuspendControlServiceInternal> gSuspendControlInternal =
        nullptr;
static sp<IWakeLock> gSuspendBlocker = nullptr;
static std::mutex gSuspendMutex;

@@ -379,10 +382,22 @@ sp<ISuspendControlService> getSuspendControl() {
    return gSuspendControl;
}

sp<system::suspend::internal::ISuspendControlServiceInternal> getSuspendControlInternal() {
    static std::once_flag suspendControlFlag;
    std::call_once(suspendControlFlag, []() {
        gSuspendControlInternal =
                waitForService<system::suspend::internal::ISuspendControlServiceInternal>(
                        String16("suspend_control_internal"));
        LOG_ALWAYS_FATAL_IF(gSuspendControlInternal == nullptr);
    });
    return gSuspendControlInternal;
}

void enableAutoSuspend() {
    static bool enabled = false;
    if (!enabled) {
        sp<ISuspendControlService> suspendControl = getSuspendControl();
        sp<system::suspend::internal::ISuspendControlServiceInternal> suspendControl =
                getSuspendControlInternal();
        suspendControl->enableAutosuspend(&enabled);
    }

@@ -515,7 +530,7 @@ static void nativeSetFeature(JNIEnv* /* env */, jclass /* clazz */, jint feature

static bool nativeForceSuspend(JNIEnv* /* env */, jclass /* clazz */) {
    bool retval = false;
    getSuspendControl()->forceSuspend(&retval);
    getSuspendControlInternal()->forceSuspend(&retval);
    return retval;
}