Revert "Fix VR interaction with screen on/off/lockscreen."

This reverts commit dfe0d7157d.

Reason for revert: 33655854

Change-Id: Ie8573a394dee768859d64493dd8c17ee0c613287
This commit is contained in:
Jorim Jaggi
2016-12-15 19:48:11 +00:00
parent dfe0d7157d
commit bbb5b6e8db
5 changed files with 80 additions and 169 deletions

View File

@@ -1220,15 +1220,6 @@ public class ActivityManagerService extends IActivityManager.Stub
/**
* Set while we are wanting to sleep, to prevent any
* activities from being started/resumed.
*
* TODO(b/33594039): Clarify the actual state transitions represented by mSleeping.
*
* Currently mSleeping is set to true when transitioning into the sleep state, and remains true
* while in the sleep state until there is a pending transition out of sleep, in which case
* mSleeping is set to false, and remains false while awake.
*
* Whether mSleeping can quickly toggled between true/false without the device actually
* display changing states is undefined.
*/
private boolean mSleeping = false;
@@ -1560,9 +1551,10 @@ public class ActivityManagerService extends IActivityManager.Stub
static final int SYSTEM_USER_UNLOCK_MSG = 59;
static final int LOG_STACK_STATE = 60;
static final int VR_MODE_CHANGE_MSG = 61;
static final int SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG = 62;
static final int HANDLE_TRUST_STORAGE_UPDATE_MSG = 63;
static final int REPORT_LOCKED_BOOT_COMPLETE_MSG = 64;
static final int VR_MODE_APPLY_IF_NEEDED_MSG = 62;
static final int SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG = 63;
static final int HANDLE_TRUST_STORAGE_UPDATE_MSG = 64;
static final int REPORT_LOCKED_BOOT_COMPLETE_MSG = 65;
static final int START_USER_SWITCH_FG_MSG = 712;
static final int FIRST_ACTIVITY_STACK_MSG = 100;
@@ -2298,6 +2290,14 @@ public class ActivityManagerService extends IActivityManager.Stub
}
vrService.setVrMode(vrMode, requestedPackage, userId, callingPackage);
} break;
case VR_MODE_APPLY_IF_NEEDED_MSG: {
final ActivityRecord r = (ActivityRecord) msg.obj;
final boolean needsVrMode = r != null && r.requestedVrComponent != null;
if (needsVrMode) {
applyVrMode(msg.arg1 == 1, r.requestedVrComponent, r.userId,
r.info.getComponentName(), false);
}
} break;
case HANDLE_TRUST_STORAGE_UPDATE_MSG: {
synchronized (ActivityManagerService.this) {
for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) {
@@ -3070,12 +3070,20 @@ public class ActivityManagerService extends IActivityManager.Stub
mHandler.obtainMessage(VR_MODE_CHANGE_MSG, 0, 0, r));
}
private void notifyVrManagerOfSleepState(boolean isSleeping) {
final VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
if (vrService == null) {
return;
void applyVrModeIfNeededLocked(ActivityRecord r, boolean enable) {
mHandler.sendMessage(
mHandler.obtainMessage(VR_MODE_APPLY_IF_NEEDED_MSG, enable ? 1 : 0, 0, r));
}
private void applyVrMode(boolean enabled, ComponentName packageName, int userId,
ComponentName callingPackage, boolean immediate) {
VrManagerInternal vrService =
LocalServices.getService(VrManagerInternal.class);
if (immediate) {
vrService.setVrModeImmediate(enabled, packageName, userId, callingPackage);
} else {
vrService.setVrMode(enabled, packageName, userId, callingPackage);
}
vrService.onSleepStateChanged(isSleeping);
}
final void showAskCompatModeDialogLocked(ActivityRecord r) {
@@ -11684,7 +11692,6 @@ public class ActivityManagerService extends IActivityManager.Stub
startTimeTrackingFocusedActivityLocked();
mTopProcessState = ActivityManager.PROCESS_STATE_TOP;
mStackSupervisor.comeOutOfSleepIfNeededLocked();
notifyVrManagerOfSleepState(false);
updateOomAdjLocked();
} else if (!mSleeping && shouldSleepLocked()) {
mSleeping = true;
@@ -11693,7 +11700,6 @@ public class ActivityManagerService extends IActivityManager.Stub
}
mTopProcessState = ActivityManager.PROCESS_STATE_TOP_SLEEPING;
mStackSupervisor.goingToSleepLocked();
notifyVrManagerOfSleepState(true);
updateOomAdjLocked();
// Initialize the wake times of all processes.
@@ -22227,6 +22233,22 @@ public class ActivityManagerService extends IActivityManager.Stub
public SleepToken acquireSleepToken(String tag) {
Preconditions.checkNotNull(tag);
ComponentName requestedVrService = null;
ComponentName callingVrActivity = null;
int userId = -1;
synchronized (ActivityManagerService.this) {
final ActivityRecord resumedActivity = mStackSupervisor.getResumedActivityLocked();
if (resumedActivity != null) {
requestedVrService = resumedActivity.requestedVrComponent;
callingVrActivity = resumedActivity.info.getComponentName();
userId = resumedActivity.userId;
}
}
if (requestedVrService != null) {
applyVrMode(false, requestedVrService, userId, callingVrActivity, true);
}
synchronized (ActivityManagerService.this) {
SleepTokenImpl token = new SleepTokenImpl(tag);
mSleepTokens.add(token);

View File

@@ -121,6 +121,8 @@ class KeyguardController {
// Some stack visibility might change (e.g. docked stack)
mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
mWindowManager.executeAppTransition();
mService.applyVrModeIfNeededLocked(mStackSupervisor.getResumedActivityLocked(),
true /* enable */);
} finally {
mWindowManager.continueSurfaceLayout();
}

View File

@@ -229,7 +229,6 @@ import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
import com.android.server.policy.keyguard.KeyguardStateMonitor.StateCallback;
import com.android.server.statusbar.StatusBarManagerInternal;
import com.android.server.wm.AppTransition;
import com.android.server.vr.VrManagerInternal;
import java.io.File;
import java.io.FileReader;
@@ -6456,7 +6455,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mKeyguardDelegate.onScreenTurnedOff();
}
}
reportScreenStateToVrManager(false);
}
// Called on the DisplayManager's DisplayPowerController thread.
@@ -6492,15 +6490,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mKeyguardDelegate.onScreenTurnedOn();
}
}
reportScreenStateToVrManager(true);
}
private void reportScreenStateToVrManager(boolean isScreenOn) {
VrManagerInternal vrService = LocalServices.getService(VrManagerInternal.class);
if (vrService == null) {
return;
}
vrService.onScreenStateChanged(isScreenOn);
}
private void finishWindowsDrawn() {

View File

@@ -56,27 +56,25 @@ public abstract class VrManagerInternal {
int userId, @NonNull ComponentName calling);
/**
* Set whether the system has acquired a sleep token.
* Set the current VR mode state immediately.
*
* @param isAsleep is {@code true} if the device is asleep, or {@code false} otherwise.
* @param enabled {@code true} to enable VR mode.
* @param packageName The package name of the requested VrListenerService to bind.
* @param userId the user requesting the VrListenerService component.
* @param calling the component currently using VR mode, or null to leave unchanged.
*/
public abstract void onSleepStateChanged(boolean isAsleep);
public abstract void setVrModeImmediate(boolean enabled, @NonNull ComponentName packageName,
int userId, @NonNull ComponentName calling);
/**
* Set whether the display used for VR output is on.
*
* @param isScreenOn is {@code true} if the display is on and can receive commands,
* or {@code false} otherwise.
*/
public abstract void onScreenStateChanged(boolean isScreenOn);
/**
* Return NO_ERROR if the given package is installed on the device and enabled as a
* VrListenerService for the given current user, or a negative error code indicating a failure.
*
* @param packageName the name of the package to check, or null to select the default package.
* @return NO_ERROR if the given package is installed and is enabled, or a negative error code
* given in {@link android.service.vr.VrModeException} on failure.
*/
/**
* Return NO_ERROR if the given package is installed on the device and enabled as a
* VrListenerService for the given current user, or a negative error code indicating a failure.
*
* @param packageName the name of the package to check, or null to select the default package.
* @return NO_ERROR if the given package is installed and is enabled, or a negative error code
* given in {@link android.service.vr.VrModeException} on failure.
*/
public abstract int hasVrPackage(@NonNull ComponentName packageName, int userId);
}

