Merge "Revert "Revert "Add remote callbacks for persistent vr mode"""
This commit is contained in:
committed by
Android (Google) Code Review
commit
327dfaa659
@@ -282,6 +282,7 @@ LOCAL_SRC_FILES += \
|
||||
core/java/android/service/notification/IStatusBarNotificationHolder.aidl \
|
||||
core/java/android/service/notification/IConditionListener.aidl \
|
||||
core/java/android/service/notification/IConditionProvider.aidl \
|
||||
core/java/android/service/vr/IPersistentVrStateCallbacks.aidl \
|
||||
core/java/android/service/vr/IVrListener.aidl \
|
||||
core/java/android/service/vr/IVrManager.aidl \
|
||||
core/java/android/service/vr/IVrStateCallbacks.aidl \
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
* Copyright (c) 2017, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -13,19 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.server.vr;
|
||||
|
||||
/**
|
||||
* Listener for state changes to persistent VR mode.
|
||||
*
|
||||
* @hide Only for use within system server.
|
||||
*/
|
||||
public abstract class PersistentVrStateListener {
|
||||
package android.service.vr;
|
||||
|
||||
/** @hide */
|
||||
oneway interface IPersistentVrStateCallbacks {
|
||||
|
||||
void onPersistentVrStateChanged(in boolean enabled);
|
||||
|
||||
/**
|
||||
* Called when the Persistent VR mode state changes.
|
||||
*
|
||||
* @param enabled {@code true} if persistent VR mode is enabled.
|
||||
*/
|
||||
public abstract void onPersistentVrStateChanged(boolean enabled);
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.service.vr;
|
||||
|
||||
import android.service.vr.IVrStateCallbacks;
|
||||
import android.service.vr.IPersistentVrStateCallbacks;
|
||||
|
||||
/** @hide */
|
||||
interface IVrManager {
|
||||
@@ -35,6 +36,20 @@ interface IVrManager {
|
||||
*/
|
||||
void unregisterListener(in IVrStateCallbacks cb);
|
||||
|
||||
/**
|
||||
* Add a callback to be notified when persistent VR mode state changes.
|
||||
*
|
||||
* @param cb the callback instance to add.
|
||||
*/
|
||||
void registerPersistentVrStateListener(in IPersistentVrStateCallbacks cb);
|
||||
|
||||
/**
|
||||
* Remove the callack from the current set of registered callbacks.
|
||||
*
|
||||
* @param cb the callback to remove.
|
||||
*/
|
||||
void unregisterPersistentVrStateListener(in IPersistentVrStateCallbacks cb);
|
||||
|
||||
/**
|
||||
* Return current VR mode state.
|
||||
*
|
||||
|
||||
@@ -298,6 +298,7 @@ import android.provider.Settings;
|
||||
import android.service.voice.IVoiceInteractionSession;
|
||||
import android.service.voice.VoiceInteractionManagerInternal;
|
||||
import android.service.voice.VoiceInteractionSession;
|
||||
import android.service.vr.IPersistentVrStateCallbacks;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
@@ -370,7 +371,6 @@ import com.android.server.firewall.IntentFirewall;
|
||||
import com.android.server.pm.Installer;
|
||||
import com.android.server.pm.Installer.InstallerException;
|
||||
import com.android.server.statusbar.StatusBarManagerInternal;
|
||||
import com.android.server.vr.PersistentVrStateListener;
|
||||
import com.android.server.vr.VrManagerInternal;
|
||||
import com.android.server.wm.WindowManagerService;
|
||||
|
||||
@@ -627,8 +627,8 @@ public class ActivityManagerService extends IActivityManager.Stub
|
||||
private int mVrState = NON_VR_MODE;
|
||||
private int mTopAppVrThreadTid = 0;
|
||||
private int mPersistentVrThreadTid = 0;
|
||||
final PersistentVrStateListener mPersistentVrModeListener =
|
||||
new PersistentVrStateListener() {
|
||||
final IPersistentVrStateCallbacks mPersistentVrModeListener =
|
||||
new IPersistentVrStateCallbacks.Stub() {
|
||||
@Override
|
||||
public void onPersistentVrStateChanged(boolean enabled) {
|
||||
synchronized(ActivityManagerService.this) {
|
||||
|
||||
@@ -183,6 +183,7 @@ import android.provider.Settings;
|
||||
import android.service.dreams.DreamManagerInternal;
|
||||
import android.service.dreams.DreamService;
|
||||
import android.service.dreams.IDreamManager;
|
||||
import android.service.vr.IPersistentVrStateCallbacks;
|
||||
import android.speech.RecognizerIntent;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.util.DisplayMetrics;
|
||||
@@ -237,7 +238,6 @@ 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 com.android.server.vr.PersistentVrStateListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -1000,8 +1000,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
|
||||
}
|
||||
MyOrientationListener mOrientationListener;
|
||||
|
||||
final PersistentVrStateListener mPersistentVrModeListener =
|
||||
new PersistentVrStateListener() {
|
||||
final IPersistentVrStateCallbacks mPersistentVrModeListener =
|
||||
new IPersistentVrStateCallbacks.Stub() {
|
||||
@Override
|
||||
public void onPersistentVrStateChanged(boolean enabled) {
|
||||
mPersistentVrModeEnabled = enabled;
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.android.server.vr;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.ComponentName;
|
||||
import android.service.vr.IPersistentVrStateCallbacks;
|
||||
|
||||
/**
|
||||
* Service for accessing the VR mode manager.
|
||||
@@ -101,5 +102,5 @@ public abstract class VrManagerInternal {
|
||||
/**
|
||||
* Adds listener that reports state changes to persistent VR mode.
|
||||
*/
|
||||
public abstract void addPersistentVrModeStateListener(PersistentVrStateListener listener);
|
||||
public abstract void addPersistentVrModeStateListener(IPersistentVrStateCallbacks listener);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.vr.IPersistentVrStateCallbacks;
|
||||
import android.service.vr.IVrListener;
|
||||
import android.service.vr.IVrManager;
|
||||
import android.service.vr.IVrStateCallbacks;
|
||||
@@ -123,10 +124,10 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
private int mCurrentVrModeUser;
|
||||
private boolean mWasDefaultGranted;
|
||||
private boolean mGuard;
|
||||
private final RemoteCallbackList<IVrStateCallbacks> mRemoteCallbacks =
|
||||
private final RemoteCallbackList<IVrStateCallbacks> mVrStateRemoteCallbacks =
|
||||
new RemoteCallbackList<>();
|
||||
private final ArrayList<PersistentVrStateListener> mPersistentVrStateListeners =
|
||||
new ArrayList<>();
|
||||
private final RemoteCallbackList<IPersistentVrStateCallbacks>
|
||||
mPersistentVrStateRemoteCallbacks = new RemoteCallbackList<>();
|
||||
private int mPreviousCoarseLocationMode = INVALID_APPOPS_MODE;
|
||||
private int mPreviousManageOverlayMode = INVALID_APPOPS_MODE;
|
||||
private VrState mPendingState;
|
||||
@@ -202,16 +203,16 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
switch(msg.what) {
|
||||
case MSG_VR_STATE_CHANGE : {
|
||||
boolean state = (msg.arg1 == 1);
|
||||
int i = mRemoteCallbacks.beginBroadcast();
|
||||
int i = mVrStateRemoteCallbacks.beginBroadcast();
|
||||
while (i > 0) {
|
||||
i--;
|
||||
try {
|
||||
mRemoteCallbacks.getBroadcastItem(i).onVrStateChanged(state);
|
||||
mVrStateRemoteCallbacks.getBroadcastItem(i).onVrStateChanged(state);
|
||||
} catch (RemoteException e) {
|
||||
// Noop
|
||||
}
|
||||
}
|
||||
mRemoteCallbacks.finishBroadcast();
|
||||
mVrStateRemoteCallbacks.finishBroadcast();
|
||||
} break;
|
||||
case MSG_PENDING_VR_STATE_CHANGE : {
|
||||
synchronized(mLock) {
|
||||
@@ -222,10 +223,17 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
} break;
|
||||
case MSG_PERSISTENT_VR_MODE_STATE_CHANGE : {
|
||||
boolean state = (msg.arg1 == 1);
|
||||
for (int i = 0; i < mPersistentVrStateListeners.size(); i++) {
|
||||
mPersistentVrStateListeners.get(i).onPersistentVrStateChanged(
|
||||
state);
|
||||
int i = mPersistentVrStateRemoteCallbacks.beginBroadcast();
|
||||
while (i > 0) {
|
||||
i--;
|
||||
try {
|
||||
mPersistentVrStateRemoteCallbacks.getBroadcastItem(i)
|
||||
.onPersistentVrStateChanged(state);
|
||||
} catch (RemoteException e) {
|
||||
// Noop
|
||||
}
|
||||
}
|
||||
mPersistentVrStateRemoteCallbacks.finishBroadcast();
|
||||
} break;
|
||||
default :
|
||||
throw new IllegalStateException("Unknown message type: " + msg.what);
|
||||
@@ -382,6 +390,26 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
VrManagerService.this.removeStateCallback(cb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPersistentVrStateListener(IPersistentVrStateCallbacks cb) {
|
||||
enforceCallerPermission(Manifest.permission.ACCESS_VR_MANAGER);
|
||||
if (cb == null) {
|
||||
throw new IllegalArgumentException("Callback binder object is null.");
|
||||
}
|
||||
|
||||
VrManagerService.this.addPersistentStateCallback(cb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterPersistentVrStateListener(IPersistentVrStateCallbacks cb) {
|
||||
enforceCallerPermission(Manifest.permission.ACCESS_VR_MANAGER);
|
||||
if (cb == null) {
|
||||
throw new IllegalArgumentException("Callback binder object is null.");
|
||||
}
|
||||
|
||||
VrManagerService.this.removePersistentStateCallback(cb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getVrModeState() {
|
||||
return VrManagerService.this.getVrMode();
|
||||
@@ -414,13 +442,21 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
String tab = " ";
|
||||
dumpStateTransitions(pw);
|
||||
pw.println("\n\nRemote Callbacks:");
|
||||
int i=mRemoteCallbacks.beginBroadcast(); // create the broadcast item array
|
||||
int i=mVrStateRemoteCallbacks.beginBroadcast(); // create the broadcast item array
|
||||
while(i-->0) {
|
||||
pw.print(tab);
|
||||
pw.print(mRemoteCallbacks.getBroadcastItem(i));
|
||||
pw.print(mVrStateRemoteCallbacks.getBroadcastItem(i));
|
||||
if (i>0) pw.println(",");
|
||||
}
|
||||
mRemoteCallbacks.finishBroadcast();
|
||||
mVrStateRemoteCallbacks.finishBroadcast();
|
||||
pw.println("\n\nPersistent Vr State Remote Callbacks:");
|
||||
i=mPersistentVrStateRemoteCallbacks.beginBroadcast();
|
||||
while(i-->0) {
|
||||
pw.print(tab);
|
||||
pw.print(mPersistentVrStateRemoteCallbacks.getBroadcastItem(i));
|
||||
if (i>0) pw.println(",");
|
||||
}
|
||||
mPersistentVrStateRemoteCallbacks.finishBroadcast();
|
||||
pw.println("\n");
|
||||
pw.println("Installed VrListenerService components:");
|
||||
int userId = mCurrentVrModeUser;
|
||||
@@ -443,16 +479,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
pw.println(n.flattenToString());
|
||||
}
|
||||
}
|
||||
pw.println("Attached persistent mode listeners:");
|
||||
if (mPersistentVrStateListeners == null ||
|
||||
mPersistentVrStateListeners.size() == 0) {
|
||||
pw.println("None");
|
||||
} else {
|
||||
for (PersistentVrStateListener l : mPersistentVrStateListeners) {
|
||||
pw.print(tab);
|
||||
pw.println("listener: " + l);
|
||||
}
|
||||
}
|
||||
pw.println("\n");
|
||||
pw.println("********* End of VrManagerService Dump *********");
|
||||
}
|
||||
@@ -507,8 +533,8 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPersistentVrModeStateListener(PersistentVrStateListener listener) {
|
||||
VrManagerService.this.addPersistentVrModeStateListener(listener);
|
||||
public void addPersistentVrModeStateListener(IPersistentVrStateCallbacks listener) {
|
||||
VrManagerService.this.addPersistentStateCallback(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,12 +1110,6 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
(mPersistentVrModeEnabled) ? 1 : 0, 0));
|
||||
}
|
||||
|
||||
private void addPersistentVrModeStateListener(PersistentVrStateListener listener) {
|
||||
synchronized (mLock) {
|
||||
mPersistentVrStateListeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
private int hasVrPackage(@NonNull ComponentName targetPackageName, int userId) {
|
||||
synchronized (mLock) {
|
||||
return mComponentObserver.isValid(targetPackageName, userId);
|
||||
@@ -1111,11 +1131,19 @@ public class VrManagerService extends SystemService implements EnabledComponentC
|
||||
*/
|
||||
|
||||
private void addStateCallback(IVrStateCallbacks cb) {
|
||||
mRemoteCallbacks.register(cb);
|
||||
mVrStateRemoteCallbacks.register(cb);
|
||||
}
|
||||
|
||||
private void removeStateCallback(IVrStateCallbacks cb) {
|
||||
mRemoteCallbacks.unregister(cb);
|
||||
mVrStateRemoteCallbacks.unregister(cb);
|
||||
}
|
||||
|
||||
private void addPersistentStateCallback(IPersistentVrStateCallbacks cb) {
|
||||
mPersistentVrStateRemoteCallbacks.register(cb);
|
||||
}
|
||||
|
||||
private void removePersistentStateCallback(IPersistentVrStateCallbacks cb) {
|
||||
mPersistentVrStateRemoteCallbacks.unregister(cb);
|
||||
}
|
||||
|
||||
private boolean getVrMode() {
|
||||
|
||||
Reference in New Issue
Block a user