diff options
author | 2021-12-08 20:55:43 +0000 | |
---|---|---|
committer | 2021-12-08 20:55:43 +0000 | |
commit | 443177b45c5780d3958df19c85a69509de449894 (patch) | |
tree | c1de9ee5f4c6a01e3d7d9c5326a29c8b0089f3e9 | |
parent | 06f9cccecfe9aa9ddf61094e2cf9781f6f9a6852 (diff) | |
parent | f5a4f33d2983565e840b4d88f3f49b0360df4589 (diff) |
Merge "Add stub for VirtualDeviceManagerInternal"
2 files changed, 66 insertions, 4 deletions
diff --git a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java new file mode 100644 index 000000000000..ee09832dc7e2 --- /dev/null +++ b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerInternal.java @@ -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); +} diff --git a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java index 58d08013eeff..8592c05d9ea5 100644 --- a/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java +++ b/services/companion/java/com/android/server/companion/virtual/VirtualDeviceManagerService.java @@ -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; + } + } } |