Merge "Add stub for VirtualDeviceManagerInternal"
This commit is contained in:
committed by
Android (Google) Code Review
commit
443177b45c
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.companion.virtual;
|
||||
|
||||
/**
|
||||
* Virtual device manager local service interface.
|
||||
*/
|
||||
public abstract class VirtualDeviceManagerInternal {
|
||||
|
||||
/**
|
||||
* Returns true if the given {@code uid} is the owner of any virtual devices that are
|
||||
* currently active.
|
||||
*/
|
||||
public abstract boolean isAppOwnerOfAnyVirtualDevice(int uid);
|
||||
|
||||
/**
|
||||
* Returns true if the given {@code uid} is currently running on any virtual devices. This is
|
||||
* determined by whether the app has any activities in the task stack on a virtual-device-owned
|
||||
* display.
|
||||
*/
|
||||
public abstract boolean isAppRunningOnAnyVirtualDevice(int uid);
|
||||
}
|
||||
@@ -81,6 +81,7 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
@Override
|
||||
public void onStart() {
|
||||
publishBinderService(Context.VIRTUAL_DEVICE_SERVICE, mImpl);
|
||||
publishLocalService(VirtualDeviceManagerInternal.class, new LocalService());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,8 +120,10 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
private class VirtualDeviceImpl extends IVirtualDevice.Stub implements IBinder.DeathRecipient {
|
||||
|
||||
private final AssociationInfo mAssociationInfo;
|
||||
private final int mOwnerUid;
|
||||
|
||||
private VirtualDeviceImpl(IBinder token, AssociationInfo associationInfo) {
|
||||
private VirtualDeviceImpl(int ownerUid, IBinder token, AssociationInfo associationInfo) {
|
||||
mOwnerUid = ownerUid;
|
||||
mAssociationInfo = associationInfo;
|
||||
try {
|
||||
token.linkToDeath(this, 0);
|
||||
@@ -156,10 +159,11 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
getContext().enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.CREATE_VIRTUAL_DEVICE,
|
||||
"createVirtualDevice");
|
||||
if (!PermissionUtils.validatePackageName(getContext(), packageName, getCallingUid())) {
|
||||
final int callingUid = getCallingUid();
|
||||
if (!PermissionUtils.validatePackageName(getContext(), packageName, callingUid)) {
|
||||
throw new SecurityException(
|
||||
"Package name " + packageName + " does not belong to calling uid "
|
||||
+ getCallingUid());
|
||||
+ callingUid);
|
||||
}
|
||||
AssociationInfo associationInfo = getAssociationInfo(packageName, associationId);
|
||||
if (associationInfo == null) {
|
||||
@@ -171,7 +175,7 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
"Virtual device for association ID " + associationId
|
||||
+ " already exists");
|
||||
}
|
||||
return new VirtualDeviceImpl(token, associationInfo);
|
||||
return new VirtualDeviceImpl(callingUid, token, associationInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,4 +226,26 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class LocalService extends VirtualDeviceManagerInternal {
|
||||
|
||||
@Override
|
||||
public boolean isAppOwnerOfAnyVirtualDevice(int uid) {
|
||||
synchronized (mVirtualDeviceManagerLock) {
|
||||
int size = mVirtualDevices.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (mVirtualDevices.valueAt(i).mOwnerUid == uid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAppRunningOnAnyVirtualDevice(int uid) {
|
||||
// TODO(yukl): Implement this using DWPC.onRunningAppsChanged
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user