blob: 9732637fdd4de020df036b7768bfe7a8f6e8b128 [file] [log] [blame]
/*
* Copyright (C) 2019 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.wm;
import android.annotation.NonNull;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
import android.view.IWindow;
import android.view.SurfaceControl;
/**
* Represents a piece of the hierarchy under which a client Shell can manage sub-windows.
*/
public class ShellRoot {
private static final String TAG = "ShellRoot";
private final DisplayContent mDisplayContent;
private IWindow mClient;
private WindowToken mToken;
private final IBinder.DeathRecipient mDeathRecipient;
private SurfaceControl mSurfaceControl = null;
ShellRoot(@NonNull IWindow client, @NonNull DisplayContent dc, final int windowType) {
mDisplayContent = dc;
mDeathRecipient = () -> mDisplayContent.removeShellRoot(windowType);
try {
client.asBinder().linkToDeath(mDeathRecipient, 0);
} catch (RemoteException e) {
Slog.e(TAG, "Unable to add shell root for layer " + windowType + " on display "
+ dc.getDisplayId(), e);
return;
}
mClient = client;
mToken = new WindowToken(
dc.mWmService, client.asBinder(), windowType, true, dc, true, false);
mSurfaceControl = mToken.makeChildSurface(null)
.setContainerLayer().setName("Shell Root Leash " + dc.getDisplayId()).build();
mToken.getPendingTransaction().show(mSurfaceControl);
}
void clear() {
if (mClient != null) {
mClient.asBinder().unlinkToDeath(mDeathRecipient, 0);
mClient = null;
}
if (mToken != null) {
mToken.removeImmediately();
mToken = null;
}
}
SurfaceControl getSurfaceControl() {
return mSurfaceControl;
}
IWindow getClient() {
return mClient;
}
}