Merge "Update Wakelocks to be per-DisplayGroup" into sc-dev
This commit is contained in:
@@ -27,9 +27,9 @@ import android.os.WorkSource;
|
||||
interface IPowerManager
|
||||
{
|
||||
void acquireWakeLock(IBinder lock, int flags, String tag, String packageName, in WorkSource ws,
|
||||
String historyTag);
|
||||
String historyTag, int displayId);
|
||||
void acquireWakeLockWithUid(IBinder lock, int flags, String tag, String packageName,
|
||||
int uidtoblame);
|
||||
int uidtoblame, int displayId);
|
||||
@UnsupportedAppUsage
|
||||
void releaseWakeLock(IBinder lock, int flags);
|
||||
void updateWakeLockUids(IBinder lock, in int[] uids);
|
||||
|
||||
@@ -36,6 +36,7 @@ import android.sysprop.InitProperties;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
import android.view.Display;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
|
||||
@@ -1143,8 +1144,7 @@ public final class PowerManager {
|
||||
* wake lock, and {@link WakeLock#release release()} when you are done.
|
||||
* </p><p>
|
||||
* {@samplecode
|
||||
* PowerManager pm = (PowerManager)mContext.getSystemService(
|
||||
* Context.POWER_SERVICE);
|
||||
* PowerManager pm = mContext.getSystemService(PowerManager.class);
|
||||
* PowerManager.WakeLock wl = pm.newWakeLock(
|
||||
* PowerManager.SCREEN_DIM_WAKE_LOCK
|
||||
* | PowerManager.ON_AFTER_RELEASE,
|
||||
@@ -1162,6 +1162,8 @@ public final class PowerManager {
|
||||
* {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead.
|
||||
* This window flag will be correctly managed by the platform
|
||||
* as the user moves between applications and doesn't require a special permission.
|
||||
* Additionally using the flag will keep only the appropriate screen on in a
|
||||
* multi-display scenario while using a wake lock will keep every screen powered on.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
@@ -1179,7 +1181,7 @@ public final class PowerManager {
|
||||
* can be transformed by java optimizer and obfuscator tools.
|
||||
* <li>avoid wrapping the tag or a prefix to avoid collision with wake lock
|
||||
* tags from the platform (e.g. *alarm*).
|
||||
* <li>never include personnally identifiable information for privacy
|
||||
* <li>never include personally identifiable information for privacy
|
||||
* reasons.
|
||||
* </ul>
|
||||
* </p>
|
||||
@@ -1200,7 +1202,27 @@ public final class PowerManager {
|
||||
*/
|
||||
public WakeLock newWakeLock(int levelAndFlags, String tag) {
|
||||
validateWakeLockParameters(levelAndFlags, tag);
|
||||
return new WakeLock(levelAndFlags, tag, mContext.getOpPackageName());
|
||||
return new WakeLock(levelAndFlags, tag, mContext.getOpPackageName(),
|
||||
Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new wake lock with the specified level and flags.
|
||||
* <p>
|
||||
* The wakelock will only apply to the {@link com.android.server.display.DisplayGroup} of the
|
||||
* provided {@code displayId}. If {@code displayId} is {@link Display#INVALID_DISPLAY} then it
|
||||
* will apply to all {@link com.android.server.display.DisplayGroup DisplayGroups}.
|
||||
*
|
||||
* @param levelAndFlags Combination of wake lock level and flag values defining
|
||||
* the requested behavior of the WakeLock.
|
||||
* @param tag Your class name (or other tag) for debugging purposes.
|
||||
* @param displayId The display id to which this wake lock is tied.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public WakeLock newWakeLock(int levelAndFlags, String tag, int displayId) {
|
||||
validateWakeLockParameters(levelAndFlags, tag);
|
||||
return new WakeLock(levelAndFlags, tag, mContext.getOpPackageName(), displayId);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@@ -2603,19 +2625,17 @@ public final class PowerManager {
|
||||
private WorkSource mWorkSource;
|
||||
private String mHistoryTag;
|
||||
private final String mTraceName;
|
||||
private final int mDisplayId;
|
||||
|
||||
private final Runnable mReleaser = new Runnable() {
|
||||
public void run() {
|
||||
release(RELEASE_FLAG_TIMEOUT);
|
||||
}
|
||||
};
|
||||
private final Runnable mReleaser = () -> release(RELEASE_FLAG_TIMEOUT);
|
||||
|
||||
WakeLock(int flags, String tag, String packageName) {
|
||||
WakeLock(int flags, String tag, String packageName, int displayId) {
|
||||
mFlags = flags;
|
||||
mTag = tag;
|
||||
mPackageName = packageName;
|
||||
mToken = new Binder();
|
||||
mTraceName = "WakeLock (" + mTag + ")";
|
||||
mDisplayId = displayId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2696,7 +2716,7 @@ public final class PowerManager {
|
||||
Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, mTraceName, 0);
|
||||
try {
|
||||
mService.acquireWakeLock(mToken, mFlags, mTag, mPackageName, mWorkSource,
|
||||
mHistoryTag);
|
||||
mHistoryTag, mDisplayId);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
|
||||
@@ -125,6 +125,10 @@ public class DisplayGroupPowerStateMapper {
|
||||
return mDisplayGroupIds;
|
||||
}
|
||||
|
||||
int getDisplayGroupCountLocked() {
|
||||
return mDisplayGroupIds.length;
|
||||
}
|
||||
|
||||
int getWakefulnessLocked(int groupId) {
|
||||
return mDisplayGroupInfos.get(groupId).wakefulness;
|
||||
}
|
||||
@@ -272,6 +276,14 @@ public class DisplayGroupPowerStateMapper {
|
||||
mDisplayGroupInfos.get(groupId).userActivitySummary = summary;
|
||||
}
|
||||
|
||||
int getWakeLockSummaryLocked(int groupId) {
|
||||
return mDisplayGroupInfos.get(groupId).wakeLockSummary;
|
||||
}
|
||||
|
||||
void setWakeLockSummaryLocked(int groupId, int summary) {
|
||||
mDisplayGroupInfos.get(groupId).wakeLockSummary = summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface through which an interested party may be informed of {@link DisplayGroup} events.
|
||||
*/
|
||||
@@ -292,6 +304,7 @@ public class DisplayGroupPowerStateMapper {
|
||||
public long lastUserActivityTime;
|
||||
public long lastUserActivityTimeNoChangeLights;
|
||||
public int userActivitySummary;
|
||||
public int wakeLockSummary;
|
||||
|
||||
/** {@code true} if this DisplayGroup supports dreaming; otherwise {@code false}. */
|
||||
public boolean supportsSandman;
|
||||
|
||||
@@ -1348,9 +1348,20 @@ public final class PowerManagerService extends SystemService
|
||||
updatePowerStateLocked();
|
||||
}
|
||||
|
||||
private void acquireWakeLockInternal(IBinder lock, int flags, String tag, String packageName,
|
||||
WorkSource ws, String historyTag, int uid, int pid) {
|
||||
private void acquireWakeLockInternal(IBinder lock, int displayId, int flags, String tag,
|
||||
String packageName, WorkSource ws, String historyTag, int uid, int pid) {
|
||||
synchronized (mLock) {
|
||||
if (displayId != Display.INVALID_DISPLAY) {
|
||||
final DisplayInfo displayInfo =
|
||||
mSystemReady ? mDisplayManagerInternal.getDisplayInfo(displayId) : null;
|
||||
if (displayInfo == null) {
|
||||
Slog.wtf(TAG, "Tried to acquire wake lock for invalid display: " + displayId);
|
||||
return;
|
||||
} else if (!displayInfo.hasAccess(uid)) {
|
||||
throw new SecurityException("Caller does not have access to display");
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUG_SPEW) {
|
||||
Slog.d(TAG, "acquireWakeLockInternal: lock=" + Objects.hashCode(lock)
|
||||
+ ", flags=0x" + Integer.toHexString(flags)
|
||||
@@ -1377,8 +1388,8 @@ public final class PowerManagerService extends SystemService
|
||||
mUidState.put(uid, state);
|
||||
}
|
||||
state.mNumWakeLocks++;
|
||||
wakeLock = new WakeLock(lock, flags, tag, packageName, ws, historyTag, uid, pid,
|
||||
state);
|
||||
wakeLock = new WakeLock(lock, displayId, flags, tag, packageName, ws, historyTag,
|
||||
uid, pid, state);
|
||||
try {
|
||||
lock.linkToDeath(wakeLock, 0);
|
||||
} catch (RemoteException ex) {
|
||||
@@ -2047,6 +2058,11 @@ public final class PowerManagerService extends SystemService
|
||||
return mWakefulnessRaw;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getWakefulnessLocked(int groupId) {
|
||||
return mDisplayGroupPowerStateMapper.getWakefulnessLocked(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the time the device would have spent awake before user activity timeout,
|
||||
* had the system not been told the user was inactive.
|
||||
@@ -2293,7 +2309,9 @@ public final class PowerManagerService extends SystemService
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateWakeLockSummaryLocked(int dirty) {
|
||||
if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_WAKEFULNESS)) != 0) {
|
||||
if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_WAKEFULNESS | DIRTY_DISPLAY_GROUP_WAKEFULNESS))
|
||||
!= 0) {
|
||||
|
||||
mWakeLockSummary = 0;
|
||||
|
||||
final int numProfiles = mProfilePowerState.size();
|
||||
@@ -2301,11 +2319,28 @@ public final class PowerManagerService extends SystemService
|
||||
mProfilePowerState.valueAt(i).mWakeLockSummary = 0;
|
||||
}
|
||||
|
||||
for (int groupId : mDisplayGroupPowerStateMapper.getDisplayGroupIdsLocked()) {
|
||||
mDisplayGroupPowerStateMapper.setWakeLockSummaryLocked(groupId, 0);
|
||||
}
|
||||
|
||||
int invalidGroupWakeLockSummary = 0;
|
||||
final int numWakeLocks = mWakeLocks.size();
|
||||
for (int i = 0; i < numWakeLocks; i++) {
|
||||
final WakeLock wakeLock = mWakeLocks.get(i);
|
||||
final int wakeLockFlags = getWakeLockSummaryFlags(wakeLock);
|
||||
mWakeLockSummary |= wakeLockFlags;
|
||||
|
||||
final int groupId = wakeLock.getDisplayGroupId();
|
||||
if (groupId != Display.INVALID_DISPLAY_GROUP) {
|
||||
int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(
|
||||
groupId);
|
||||
wakeLockSummary |= wakeLockFlags;
|
||||
mDisplayGroupPowerStateMapper.setWakeLockSummaryLocked(groupId,
|
||||
wakeLockSummary);
|
||||
} else {
|
||||
invalidGroupWakeLockSummary |= wakeLockFlags;
|
||||
}
|
||||
|
||||
for (int j = 0; j < numProfiles; j++) {
|
||||
final ProfilePowerState profile = mProfilePowerState.valueAt(j);
|
||||
if (wakeLockAffectsUser(wakeLock, profile.mUserId)) {
|
||||
@@ -2314,10 +2349,21 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
}
|
||||
|
||||
mWakeLockSummary = adjustWakeLockSummaryLocked(mWakeLockSummary);
|
||||
for (int groupId : mDisplayGroupPowerStateMapper.getDisplayGroupIdsLocked()) {
|
||||
final int wakeLockSummary = adjustWakeLockSummaryLocked(
|
||||
mDisplayGroupPowerStateMapper.getWakefulnessLocked(groupId),
|
||||
invalidGroupWakeLockSummary
|
||||
| mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId));
|
||||
mDisplayGroupPowerStateMapper.setWakeLockSummaryLocked(groupId, wakeLockSummary);
|
||||
}
|
||||
|
||||
mWakeLockSummary = adjustWakeLockSummaryLocked(getWakefulnessLocked(),
|
||||
mWakeLockSummary);
|
||||
|
||||
for (int i = 0; i < numProfiles; i++) {
|
||||
final ProfilePowerState profile = mProfilePowerState.valueAt(i);
|
||||
profile.mWakeLockSummary = adjustWakeLockSummaryLocked(profile.mWakeLockSummary);
|
||||
profile.mWakeLockSummary = adjustWakeLockSummaryLocked(getWakefulnessLocked(),
|
||||
profile.mWakeLockSummary);
|
||||
}
|
||||
|
||||
if (DEBUG_SPEW) {
|
||||
@@ -2328,25 +2374,25 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
}
|
||||
|
||||
private int adjustWakeLockSummaryLocked(int wakeLockSummary) {
|
||||
private static int adjustWakeLockSummaryLocked(int wakefulness, int wakeLockSummary) {
|
||||
// Cancel wake locks that make no sense based on the current state.
|
||||
if (getWakefulnessLocked() != WAKEFULNESS_DOZING) {
|
||||
if (wakefulness != WAKEFULNESS_DOZING) {
|
||||
wakeLockSummary &= ~(WAKE_LOCK_DOZE | WAKE_LOCK_DRAW);
|
||||
}
|
||||
if (getWakefulnessLocked() == WAKEFULNESS_ASLEEP
|
||||
if (wakefulness == WAKEFULNESS_ASLEEP
|
||||
|| (wakeLockSummary & WAKE_LOCK_DOZE) != 0) {
|
||||
wakeLockSummary &= ~(WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM
|
||||
| WAKE_LOCK_BUTTON_BRIGHT);
|
||||
if (getWakefulnessLocked() == WAKEFULNESS_ASLEEP) {
|
||||
if (wakefulness == WAKEFULNESS_ASLEEP) {
|
||||
wakeLockSummary &= ~WAKE_LOCK_PROXIMITY_SCREEN_OFF;
|
||||
}
|
||||
}
|
||||
|
||||
// Infer implied wake locks where necessary based on the current state.
|
||||
if ((wakeLockSummary & (WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM)) != 0) {
|
||||
if (getWakefulnessLocked() == WAKEFULNESS_AWAKE) {
|
||||
if (wakefulness == WAKEFULNESS_AWAKE) {
|
||||
wakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_STAY_AWAKE;
|
||||
} else if (getWakefulnessLocked() == WAKEFULNESS_DREAMING) {
|
||||
} else if (wakefulness == WAKEFULNESS_DREAMING) {
|
||||
wakeLockSummary |= WAKE_LOCK_CPU;
|
||||
}
|
||||
}
|
||||
@@ -2531,7 +2577,8 @@ public final class PowerManagerService extends SystemService
|
||||
}
|
||||
|
||||
if ((groupUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0
|
||||
&& (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) == 0) {
|
||||
&& (mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId)
|
||||
& WAKE_LOCK_STAY_AWAKE) == 0) {
|
||||
groupNextTimeout = mAttentionDetector.updateUserActivity(groupNextTimeout,
|
||||
screenDimDuration);
|
||||
}
|
||||
@@ -2831,7 +2878,8 @@ public final class PowerManagerService extends SystemService
|
||||
private boolean isBeingKeptAwakeLocked(int groupId) {
|
||||
return mStayOn
|
||||
|| mProximityPositive
|
||||
|| (mWakeLockSummary & WAKE_LOCK_STAY_AWAKE) != 0
|
||||
|| (mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId)
|
||||
& WAKE_LOCK_STAY_AWAKE) != 0
|
||||
|| (mDisplayGroupPowerStateMapper.getUserActivitySummaryLocked(groupId) & (
|
||||
USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM)) != 0
|
||||
|| mScreenBrightnessBoostInProgress;
|
||||
@@ -3101,8 +3149,8 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
if (displayPowerRequest.policy == DisplayPowerRequest.POLICY_DOZE) {
|
||||
displayPowerRequest.dozeScreenState = mDozeScreenStateOverrideFromDreamManager;
|
||||
if ((mWakeLockSummary & WAKE_LOCK_DRAW) != 0
|
||||
&& !mDrawWakeLockOverrideFromSidekick) {
|
||||
if ((mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId)
|
||||
& WAKE_LOCK_DRAW) != 0 && !mDrawWakeLockOverrideFromSidekick) {
|
||||
if (displayPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND) {
|
||||
displayPowerRequest.dozeScreenState = Display.STATE_DOZE;
|
||||
}
|
||||
@@ -3128,7 +3176,8 @@ public final class PowerManagerService extends SystemService
|
||||
+ ", mWakefulness="
|
||||
+ PowerManagerInternal.wakefulnessToString(
|
||||
mDisplayGroupPowerStateMapper.getWakefulnessLocked(groupId))
|
||||
+ ", mWakeLockSummary=0x" + Integer.toHexString(mWakeLockSummary)
|
||||
+ ", mWakeLockSummary=0x" + Integer.toHexString(
|
||||
mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId))
|
||||
+ ", mUserActivitySummary=0x" + Integer.toHexString(
|
||||
mDisplayGroupPowerStateMapper.getUserActivitySummaryLocked(groupId))
|
||||
+ ", mBootCompleted=" + mBootCompleted
|
||||
@@ -3193,10 +3242,11 @@ public final class PowerManagerService extends SystemService
|
||||
@VisibleForTesting
|
||||
int getDesiredScreenPolicyLocked(int groupId) {
|
||||
final int wakefulness = mDisplayGroupPowerStateMapper.getWakefulnessLocked(groupId);
|
||||
final int wakeLockSummary = mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(groupId);
|
||||
if (wakefulness == WAKEFULNESS_ASLEEP || sQuiescent) {
|
||||
return DisplayPowerRequest.POLICY_OFF;
|
||||
} else if (wakefulness == WAKEFULNESS_DOZING) {
|
||||
if ((mWakeLockSummary & WAKE_LOCK_DOZE) != 0) {
|
||||
if ((wakeLockSummary & WAKE_LOCK_DOZE) != 0) {
|
||||
return DisplayPowerRequest.POLICY_DOZE;
|
||||
}
|
||||
if (mDozeAfterScreenOff) {
|
||||
@@ -3213,7 +3263,7 @@ public final class PowerManagerService extends SystemService
|
||||
return DisplayPowerRequest.POLICY_VR;
|
||||
}
|
||||
|
||||
if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
|
||||
if ((wakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0
|
||||
|| !mBootCompleted
|
||||
|| (mDisplayGroupPowerStateMapper.getUserActivitySummaryLocked(groupId)
|
||||
& USER_ACTIVITY_SCREEN_BRIGHT) != 0
|
||||
@@ -3292,7 +3342,9 @@ public final class PowerManagerService extends SystemService
|
||||
};
|
||||
|
||||
private boolean shouldUseProximitySensorLocked() {
|
||||
return !mIsVrModeEnabled && (mWakeLockSummary & WAKE_LOCK_PROXIMITY_SCREEN_OFF) != 0;
|
||||
// Use default display group for proximity sensor.
|
||||
return !mIsVrModeEnabled && (mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(
|
||||
Display.DEFAULT_DISPLAY_GROUP) & WAKE_LOCK_PROXIMITY_SCREEN_OFF) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4248,6 +4300,8 @@ public final class PowerManagerService extends SystemService
|
||||
pw.println(" lastUserActivityTimeNoChangeLights=" + TimeUtils.formatUptime(
|
||||
mDisplayGroupPowerStateMapper.getLastUserActivityTimeNoChangeLightsLocked(
|
||||
id)));
|
||||
pw.println(" mWakeLockSummary=0x" + Integer.toHexString(
|
||||
mDisplayGroupPowerStateMapper.getWakeLockSummaryLocked(id)));
|
||||
}
|
||||
|
||||
wcd = mWirelessChargerDetector;
|
||||
@@ -4738,6 +4792,7 @@ public final class PowerManagerService extends SystemService
|
||||
*/
|
||||
/* package */ final class WakeLock implements IBinder.DeathRecipient {
|
||||
public final IBinder mLock;
|
||||
public final int mDisplayId;
|
||||
public int mFlags;
|
||||
public String mTag;
|
||||
public final String mPackageName;
|
||||
@@ -4751,10 +4806,11 @@ public final class PowerManagerService extends SystemService
|
||||
public boolean mNotifiedLong;
|
||||
public boolean mDisabled;
|
||||
|
||||
public WakeLock(IBinder lock, int flags, String tag, String packageName,
|
||||
public WakeLock(IBinder lock, int displayId, int flags, String tag, String packageName,
|
||||
WorkSource workSource, String historyTag, int ownerUid, int ownerPid,
|
||||
UidState uidState) {
|
||||
mLock = lock;
|
||||
mDisplayId = displayId;
|
||||
mFlags = flags;
|
||||
mTag = tag;
|
||||
mPackageName = packageName;
|
||||
@@ -4807,6 +4863,15 @@ public final class PowerManagerService extends SystemService
|
||||
mWorkSource = copyWorkSource(workSource);
|
||||
}
|
||||
|
||||
public int getDisplayGroupId() {
|
||||
if (!mSystemReady || mDisplayId == Display.INVALID_DISPLAY) {
|
||||
return Display.INVALID_DISPLAY_GROUP;
|
||||
}
|
||||
|
||||
final DisplayInfo displayInfo = mDisplayManagerInternal.getDisplayInfo(mDisplayId);
|
||||
return displayInfo == null ? Display.INVALID_DISPLAY_GROUP : displayInfo.displayGroupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -4996,11 +5061,11 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
@Override // Binder call
|
||||
public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
|
||||
String packageName, int uid) {
|
||||
String packageName, int uid, int displayId) {
|
||||
if (uid < 0) {
|
||||
uid = Binder.getCallingUid();
|
||||
}
|
||||
acquireWakeLock(lock, flags, tag, packageName, new WorkSource(uid), null);
|
||||
acquireWakeLock(lock, flags, tag, packageName, new WorkSource(uid), null, displayId);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
@@ -5035,7 +5100,7 @@ public final class PowerManagerService extends SystemService
|
||||
|
||||
@Override // Binder call
|
||||
public void acquireWakeLock(IBinder lock, int flags, String tag, String packageName,
|
||||
WorkSource ws, String historyTag) {
|
||||
WorkSource ws, String historyTag, int displayId) {
|
||||
if (lock == null) {
|
||||
throw new IllegalArgumentException("lock must not be null");
|
||||
}
|
||||
@@ -5060,7 +5125,8 @@ public final class PowerManagerService extends SystemService
|
||||
final int pid = Binder.getCallingPid();
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
acquireWakeLockInternal(lock, flags, tag, packageName, ws, historyTag, uid, pid);
|
||||
acquireWakeLockInternal(lock, displayId, flags, tag, packageName, ws, historyTag,
|
||||
uid, pid);
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
@@ -5069,7 +5135,7 @@ public final class PowerManagerService extends SystemService
|
||||
@Override // Binder call
|
||||
public void acquireWakeLockAsync(IBinder lock, int flags, String tag, String packageName,
|
||||
WorkSource ws, String historyTag) {
|
||||
acquireWakeLock(lock, flags, tag, packageName, ws, historyTag);
|
||||
acquireWakeLock(lock, flags, tag, packageName, ws, historyTag, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
@Override // Binder call
|
||||
|
||||
@@ -467,21 +467,21 @@ public class PowerManagerServiceTest {
|
||||
// First, ensure that a normal full wake lock does not cause a wakeup
|
||||
int flags = PowerManager.FULL_WAKE_LOCK;
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token, flags, tag, packageName,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
mService.getBinderServiceInstance().releaseWakeLock(token, 0 /* flags */);
|
||||
|
||||
// Ensure that the flag does *NOT* work with a partial wake lock.
|
||||
flags = PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token, flags, tag, packageName,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
mService.getBinderServiceInstance().releaseWakeLock(token, 0 /* flags */);
|
||||
|
||||
// Verify that flag forces a wakeup when paired to a FULL_WAKE_LOCK
|
||||
flags = PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP;
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token, flags, tag, packageName,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
mService.getBinderServiceInstance().releaseWakeLock(token, 0 /* flags */);
|
||||
}
|
||||
@@ -669,7 +669,7 @@ public class PowerManagerServiceTest {
|
||||
|
||||
// Create a wakelock
|
||||
mService.getBinderServiceInstance().acquireWakeLock(new Binder(), flags, tag, pkg,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
assertThat(wakelockMap.get(tag)).isEqualTo(flags); // Verify wakelock is active.
|
||||
|
||||
// Confirm that the wakelocks have been disabled when the forceSuspend is in flight.
|
||||
@@ -727,7 +727,7 @@ public class PowerManagerServiceTest {
|
||||
// Take a nap and verify we no longer hold the blocker
|
||||
int flags = PowerManager.DOZE_WAKE_LOCK;
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token, flags, tag, packageName,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
when(mDreamManagerInternalMock.isDreaming()).thenReturn(true);
|
||||
mService.getBinderServiceInstance().goToSleep(mClock.now(),
|
||||
PowerManager.GO_TO_SLEEP_REASON_APPLICATION, 0);
|
||||
@@ -835,12 +835,93 @@ public class PowerManagerServiceTest {
|
||||
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token,
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
|
||||
null /* workSource */, null /* historyTag */);
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
advanceTime(60);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWakeLock_affectsProperDisplayGroup() throws Exception {
|
||||
final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
|
||||
final AtomicReference<DisplayManagerInternal.DisplayGroupListener> listener =
|
||||
new AtomicReference<>();
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
listener.set(invocation.getArgument(0));
|
||||
return null;
|
||||
}).when(mDisplayManagerInternalMock).registerDisplayGroupListener(any());
|
||||
final DisplayInfo info = new DisplayInfo();
|
||||
info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP;
|
||||
when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info);
|
||||
|
||||
final String pkg = mContextSpy.getOpPackageName();
|
||||
final Binder token = new Binder();
|
||||
final String tag = "testWakeLock_affectsProperDisplayGroup";
|
||||
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
createService();
|
||||
startSystem();
|
||||
listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);
|
||||
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token,
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
|
||||
null /* workSource */, null /* historyTag */, Display.DEFAULT_DISPLAY);
|
||||
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
|
||||
advanceTime(15000);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_DOZING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidDisplayGroupWakeLock_affectsAllDisplayGroups() throws Exception {
|
||||
final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1;
|
||||
final AtomicReference<DisplayManagerInternal.DisplayGroupListener> listener =
|
||||
new AtomicReference<>();
|
||||
doAnswer((Answer<Void>) invocation -> {
|
||||
listener.set(invocation.getArgument(0));
|
||||
return null;
|
||||
}).when(mDisplayManagerInternalMock).registerDisplayGroupListener(any());
|
||||
final DisplayInfo info = new DisplayInfo();
|
||||
info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP;
|
||||
when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info);
|
||||
|
||||
final String pkg = mContextSpy.getOpPackageName();
|
||||
final Binder token = new Binder();
|
||||
final String tag = "testInvalidDisplayGroupWakeLock_affectsAllDisplayGroups";
|
||||
|
||||
setMinimumScreenOffTimeoutConfig(5);
|
||||
createService();
|
||||
startSystem();
|
||||
listener.get().onDisplayGroupAdded(nonDefaultDisplayGroupId);
|
||||
|
||||
mService.getBinderServiceInstance().acquireWakeLock(token,
|
||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, tag, pkg,
|
||||
null /* workSource */, null /* historyTag */, Display.INVALID_DISPLAY);
|
||||
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
|
||||
advanceTime(15000);
|
||||
assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
assertThat(mService.getWakefulnessLocked(nonDefaultDisplayGroupId)).isEqualTo(
|
||||
WAKEFULNESS_AWAKE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoot_ShouldBeAwake() throws Exception {
|
||||
createService();
|
||||
|
||||
Reference in New Issue
Block a user