Merge "Remove powerHint from IPowerManager.aidl"
This commit is contained in:
committed by
Android (Google) Code Review
commit
3758432ae2
@@ -32,7 +32,6 @@ interface IPowerManager
|
||||
@UnsupportedAppUsage
|
||||
void releaseWakeLock(IBinder lock, int flags);
|
||||
void updateWakeLockUids(IBinder lock, in int[] uids);
|
||||
oneway void powerHint(int hintId, int data);
|
||||
oneway void setPowerBoost(int boost, int durationMs);
|
||||
oneway void setPowerMode(int mode, boolean enabled);
|
||||
|
||||
|
||||
@@ -195,12 +195,6 @@ public abstract class PowerManagerInternal {
|
||||
|
||||
public abstract void uidIdle(int uid);
|
||||
|
||||
/**
|
||||
* The hintId sent through this method should be in-line with the
|
||||
* PowerHint defined in android/hardware/power/<version 1.0 & up>/IPower.h
|
||||
*/
|
||||
public abstract void powerHint(int hintId, int data);
|
||||
|
||||
/**
|
||||
* Boost: It is sent when user interacting with the device, for example,
|
||||
* touchscreen events are incoming.
|
||||
|
||||
@@ -44,8 +44,8 @@ import android.hardware.SystemSensorManager;
|
||||
import android.hardware.display.AmbientDisplayConfiguration;
|
||||
import android.hardware.display.DisplayManagerInternal;
|
||||
import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
|
||||
import android.hardware.power.Boost;
|
||||
import android.hardware.power.Mode;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.net.Uri;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryManagerInternal;
|
||||
@@ -203,9 +203,6 @@ public final class PowerManagerService extends SystemService
|
||||
// How long a partial wake lock must be held until we consider it a long wake lock.
|
||||
static final long MIN_LONG_WAKE_CHECK_INTERVAL = 60*1000;
|
||||
|
||||
// Power features defined in hardware/libhardware/include/hardware/power.h.
|
||||
private static final int POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 1;
|
||||
|
||||
// Default setting for double tap to wake.
|
||||
private static final int DEFAULT_DOUBLE_TAP_TO_WAKE = 0;
|
||||
|
||||
@@ -325,7 +322,7 @@ public final class PowerManagerService extends SystemService
|
||||
private long mLastUserActivityTime;
|
||||
private long mLastUserActivityTimeNoChangeLights;
|
||||
|
||||
// Timestamp of last interactive power hint.
|
||||
// Timestamp of last time power boost interaction was sent.
|
||||
private long mLastInteractivePowerHintTime;
|
||||
|
||||
// Timestamp of the last screen brightness boost.
|
||||
@@ -719,21 +716,11 @@ public final class PowerManagerService extends SystemService
|
||||
PowerManagerService.nativeReleaseSuspendBlocker(name);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeSetInteractive */
|
||||
public void nativeSetInteractive(boolean enable) {
|
||||
PowerManagerService.nativeSetInteractive(enable);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeSetAutoSuspend */
|
||||
public void nativeSetAutoSuspend(boolean enable) {
|
||||
PowerManagerService.nativeSetAutoSuspend(enable);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeSendPowerHint */
|
||||
public void nativeSendPowerHint(int hintId, int data) {
|
||||
PowerManagerService.nativeSendPowerHint(hintId, data);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeSetPowerBoost */
|
||||
public void nativeSetPowerBoost(int boost, int durationMs) {
|
||||
PowerManagerService.nativeSetPowerBoost(boost, durationMs);
|
||||
@@ -744,11 +731,6 @@ public final class PowerManagerService extends SystemService
|
||||
return PowerManagerService.nativeSetPowerMode(mode, enabled);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeSetFeature */
|
||||
public void nativeSetFeature(int featureId, int data) {
|
||||
PowerManagerService.nativeSetFeature(featureId, data);
|
||||
}
|
||||
|
||||
/** Wrapper for PowerManager.nativeForceSuspend */
|
||||
public boolean nativeForceSuspend() {
|
||||
return PowerManagerService.nativeForceSuspend();
|
||||
@@ -851,12 +833,9 @@ public final class PowerManagerService extends SystemService
|
||||
private native void nativeInit();
|
||||
private static native void nativeAcquireSuspendBlocker(String name);
|
||||
private static native void nativeReleaseSuspendBlocker(String name);
|
||||
private static native void nativeSetInteractive(boolean enable);
|
||||
private static native void nativeSetAutoSuspend(boolean enable);
|
||||
private static native void nativeSendPowerHint(int hintId, int data);
|
||||
private static native void nativeSetPowerBoost(int boost, int durationMs);
|
||||
private static native boolean nativeSetPowerMode(int mode, boolean enabled);
|
||||
private static native void nativeSetFeature(int featureId, int data);
|
||||
private static native boolean nativeForceSuspend();
|
||||
|
||||
public PowerManagerService(Context context) {
|
||||
@@ -1000,8 +979,8 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
mNativeWrapper.nativeInit(this);
|
||||
mNativeWrapper.nativeSetAutoSuspend(false);
|
||||
mNativeWrapper.nativeSetInteractive(true);
|
||||
mNativeWrapper.nativeSetFeature(POWER_FEATURE_DOUBLE_TAP_TO_WAKE, 0);
|
||||
mNativeWrapper.nativeSetPowerMode(Mode.INTERACTIVE, true);
|
||||
mNativeWrapper.nativeSetPowerMode(Mode.DOUBLE_TAP_TO_WAKE, false);
|
||||
mInjector.invalidateIsInteractiveCaches();
|
||||
}
|
||||
}
|
||||
@@ -1252,8 +1231,7 @@ public final class PowerManagerService extends SystemService
|
||||
UserHandle.USER_CURRENT) != 0;
|
||||
if (doubleTapWakeEnabled != mDoubleTapWakeEnabled) {
|
||||
mDoubleTapWakeEnabled = doubleTapWakeEnabled;
|
||||
mNativeWrapper.nativeSetFeature(
|
||||
POWER_FEATURE_DOUBLE_TAP_TO_WAKE, mDoubleTapWakeEnabled ? 1 : 0);
|
||||
mNativeWrapper.nativeSetPowerMode(Mode.DOUBLE_TAP_TO_WAKE, mDoubleTapWakeEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1612,7 +1590,7 @@ public final class PowerManagerService extends SystemService
|
||||
Trace.traceBegin(Trace.TRACE_TAG_POWER, "userActivity");
|
||||
try {
|
||||
if (eventTime > mLastInteractivePowerHintTime) {
|
||||
powerHintInternal(PowerHint.INTERACTION, 0);
|
||||
setPowerBoostInternal(Boost.INTERACTION, 0);
|
||||
mLastInteractivePowerHintTime = eventTime;
|
||||
}
|
||||
|
||||
@@ -3171,7 +3149,7 @@ public final class PowerManagerService extends SystemService
|
||||
mHalInteractiveModeEnabled = enable;
|
||||
Trace.traceBegin(Trace.TRACE_TAG_POWER, "setHalInteractive(" + enable + ")");
|
||||
try {
|
||||
mNativeWrapper.nativeSetInteractive(enable);
|
||||
mNativeWrapper.nativeSetPowerMode(Mode.INTERACTIVE, enable);
|
||||
} finally {
|
||||
Trace.traceEnd(Trace.TRACE_TAG_POWER);
|
||||
}
|
||||
@@ -3645,19 +3623,6 @@ public final class PowerManagerService extends SystemService
|
||||
mIsVrModeEnabled = enabled;
|
||||
}
|
||||
|
||||
private void powerHintInternal(int hintId, int data) {
|
||||
// Maybe filter the event.
|
||||
switch (hintId) {
|
||||
case PowerHint.LAUNCH: // 1: activate launch boost 0: deactivate.
|
||||
if (data == 1 && mBatterySaverController.isLaunchBoostDisabled()) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
mNativeWrapper.nativeSendPowerHint(hintId, data);
|
||||
}
|
||||
|
||||
private void setPowerBoostInternal(int boost, int durationMs) {
|
||||
// Maybe filter the event.
|
||||
mNativeWrapper.nativeSetPowerBoost(boost, durationMs);
|
||||
@@ -4404,7 +4369,7 @@ public final class PowerManagerService extends SystemService
|
||||
private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
|
||||
@Override
|
||||
public void onVrStateChanged(boolean enabled) {
|
||||
powerHintInternal(PowerHint.VR_MODE, enabled ? 1 : 0);
|
||||
setPowerModeInternal(Mode.VR, enabled);
|
||||
|
||||
synchronized (mLock) {
|
||||
if (mIsVrModeEnabled != enabled) {
|
||||
@@ -4714,16 +4679,6 @@ public final class PowerManagerService extends SystemService
|
||||
acquireWakeLock(lock, flags, tag, packageName, new WorkSource(uid), null);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
public void powerHint(int hintId, int data) {
|
||||
if (!mSystemReady) {
|
||||
// Service not ready yet, so who the heck cares about power hints, bah.
|
||||
return;
|
||||
}
|
||||
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
|
||||
powerHintInternal(hintId, data);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
public void setPowerBoost(int boost, int durationMs) {
|
||||
if (!mSystemReady) {
|
||||
@@ -5558,11 +5513,6 @@ public final class PowerManagerService extends SystemService
|
||||
uidIdleInternal(uid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void powerHint(int hintId, int data) {
|
||||
powerHintInternal(hintId, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPowerBoost(int boost, int durationMs) {
|
||||
setPowerBoostInternal(boost, durationMs);
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManagerInternal;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.hardware.power.Mode;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatterySaverPolicyConfig;
|
||||
import android.os.Handler;
|
||||
@@ -475,7 +475,7 @@ public class BatterySaverController implements BatterySaverPolicyListener {
|
||||
|
||||
final PowerManagerInternal pmi = LocalServices.getService(PowerManagerInternal.class);
|
||||
if (pmi != null) {
|
||||
pmi.powerHint(PowerHint.LOW_POWER, isEnabled() ? 1 : 0);
|
||||
pmi.setPowerMode(Mode.LOW_POWER, isEnabled());
|
||||
}
|
||||
|
||||
updateBatterySavingStats();
|
||||
|
||||
@@ -144,7 +144,7 @@ import android.graphics.PixelFormat;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Region;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.hardware.power.Boost;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
@@ -567,8 +567,8 @@ public class DisplayPolicy {
|
||||
@Override
|
||||
public void onFling(int duration) {
|
||||
if (mService.mPowerManagerInternal != null) {
|
||||
mService.mPowerManagerInternal.powerHint(
|
||||
PowerHint.INTERACTION, duration);
|
||||
mService.mPowerManagerInternal.setPowerBoost(
|
||||
Boost.INTERACTION, duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import android.content.pm.ActivityInfo.ScreenOrientation;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.hardware.power.Boost;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
@@ -1473,7 +1473,7 @@ public class DisplayRotation {
|
||||
@Override
|
||||
public void run() {
|
||||
// Send interaction power boost to improve redraw performance.
|
||||
mService.mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
|
||||
mService.mPowerManagerInternal.setPowerBoost(Boost.INTERACTION, 0);
|
||||
if (isRotationChoicePossible(mCurrentAppOrientation)) {
|
||||
final boolean isValid = isValidRotationChoice(mRotation);
|
||||
sendProposedRotationChangeToStatusBarInternal(mRotation, isValid);
|
||||
|
||||
@@ -112,7 +112,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.display.DisplayManagerInternal;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.hardware.power.Mode;
|
||||
import android.net.Uri;
|
||||
import android.os.Binder;
|
||||
import android.os.Debug;
|
||||
@@ -955,9 +955,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
|
||||
if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
|
||||
mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
|
||||
mWmService.mPowerManagerInternal.powerHint(
|
||||
PowerHint.SUSTAINED_PERFORMANCE,
|
||||
mSustainedPerformanceModeEnabled ? 1 : 0);
|
||||
mWmService.mPowerManagerInternal.setPowerMode(
|
||||
Mode.SUSTAINED_PERFORMANCE,
|
||||
mSustainedPerformanceModeEnabled);
|
||||
}
|
||||
|
||||
if (mUpdateRotation) {
|
||||
@@ -3528,7 +3528,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
}
|
||||
|
||||
if (sendPowerModeLaunch && mService.mPowerManagerInternal != null) {
|
||||
mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 1);
|
||||
mService.mPowerManagerInternal.setPowerMode(Mode.LAUNCH, true);
|
||||
mPowerModeLaunchStarted = true;
|
||||
}
|
||||
}
|
||||
@@ -3536,7 +3536,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
|
||||
void endPowerModeLaunchIfNeeded() {
|
||||
// Trigger launch power mode off if activity is launched
|
||||
if (mPowerModeLaunchStarted && mService.mPowerManagerInternal != null) {
|
||||
mService.mPowerManagerInternal.powerHint(PowerHint.LAUNCH, 0);
|
||||
mService.mPowerManagerInternal.setPowerMode(Mode.LAUNCH, false);
|
||||
mPowerModeLaunchStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.Nullable;
|
||||
import android.hardware.power.V1_0.PowerHint;
|
||||
import android.hardware.power.Boost;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManagerInternal;
|
||||
import android.util.ArrayMap;
|
||||
@@ -246,7 +246,7 @@ class SurfaceAnimationRunner {
|
||||
synchronized (mLock) {
|
||||
startPendingAnimationsLocked();
|
||||
}
|
||||
mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
|
||||
mPowerManagerInternal.setPowerBoost(Boost.INTERACTION, 0);
|
||||
}
|
||||
|
||||
private void scheduleApplyTransaction() {
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <powermanager/PowerHalController.h>
|
||||
#include <powermanager/PowerHalLoader.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@@ -49,12 +48,8 @@
|
||||
#include "com_android_server_power_PowerManagerService.h"
|
||||
|
||||
using android::String8;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::Void;
|
||||
using android::hardware::power::Boost;
|
||||
using android::hardware::power::Mode;
|
||||
using android::hardware::power::V1_0::Feature;
|
||||
using android::hardware::power::V1_0::PowerHint;
|
||||
using android::system::suspend::ISuspendControlService;
|
||||
using android::system::suspend::V1_0::ISystemSuspend;
|
||||
using android::system::suspend::V1_0::IWakeLock;
|
||||
@@ -74,18 +69,7 @@ static struct {
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static jobject gPowerManagerServiceObj;
|
||||
static sp<IPowerV1_0> gPowerHalHidlV1_0_ = nullptr;
|
||||
static sp<IPowerV1_1> gPowerHalHidlV1_1_ = nullptr;
|
||||
static sp<IPowerAidl> gPowerHalAidl_ = nullptr;
|
||||
static std::mutex gPowerHalMutex;
|
||||
|
||||
enum class HalVersion {
|
||||
NONE,
|
||||
HIDL_1_0,
|
||||
HIDL_1_1,
|
||||
AIDL,
|
||||
};
|
||||
|
||||
static power::PowerHalController gPowerHalController;
|
||||
static nsecs_t gLastEventTime[USER_ACTIVITY_EVENT_LAST + 1];
|
||||
|
||||
// Throttling interval for user activity calls.
|
||||
@@ -103,208 +87,19 @@ static bool checkAndClearExceptionFromCallback(JNIEnv* env, const char* methodNa
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check validity of current handle to the power HAL service, and connect to it if necessary.
|
||||
// The caller must be holding gPowerHalMutex.
|
||||
static HalVersion connectPowerHalLocked() {
|
||||
static bool gPowerHalHidlExists = true;
|
||||
static bool gPowerHalAidlExists = true;
|
||||
if (!gPowerHalHidlExists && !gPowerHalAidlExists) {
|
||||
return HalVersion::NONE;
|
||||
}
|
||||
if (gPowerHalAidlExists) {
|
||||
if (!gPowerHalAidl_) {
|
||||
gPowerHalAidl_ = waitForVintfService<IPowerAidl>();
|
||||
}
|
||||
if (gPowerHalAidl_) {
|
||||
ALOGV("Successfully connected to Power HAL AIDL service.");
|
||||
return HalVersion::AIDL;
|
||||
} else {
|
||||
gPowerHalAidlExists = false;
|
||||
}
|
||||
}
|
||||
if (gPowerHalHidlExists && gPowerHalHidlV1_0_ == nullptr) {
|
||||
gPowerHalHidlV1_0_ = IPowerV1_0::getService();
|
||||
if (gPowerHalHidlV1_0_) {
|
||||
ALOGV("Successfully connected to Power HAL HIDL 1.0 service.");
|
||||
// Try cast to powerHAL HIDL V1_1
|
||||
gPowerHalHidlV1_1_ = IPowerV1_1::castFrom(gPowerHalHidlV1_0_);
|
||||
if (gPowerHalHidlV1_1_) {
|
||||
ALOGV("Successfully connected to Power HAL HIDL 1.1 service.");
|
||||
}
|
||||
} else {
|
||||
ALOGV("Couldn't load power HAL HIDL service");
|
||||
gPowerHalHidlExists = false;
|
||||
return HalVersion::NONE;
|
||||
}
|
||||
}
|
||||
if (gPowerHalHidlV1_1_) {
|
||||
return HalVersion::HIDL_1_1;
|
||||
} else if (gPowerHalHidlV1_0_) {
|
||||
return HalVersion::HIDL_1_0;
|
||||
}
|
||||
return HalVersion::NONE;
|
||||
}
|
||||
|
||||
// Check if a call to a power HAL function failed; if so, log the failure and invalidate the
|
||||
// current handle to the power HAL service.
|
||||
bool processPowerHalReturn(bool isOk, const char* functionName) {
|
||||
if (!isOk) {
|
||||
ALOGE("%s() failed: power HAL service not available.", functionName);
|
||||
gPowerHalMutex.lock();
|
||||
gPowerHalHidlV1_0_ = nullptr;
|
||||
gPowerHalHidlV1_1_ = nullptr;
|
||||
gPowerHalAidl_ = nullptr;
|
||||
gPowerHalMutex.unlock();
|
||||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
enum class HalSupport {
|
||||
UNKNOWN = 0,
|
||||
ON,
|
||||
OFF,
|
||||
};
|
||||
|
||||
static void setPowerBoostWithHandle(sp<IPowerAidl> handle, Boost boost, int32_t durationMs) {
|
||||
// Android framework only sends boost upto DISPLAY_UPDATE_IMMINENT.
|
||||
// Need to increase the array size if more boost supported.
|
||||
static std::array<std::atomic<HalSupport>,
|
||||
static_cast<int32_t>(Boost::DISPLAY_UPDATE_IMMINENT) + 1>
|
||||
boostSupportedArray = {HalSupport::UNKNOWN};
|
||||
|
||||
// Quick return if boost is not supported by HAL
|
||||
if (boost > Boost::DISPLAY_UPDATE_IMMINENT ||
|
||||
boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::OFF) {
|
||||
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it", toString(boost).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (boostSupportedArray[static_cast<int32_t>(boost)] == HalSupport::UNKNOWN) {
|
||||
bool isSupported = false;
|
||||
handle->isBoostSupported(boost, &isSupported);
|
||||
boostSupportedArray[static_cast<int32_t>(boost)] =
|
||||
isSupported ? HalSupport::ON : HalSupport::OFF;
|
||||
if (!isSupported) {
|
||||
ALOGV("Skipped setPowerBoost %s because HAL doesn't support it",
|
||||
toString(boost).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
auto ret = handle->setBoost(boost, durationMs);
|
||||
processPowerHalReturn(ret.isOk(), "setPowerBoost");
|
||||
}
|
||||
|
||||
static void setPowerBoost(Boost boost, int32_t durationMs) {
|
||||
std::unique_lock<std::mutex> lock(gPowerHalMutex);
|
||||
if (connectPowerHalLocked() != HalVersion::AIDL) {
|
||||
ALOGV("Power HAL AIDL not available");
|
||||
return;
|
||||
}
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerBoostWithHandle(handle, boost, durationMs);
|
||||
}
|
||||
|
||||
static bool setPowerModeWithHandle(sp<IPowerAidl> handle, Mode mode, bool enabled) {
|
||||
// Android framework only sends mode upto DISPLAY_INACTIVE.
|
||||
// Need to increase the array if more mode supported.
|
||||
static std::array<std::atomic<HalSupport>, static_cast<int32_t>(Mode::DISPLAY_INACTIVE) + 1>
|
||||
modeSupportedArray = {HalSupport::UNKNOWN};
|
||||
|
||||
// Quick return if mode is not supported by HAL
|
||||
if (mode > Mode::DISPLAY_INACTIVE ||
|
||||
modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::OFF) {
|
||||
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (modeSupportedArray[static_cast<int32_t>(mode)] == HalSupport::UNKNOWN) {
|
||||
bool isSupported = false;
|
||||
handle->isModeSupported(mode, &isSupported);
|
||||
modeSupportedArray[static_cast<int32_t>(mode)] =
|
||||
isSupported ? HalSupport::ON : HalSupport::OFF;
|
||||
if (!isSupported) {
|
||||
ALOGV("Skipped setPowerMode %s because HAL doesn't support it", toString(mode).c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto ret = handle->setMode(mode, enabled);
|
||||
processPowerHalReturn(ret.isOk(), "setPowerMode");
|
||||
return ret.isOk();
|
||||
gPowerHalController.setBoost(boost, durationMs);
|
||||
SurfaceComposerClient::notifyPowerBoost(static_cast<int32_t>(boost));
|
||||
}
|
||||
|
||||
static bool setPowerMode(Mode mode, bool enabled) {
|
||||
std::unique_lock<std::mutex> lock(gPowerHalMutex);
|
||||
if (connectPowerHalLocked() != HalVersion::AIDL) {
|
||||
ALOGV("Power HAL AIDL not available");
|
||||
return false;
|
||||
}
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
return setPowerModeWithHandle(handle, mode, enabled);
|
||||
}
|
||||
|
||||
static void sendPowerHint(PowerHint hintId, uint32_t data) {
|
||||
std::unique_lock<std::mutex> lock(gPowerHalMutex);
|
||||
switch (connectPowerHalLocked()) {
|
||||
case HalVersion::NONE:
|
||||
return;
|
||||
case HalVersion::HIDL_1_0: {
|
||||
sp<IPowerV1_0> handle = gPowerHalHidlV1_0_;
|
||||
lock.unlock();
|
||||
auto ret = handle->powerHint(hintId, data);
|
||||
processPowerHalReturn(ret.isOk(), "powerHint");
|
||||
break;
|
||||
}
|
||||
case HalVersion::HIDL_1_1: {
|
||||
sp<IPowerV1_1> handle = gPowerHalHidlV1_1_;
|
||||
lock.unlock();
|
||||
auto ret = handle->powerHintAsync(hintId, data);
|
||||
processPowerHalReturn(ret.isOk(), "powerHintAsync");
|
||||
break;
|
||||
}
|
||||
case HalVersion::AIDL: {
|
||||
if (hintId == PowerHint::INTERACTION) {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerBoostWithHandle(handle, Boost::INTERACTION, data);
|
||||
break;
|
||||
} else if (hintId == PowerHint::LAUNCH) {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::LAUNCH, static_cast<bool>(data));
|
||||
break;
|
||||
} else if (hintId == PowerHint::LOW_POWER) {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::LOW_POWER, static_cast<bool>(data));
|
||||
break;
|
||||
} else if (hintId == PowerHint::SUSTAINED_PERFORMANCE) {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::SUSTAINED_PERFORMANCE,
|
||||
static_cast<bool>(data));
|
||||
break;
|
||||
} else if (hintId == PowerHint::VR_MODE) {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::VR, static_cast<bool>(data));
|
||||
break;
|
||||
} else {
|
||||
ALOGE("Unsupported power hint: %s.", toString(hintId).c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
default: {
|
||||
ALOGE("Unknown power HAL state");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (hintId == PowerHint::INTERACTION) {
|
||||
SurfaceComposerClient::notifyPowerBoost(static_cast<int32_t>(Boost::INTERACTION));
|
||||
android::base::Timer t;
|
||||
auto result = gPowerHalController.setMode(mode, enabled);
|
||||
if (mode == Mode::INTERACTIVE && t.duration() > 20ms) {
|
||||
ALOGD("Excessive delay in setting interactive mode to %s while turning screen %s",
|
||||
enabled ? "true" : "false", enabled ? "on" : "off");
|
||||
}
|
||||
return result == power::HalResult::SUCCESSFUL;
|
||||
}
|
||||
|
||||
void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) {
|
||||
@@ -324,7 +119,7 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t
|
||||
gLastEventTime[eventType] = eventTime;
|
||||
|
||||
// Tell the power HAL when user activity occurs.
|
||||
sendPowerHint(PowerHint::INTERACTION, 0);
|
||||
setPowerBoost(Boost::INTERACTION, 0);
|
||||
}
|
||||
|
||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||
@@ -391,10 +186,7 @@ void disableAutoSuspend() {
|
||||
|
||||
static void nativeInit(JNIEnv* env, jobject obj) {
|
||||
gPowerManagerServiceObj = env->NewGlobalRef(obj);
|
||||
|
||||
gPowerHalMutex.lock();
|
||||
connectPowerHalLocked();
|
||||
gPowerHalMutex.unlock();
|
||||
gPowerHalController.init();
|
||||
}
|
||||
|
||||
static void nativeAcquireSuspendBlocker(JNIEnv *env, jclass /* clazz */, jstring nameStr) {
|
||||
@@ -407,38 +199,6 @@ static void nativeReleaseSuspendBlocker(JNIEnv *env, jclass /* clazz */, jstring
|
||||
release_wake_lock(name.c_str());
|
||||
}
|
||||
|
||||
static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean enable) {
|
||||
std::unique_lock<std::mutex> lock(gPowerHalMutex);
|
||||
switch (connectPowerHalLocked()) {
|
||||
case HalVersion::NONE:
|
||||
return;
|
||||
case HalVersion::HIDL_1_0:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case HalVersion::HIDL_1_1: {
|
||||
android::base::Timer t;
|
||||
sp<IPowerV1_0> handle = gPowerHalHidlV1_0_;
|
||||
lock.unlock();
|
||||
auto ret = handle->setInteractive(enable);
|
||||
processPowerHalReturn(ret.isOk(), "setInteractive");
|
||||
if (t.duration() > 20ms) {
|
||||
ALOGD("Excessive delay in setInteractive(%s) while turning screen %s",
|
||||
enable ? "true" : "false", enable ? "on" : "off");
|
||||
}
|
||||
return;
|
||||
}
|
||||
case HalVersion::AIDL: {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::INTERACTIVE, enable);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
ALOGE("Unknown power HAL state");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void nativeSetAutoSuspend(JNIEnv* /* env */, jclass /* clazz */, jboolean enable) {
|
||||
if (enable) {
|
||||
android::base::Timer t;
|
||||
@@ -455,10 +215,6 @@ static void nativeSetAutoSuspend(JNIEnv* /* env */, jclass /* clazz */, jboolean
|
||||
}
|
||||
}
|
||||
|
||||
static void nativeSendPowerHint(JNIEnv* /* env */, jclass /* clazz */, jint hintId, jint data) {
|
||||
sendPowerHint(static_cast<PowerHint>(hintId), data);
|
||||
}
|
||||
|
||||
static void nativeSetPowerBoost(JNIEnv* /* env */, jclass /* clazz */, jint boost,
|
||||
jint durationMs) {
|
||||
setPowerBoost(static_cast<Boost>(boost), durationMs);
|
||||
@@ -469,33 +225,6 @@ static jboolean nativeSetPowerMode(JNIEnv* /* env */, jclass /* clazz */, jint m
|
||||
return setPowerMode(static_cast<Mode>(mode), enabled);
|
||||
}
|
||||
|
||||
static void nativeSetFeature(JNIEnv* /* env */, jclass /* clazz */, jint featureId, jint data) {
|
||||
std::unique_lock<std::mutex> lock(gPowerHalMutex);
|
||||
switch (connectPowerHalLocked()) {
|
||||
case HalVersion::NONE:
|
||||
return;
|
||||
case HalVersion::HIDL_1_0:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case HalVersion::HIDL_1_1: {
|
||||
sp<IPowerV1_0> handle = gPowerHalHidlV1_0_;
|
||||
lock.unlock();
|
||||
auto ret = handle->setFeature(static_cast<Feature>(featureId), static_cast<bool>(data));
|
||||
processPowerHalReturn(ret.isOk(), "setFeature");
|
||||
return;
|
||||
}
|
||||
case HalVersion::AIDL: {
|
||||
sp<IPowerAidl> handle = gPowerHalAidl_;
|
||||
lock.unlock();
|
||||
setPowerModeWithHandle(handle, Mode::DOUBLE_TAP_TO_WAKE, static_cast<bool>(data));
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
ALOGE("Unknown power HAL state");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool nativeForceSuspend(JNIEnv* /* env */, jclass /* clazz */) {
|
||||
bool retval = false;
|
||||
getSuspendControl()->forceSuspend(&retval);
|
||||
@@ -512,12 +241,9 @@ static const JNINativeMethod gPowerManagerServiceMethods[] = {
|
||||
{"nativeForceSuspend", "()Z", (void*)nativeForceSuspend},
|
||||
{"nativeReleaseSuspendBlocker", "(Ljava/lang/String;)V",
|
||||
(void*)nativeReleaseSuspendBlocker},
|
||||
{"nativeSetInteractive", "(Z)V", (void*)nativeSetInteractive},
|
||||
{"nativeSetAutoSuspend", "(Z)V", (void*)nativeSetAutoSuspend},
|
||||
{"nativeSendPowerHint", "(II)V", (void*)nativeSendPowerHint},
|
||||
{"nativeSetPowerBoost", "(II)V", (void*)nativeSetPowerBoost},
|
||||
{"nativeSetPowerMode", "(IZ)Z", (void*)nativeSetPowerMode},
|
||||
{"nativeSetFeature", "(II)V", (void*)nativeSetFeature},
|
||||
};
|
||||
|
||||
#define FIND_CLASS(var, className) \
|
||||
|
||||
@@ -369,9 +369,11 @@ public class PowerManagerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateService_initializesNativeService() {
|
||||
public void testCreateService_initializesNativeServiceAndSetsPowerModes() {
|
||||
PowerManagerService service = createService();
|
||||
verify(mNativeWrapperMock).nativeInit(same(service));
|
||||
verify(mNativeWrapperMock).nativeSetPowerMode(eq(Mode.INTERACTIVE), eq(true));
|
||||
verify(mNativeWrapperMock).nativeSetPowerMode(eq(Mode.DOUBLE_TAP_TO_WAKE), eq(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,7 +26,6 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
@@ -34,6 +33,7 @@ import android.animation.AnimationHandler.AnimationFrameCallbackProvider;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.power.Boost;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManagerInternal;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
@@ -202,7 +202,7 @@ public class SurfaceAnimationRunnerTest {
|
||||
mMockTransaction, this::finishedCallback);
|
||||
waitUntilNextFrame();
|
||||
|
||||
verify(mMockPowerManager).powerHint(anyInt(), eq(0));
|
||||
verify(mMockPowerManager).setPowerBoost(eq(Boost.INTERACTION), eq(0));
|
||||
}
|
||||
|
||||
private void waitUntilNextFrame() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user