View File

@@ -101,14 +101,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private static final int PENDING_STATE_DELAY_MS = 300;
private static final int EVENT_LOG_SIZE = 32;
private static final int INVALID_APPOPS_MODE = -1;
/** Null set of sleep sleep flags. */
private static final int FLAG_NONE = 0;
/** Flag set when the device is not sleeping. */
private static final int FLAG_AWAKE = 1;
/** Flag set when the screen has been turned on. */
private static final int FLAG_SCREEN_ON = 2;
/** Flag indicating that all system sleep flags have been set.*/
private static final int FLAG_ALL = FLAG_AWAKE | FLAG_SCREEN_ON;
private static native void initializeNative();
private static native void setVrModeNative(boolean enabled);
@@ -118,7 +110,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private final IBinder mOverlayToken = new Binder();
// State protected by mLock
private boolean mVrModeAllowed;
private boolean mVrModeEnabled;
private EnabledComponentsObserver mComponentObserver;
private ManagedApplicationService mCurrentVrService;
@@ -134,64 +125,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private VrState mPendingState;
private final ArrayDeque<VrState> mLoggingDeque = new ArrayDeque<>(EVENT_LOG_SIZE);
private final NotificationAccessManager mNotifAccessManager = new NotificationAccessManager();
/** Tracks the state of the screen and keyguard UI.*/
private int mSystemSleepFlags = FLAG_NONE;
private static final int MSG_VR_STATE_CHANGE = 0;
private static final int MSG_PENDING_VR_STATE_CHANGE = 1;
/**
* Set whether VR mode may be enabled.
* <p/>
* If VR mode is not allowed to be enabled, calls to set VR mode will be cached. When VR mode
* is again allowed to be enabled, the most recent cached state will be applied.
*
* @param allowed {@code true} if calling any of the setVrMode methods may cause the device to
* enter VR mode.
*/
private void setVrModeAllowedLocked(boolean allowed) {
if (mVrModeAllowed != allowed) {
mVrModeAllowed = allowed;
Slog.i(TAG, "VR mode is " + ((allowed) ? "allowed" : "disallowed"));
if (mVrModeAllowed) {
consumeAndApplyPendingStateLocked();
} else {
// Set pending state to current state.
mPendingState = (mVrModeEnabled && mCurrentVrService != null)
? new VrState(mVrModeEnabled, mCurrentVrService.getComponent(),
mCurrentVrService.getUserId(), mCurrentVrModeComponent)
: null;
// Unbind current VR service and do necessary callbacks.
updateCurrentVrServiceLocked(false, null, 0, null);
}
}
}
private void setSleepState(boolean isAsleep) {
synchronized(mLock) {
if (!isAsleep) {
mSystemSleepFlags |= FLAG_AWAKE;
} else {
mSystemSleepFlags &= ~FLAG_AWAKE;
}
setVrModeAllowedLocked(mSystemSleepFlags == FLAG_ALL);
}
}
private void setScreenOn(boolean isScreenOn) {
synchronized(mLock) {
if (isScreenOn) {
mSystemSleepFlags |= FLAG_SCREEN_ON;
} else {
mSystemSleepFlags &= ~FLAG_SCREEN_ON;
}
setVrModeAllowedLocked(mSystemSleepFlags == FLAG_ALL);
}
}
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -211,9 +148,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
} break;
case MSG_PENDING_VR_STATE_CHANGE : {
synchronized(mLock) {
if (mVrModeAllowed) {
VrManagerService.this.consumeAndApplyPendingStateLocked();
}
VrManagerService.this.consumeAndApplyPendingStateLocked();
}
} break;
default :
@@ -333,8 +268,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
}
mNotifAccessManager.update(enabledPackages);
if (!mVrModeAllowed) {
return; // Don't do anything, we shouldn't be in VR mode.
if (mCurrentVrService == null) {
return; // No active services
}
// If there is a pending state change, we'd better deal with that first
@@ -386,7 +321,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
return;
}
pw.println("********* Dump of VrManagerService *********");
pw.println("VR mode is currently: " + ((mVrModeAllowed) ? "allowed" : "disallowed"));
pw.println("Previous state transitions:\n");
String tab = " ";
dumpStateTransitions(pw);
@@ -440,17 +374,13 @@ public class VrManagerService extends SystemService implements EnabledComponentC
@Override
public void setVrMode(boolean enabled, ComponentName packageName, int userId,
ComponentName callingPackage) {
VrManagerService.this.setVrMode(enabled, packageName, userId, callingPackage);
VrManagerService.this.setVrMode(enabled, packageName, userId, callingPackage, false);
}
@Override
public void onSleepStateChanged(boolean isAsleep) {
VrManagerService.this.setSleepState(isAsleep);
}
@Override
public void onScreenStateChanged(boolean isScreenOn) {
VrManagerService.this.setScreenOn(isScreenOn);
public void setVrModeImmediate(boolean enabled, ComponentName packageName, int userId,
ComponentName callingPackage) {
VrManagerService.this.setVrMode(enabled, packageName, userId, callingPackage, true);
}
@Override
@@ -494,10 +424,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
mComponentObserver.rebuildAll();
}
} else if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
synchronized (mLock) {
mVrModeAllowed = true;
}
}
}
@@ -540,16 +466,12 @@ public class VrManagerService extends SystemService implements EnabledComponentC
false, mOverlayToken, null, oldUserId);
}
if (!mVrModeEnabled) {
return;
}
// Apply the restrictions for the current user based on vr state
String[] exemptions = (exemptedPackage == null) ? new String[0] :
new String[] { exemptedPackage };
appOpsManager.setUserRestrictionForUser(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
true, mOverlayToken, exemptions, newUserId);
mVrModeEnabled, mOverlayToken, exemptions, newUserId);
}
private void updateDependentAppOpsLocked(String newVrServicePackage, int newUserId,
@@ -590,8 +512,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
boolean validUserComponent = (mComponentObserver.isValid(component, userId) ==
EnabledComponentsObserver.NO_ERROR);
boolean goingIntoVrMode = validUserComponent && enabled;
if (!mVrModeEnabled && !goingIntoVrMode) {
if (!mVrModeEnabled && !enabled) {
return validUserComponent; // Disabled -> Disabled transition does nothing.
}
@@ -599,37 +520,29 @@ public class VrManagerService extends SystemService implements EnabledComponentC
? mCurrentVrService.getComponent().getPackageName() : null;
final int oldUserId = mCurrentVrModeUser;
// Notify system services and VR HAL of mode change.
changeVrModeLocked(goingIntoVrMode);
// Always send mode change events.
changeVrModeLocked(enabled);
boolean nothingChanged = false;
if (!goingIntoVrMode) {
// Not going into VR mode, unbind whatever is running
if (!enabled || !validUserComponent) {
// Unbind whatever is running
if (mCurrentVrService != null) {
Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() + " for user " +
mCurrentVrService.getUserId());
mCurrentVrService.disconnect();
mCurrentVrService = null;
} else {
nothingChanged = true;
}
} else {
// Going into VR mode
if (mCurrentVrService != null) {
// Unbind any running service that doesn't match the latest component/user
// selection.
// Unbind any running service that doesn't match the component/user selection
if (mCurrentVrService.disconnectIfNotMatching(component, userId)) {
Slog.i(TAG, "Disconnecting " + mCurrentVrService.getComponent() +
" for user " + mCurrentVrService.getUserId());
createAndConnectService(component, userId);
sendUpdatedCaller = true;
} else {
nothingChanged = true;
}
// The service with the correct component/user is already bound, do nothing.
// The service with the correct component/user is bound
} else {
// Nothing was previously running, bind a new service for the latest
// component/user selection.
// Nothing was previously running, bind a new service
createAndConnectService(component, userId);
sendUpdatedCaller = true;
}
@@ -664,10 +577,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
}
});
}
if (!nothingChanged) {
logStateLocked();
}
logStateLocked();
return validUserComponent;
} finally {
@@ -862,10 +772,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
mPendingState.targetPackageName, mPendingState.userId,
mPendingState.callingPackage);
mPendingState = null;
} else {
updateCurrentVrServiceLocked(false, null, 0, null);
}
}
private void logStateLocked() {
@@ -915,20 +822,13 @@ public class VrManagerService extends SystemService implements EnabledComponentC
/*
* Implementation of VrManagerInternal calls. These are callable from system services.
*/
private void setVrMode(boolean enabled, @NonNull ComponentName targetPackageName,
int userId, @NonNull ComponentName callingPackage) {
int userId, @NonNull ComponentName callingPackage, boolean immediate) {
synchronized (mLock) {
VrState pending = new VrState(enabled, targetPackageName, userId, callingPackage);
if (!mVrModeAllowed) {
// We're not allowed to be in VR mode. Make this state pending. This will be
// applied the next time we are allowed to enter VR mode unless it is superseded by
// another call.
mPendingState = pending;
return;
}
if (!enabled && mCurrentVrService != null) {
if (!enabled && mCurrentVrService != null && !immediate) {
// If we're transitioning out of VR mode, delay briefly to avoid expensive HAL calls
// and service bind/unbind in case we are immediately switching to another VR app.
if (mPendingState == null) {
@@ -936,7 +836,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
PENDING_STATE_DELAY_MS);
}
mPendingState = pending;
mPendingState = new VrState(enabled, targetPackageName, userId, callingPackage);
return;
} else {
mHandler.removeMessages(MSG_PENDING_VR_STATE_CHANGE);