Merge "Add modified API to send more information to VrCore" into oc-dr1-dev am: c48e304bbf

am: 8cba74a660

Change-Id: If498e7946dc9ede3c81a62247149ad48723bbbc6
This commit is contained in:
Albert Chaulk
2017-07-21 18:43:08 +00:00
committed by android-build-merger
5 changed files with 84 additions and 39 deletions

View File

@@ -20,5 +20,5 @@ import android.content.ComponentName;
/** @hide */
oneway interface IVrListener {
void focusedActivityChanged(in ComponentName component);
void focusedActivityChanged(in ComponentName component, boolean running2dInVr, int pid);
}

View File

@@ -70,8 +70,10 @@ public abstract class VrListenerService extends Service {
private final IVrListener.Stub mBinder = new IVrListener.Stub() {
@Override
public void focusedActivityChanged(ComponentName component) {
mHandler.obtainMessage(MSG_ON_CURRENT_VR_ACTIVITY_CHANGED, component).sendToTarget();
public void focusedActivityChanged(
ComponentName component, boolean running2dInVr, int pid) {
mHandler.obtainMessage(MSG_ON_CURRENT_VR_ACTIVITY_CHANGED, running2dInVr ? 1 : 0,
pid, component).sendToTarget();
}
};
@@ -84,7 +86,8 @@ public abstract class VrListenerService extends Service {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_ON_CURRENT_VR_ACTIVITY_CHANGED: {
VrListenerService.this.onCurrentVrActivityChanged((ComponentName) msg.obj);
VrListenerService.this.onCurrentVrActivityChanged(
(ComponentName) msg.obj, msg.arg1 == 1, msg.arg2);
} break;
}
}
@@ -119,6 +122,29 @@ public abstract class VrListenerService extends Service {
// Override to implement
}
/**
* An extended version of onCurrentVrActivityChanged
*
* <p>This will be called when this service is initially bound, but is not
* guaranteed to be called before onUnbind. In general, this is intended to be used to
* determine when user focus has transitioned between two VR activities, or between a
* VR activity and a 2D activity. This should be overridden instead of the above
* onCurrentVrActivityChanged as that version is deprecated.</p>
*
* @param component the {@link ComponentName} of the VR activity or the 2D intent.
* @param running2dInVr true if the component is a 2D component.
* @param pid the process the component is running in.
*
* @see android.app.Activity#setVrModeEnabled
* @see android.R.attr#enableVrMode
* @hide
*/
public void onCurrentVrActivityChanged(
ComponentName component, boolean running2dInVr, int pid) {
// Override to implement. Default to old behaviour of sending null for 2D.
onCurrentVrActivityChanged(running2dInVr ? null : component);
}
/**
* Checks if the given component is enabled in user settings.
*

View File

@@ -163,6 +163,7 @@ final class VrController {
ComponentName requestedPackage;
ComponentName callingPackage;
int userId;
int processId = -1;
boolean changed = false;
synchronized (mGlobalAmLock) {
vrMode = record.requestedVrComponent != null;
@@ -172,11 +173,15 @@ final class VrController {
// Tell the VrController that a VR mode change is requested.
changed = changeVrModeLocked(vrMode, record.app);
if (record.app != null) {
processId = record.app.pid;
}
}
// Tell VrManager that a VR mode changed is requested, VrManager will handle
// notifying all non-AM dependencies if needed.
vrService.setVrMode(vrMode, requestedPackage, userId, callingPackage);
vrService.setVrMode(vrMode, requestedPackage, userId, processId, callingPackage);
return changed;
}

View File

@@ -52,10 +52,11 @@ public abstract class VrManagerInternal {
* @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 processId the process the component is running in.
* @param calling the component currently using VR mode, or null to leave unchanged.
*/
public abstract void setVrMode(boolean enabled, @NonNull ComponentName packageName,
int userId, @NonNull ComponentName calling);
int userId, int processId, @NonNull ComponentName calling);
/**
* Set whether the system has acquired a sleep token.

View File

@@ -128,6 +128,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private boolean mVrModeAllowed;
private boolean mVrModeEnabled;
private boolean mPersistentVrModeEnabled;
private boolean mRunning2dInVr;
private int mVrAppProcessId;
private EnabledComponentsObserver mComponentObserver;
private ManagedApplicationService mCurrentVrService;
private ComponentName mDefaultVrService;
@@ -178,7 +180,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
}
consumeAndApplyPendingStateLocked();
if (mBootsToVr && !mVrModeEnabled) {
setVrMode(true, mDefaultVrService, 0, null);
setVrMode(true, mDefaultVrService, 0, -1, null);
}
} else {
// Disable persistent mode when VR mode isn't allowed, allows an escape hatch to
@@ -187,12 +189,12 @@ public class VrManagerService extends SystemService implements EnabledComponentC
// Set pending state to current state.
mPendingState = (mVrModeEnabled && mCurrentVrService != null)
? new VrState(mVrModeEnabled, mCurrentVrService.getComponent(),
mCurrentVrService.getUserId(), mCurrentVrModeComponent)
? new VrState(mVrModeEnabled, mRunning2dInVr, mCurrentVrService.getComponent(),
mCurrentVrService.getUserId(), mVrAppProcessId, mCurrentVrModeComponent)
: null;
// Unbind current VR service and do necessary callbacks.
updateCurrentVrServiceLocked(false, null, 0, null);
updateCurrentVrServiceLocked(false, false, null, 0, -1, null);
}
}
}
@@ -274,26 +276,33 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private static class VrState {
final boolean enabled;
final boolean running2dInVr;
final int userId;
final int processId;
final ComponentName targetPackageName;
final ComponentName callingPackage;
final long timestamp;
final boolean defaultPermissionsGranted;
VrState(boolean enabled, ComponentName targetPackageName, int userId,
ComponentName callingPackage) {
VrState(boolean enabled, boolean running2dInVr, ComponentName targetPackageName, int userId,
int processId, ComponentName callingPackage) {
this.enabled = enabled;
this.running2dInVr = running2dInVr;
this.userId = userId;
this.processId = processId;
this.targetPackageName = targetPackageName;
this.callingPackage = callingPackage;
this.defaultPermissionsGranted = false;
this.timestamp = System.currentTimeMillis();
}
VrState(boolean enabled, ComponentName targetPackageName, int userId,
ComponentName callingPackage, boolean defaultPermissionsGranted) {
VrState(boolean enabled, boolean running2dInVr, ComponentName targetPackageName, int userId,
int processId, ComponentName callingPackage, boolean defaultPermissionsGranted) {
this.enabled = enabled;
this.running2dInVr = running2dInVr;
this.userId = userId;
this.processId = processId;
this.targetPackageName = targetPackageName;
this.callingPackage = callingPackage;
this.defaultPermissionsGranted = defaultPermissionsGranted;
@@ -394,8 +403,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC
}
// There is an active service, update it if needed
updateCurrentVrServiceLocked(mVrModeEnabled, mCurrentVrService.getComponent(),
mCurrentVrService.getUserId(), mCurrentVrModeComponent);
updateCurrentVrServiceLocked(mVrModeEnabled, mRunning2dInVr,
mCurrentVrService.getComponent(), mCurrentVrService.getUserId(),
mVrAppProcessId, mCurrentVrModeComponent);
}
}
@@ -531,9 +541,9 @@ public class VrManagerService extends SystemService implements EnabledComponentC
*/
private final class LocalService extends VrManagerInternal {
@Override
public void setVrMode(boolean enabled, ComponentName packageName, int userId,
public void setVrMode(boolean enabled, ComponentName packageName, int userId, int processId,
ComponentName callingPackage) {
VrManagerService.this.setVrMode(enabled, packageName, userId, callingPackage);
VrManagerService.this.setVrMode(enabled, packageName, userId, processId, callingPackage);
}
@Override
@@ -710,14 +720,16 @@ public class VrManagerService extends SystemService implements EnabledComponentC
* Note: Must be called while holding {@code mLock}.
*
* @param enabled new state for VR mode.
* @param running2dInVr true if we have a top-level 2D intent.
* @param component new component to be bound as a VR listener.
* @param userId user owning the component to be bound.
* @param calling the component currently using VR mode.
* @param processId the process hosting the activity specified by calling.
* @param calling the component currently using VR mode or a 2D intent.
*
* @return {@code true} if the component/user combination specified is valid.
*/
private boolean updateCurrentVrServiceLocked(boolean enabled, @NonNull ComponentName component,
int userId, ComponentName calling) {
private boolean updateCurrentVrServiceLocked(boolean enabled, boolean running2dInVr,
@NonNull ComponentName component, int userId, int processId, ComponentName calling) {
boolean sendUpdatedCaller = false;
final long identity = Binder.clearCallingIdentity();
@@ -777,6 +789,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
sendUpdatedCaller = true;
}
mCurrentVrModeComponent = calling;
mRunning2dInVr = running2dInVr;
mVrAppProcessId = processId;
if (mCurrentVrModeUser != userId) {
mCurrentVrModeUser = userId;
@@ -794,11 +808,13 @@ public class VrManagerService extends SystemService implements EnabledComponentC
if (mCurrentVrService != null && sendUpdatedCaller) {
final ComponentName c = mCurrentVrModeComponent;
final boolean b = running2dInVr;
final int pid = processId;
mCurrentVrService.sendEvent(new PendingEvent() {
@Override
public void runEvent(IInterface service) throws RemoteException {
IVrListener l = (IVrListener) service;
l.focusedActivityChanged(c);
l.focusedActivityChanged(c, b, pid);
}
});
}
@@ -1001,20 +1017,20 @@ public class VrManagerService extends SystemService implements EnabledComponentC
*/
private void consumeAndApplyPendingStateLocked(boolean disconnectIfNoPendingState) {
if (mPendingState != null) {
updateCurrentVrServiceLocked(mPendingState.enabled,
mPendingState.targetPackageName, mPendingState.userId,
updateCurrentVrServiceLocked(mPendingState.enabled, mPendingState.running2dInVr,
mPendingState.targetPackageName, mPendingState.userId, mPendingState.processId,
mPendingState.callingPackage);
mPendingState = null;
} else if (disconnectIfNoPendingState) {
updateCurrentVrServiceLocked(false, null, 0, null);
updateCurrentVrServiceLocked(false, false, null, 0, -1, null);
}
}
private void logStateLocked() {
ComponentName currentBoundService = (mCurrentVrService == null) ? null :
mCurrentVrService.getComponent();
VrState current = new VrState(mVrModeEnabled, currentBoundService, mCurrentVrModeUser,
mCurrentVrModeComponent, mWasDefaultGranted);
VrState current = new VrState(mVrModeEnabled, mRunning2dInVr, currentBoundService,
mCurrentVrModeUser, mVrAppProcessId, mCurrentVrModeComponent, mWasDefaultGranted);
if (mLoggingDeque.size() == EVENT_LOG_SIZE) {
mLoggingDeque.removeFirst();
}
@@ -1058,27 +1074,24 @@ 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, int processId, @NonNull ComponentName callingPackage) {
synchronized (mLock) {
VrState pending;
ComponentName targetListener;
ComponentName foregroundVrComponent;
// If the device is in persistent VR mode, then calls to disable VR mode are ignored,
// and the system default VR listener is used.
boolean targetEnabledState = enabled || mPersistentVrModeEnabled;
if (!enabled && mPersistentVrModeEnabled) {
boolean running2dInVr = !enabled && mPersistentVrModeEnabled;
if (running2dInVr) {
targetListener = mDefaultVrService;
// Current foreground component isn't a VR one (in 2D app case)
foregroundVrComponent = null;
} else {
targetListener = targetPackageName;
foregroundVrComponent = callingPackage;
}
pending = new VrState(
targetEnabledState, targetListener, userId, foregroundVrComponent);
pending = new VrState(targetEnabledState, running2dInVr, targetListener,
userId, processId, callingPackage);
if (!mVrModeAllowed) {
// We're not allowed to be in VR mode. Make this state pending. This will be
@@ -1103,8 +1116,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
mPendingState = null;
}
updateCurrentVrServiceLocked(
targetEnabledState, targetListener, userId, foregroundVrComponent);
updateCurrentVrServiceLocked(targetEnabledState, running2dInVr, targetListener,
userId, processId, callingPackage);
}
}
@@ -1113,7 +1126,7 @@ public class VrManagerService extends SystemService implements EnabledComponentC
setPersistentModeAndNotifyListenersLocked(enabled);
// Disabling persistent mode when not showing a VR should disable the overall vr mode.
if (!enabled && mCurrentVrModeComponent == null) {
setVrMode(false, null, 0, null);
setVrMode(false, null, 0, -1, null);
}
}
}