Merge "Implement DisplayWindowPolicyController"
This commit is contained in:
committed by
Android (Google) Code Review
commit
418ab6888b
@@ -24,5 +24,8 @@ java_library_static {
|
||||
type: "stream",
|
||||
},
|
||||
srcs: [":services.companion-sources"],
|
||||
libs: ["services.core"],
|
||||
libs: [
|
||||
"app-compat-annotations",
|
||||
"services.core",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.app.compat.CompatChanges;
|
||||
import android.compat.annotation.ChangeId;
|
||||
import android.compat.annotation.EnabledSince;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Build;
|
||||
import android.os.UserHandle;
|
||||
import android.window.DisplayWindowPolicyController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* A controller to control the policies of the windows that can be displayed on the virtual display.
|
||||
*/
|
||||
class GenericWindowPolicyController extends DisplayWindowPolicyController {
|
||||
|
||||
/**
|
||||
* If required, allow the secure activity to display on remote device since
|
||||
* {@link android.os.Build.VERSION_CODES#TIRAMISU}.
|
||||
*/
|
||||
@ChangeId
|
||||
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU)
|
||||
public static final long ALLOW_SECURE_ACTIVITY_DISPLAY_ON_REMOTE_DEVICE = 201712607L;
|
||||
|
||||
GenericWindowPolicyController(int windowFlags, int systemWindowFlags) {
|
||||
setInterestedWindowFlags(windowFlags, systemWindowFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canContainActivities(@NonNull List<ActivityInfo> activities) {
|
||||
// Can't display all the activities if any of them don't want to be displayed.
|
||||
final int activityCount = activities.size();
|
||||
for (int i = 0; i < activityCount; i++) {
|
||||
final ActivityInfo aInfo = activities.get(i);
|
||||
if ((aInfo.flags & ActivityInfo.FLAG_CAN_DISPLAY_ON_REMOTE_DEVICES) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keepActivityOnWindowFlagsChanged(ActivityInfo activityInfo, int windowFlags,
|
||||
int systemWindowFlags) {
|
||||
if ((activityInfo.flags & ActivityInfo.FLAG_CAN_DISPLAY_ON_REMOTE_DEVICES) == 0) {
|
||||
return false;
|
||||
}
|
||||
if (!CompatChanges.isChangeEnabled(ALLOW_SECURE_ACTIVITY_DISPLAY_ON_REMOTE_DEVICE,
|
||||
activityInfo.packageName,
|
||||
UserHandle.getUserHandleForUid(activityInfo.applicationInfo.uid))) {
|
||||
// TODO(b/201712607): Add checks for the apps that use SurfaceView#setSecure.
|
||||
if ((windowFlags & FLAG_SECURE) != 0) {
|
||||
return false;
|
||||
}
|
||||
if ((systemWindowFlags & SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS) != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopActivityChanged(ComponentName topActivity, int uid) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRunningAppsChanged(int[] runningUids) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.server.companion.virtual;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -131,11 +134,14 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
|
||||
private final AssociationInfo mAssociationInfo;
|
||||
private final int mOwnerUid;
|
||||
private final GenericWindowPolicyController mGenericWindowPolicyController;
|
||||
private final ArrayList<Integer> mDisplayIds = new ArrayList<>();
|
||||
|
||||
private VirtualDeviceImpl(int ownerUid, IBinder token, AssociationInfo associationInfo) {
|
||||
mOwnerUid = ownerUid;
|
||||
mAssociationInfo = associationInfo;
|
||||
mGenericWindowPolicyController = new GenericWindowPolicyController(FLAG_SECURE,
|
||||
SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
try {
|
||||
token.linkToDeath(this, 0);
|
||||
} catch (RemoteException e) {
|
||||
@@ -167,8 +173,7 @@ public class VirtualDeviceManagerService extends SystemService {
|
||||
"Virtual device already have a virtual display with ID " + displayId);
|
||||
}
|
||||
mDisplayIds.add(displayId);
|
||||
// TODO(b/201712607): Return the corresponding DisplayWindowPolicyController.
|
||||
return null;
|
||||
return mGenericWindowPolicyController;
|
||||
}
|
||||
|
||||
void onVirtualDisplayRemovedLocked(int displayId) {
|
||||
|
||||
Reference in New Issue
Block a user