Merge "Update to use new android.system.suspend.control AIDL interface" am: e40aa2d118 am: b726bcfd65 am: a9b465c8d8

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1480304

Change-Id: I1aea5a7ddd2b6b30854683f5133906fa33aab78d
This commit is contained in:
Michael Sun
2020-11-06 19:20:04 +00:00
committed by Automerger Merge Worker
5 changed files with 29 additions and 12 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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.

View File

@@ -163,9 +163,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: [

View File

@@ -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;
}