1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wm; 18 19 import android.annotation.SystemApi; 20 import android.app.ActivityOptions; 21 import android.os.IBinder; 22 import android.window.WindowContainerToken; 23 24 25 /** 26 * Wrapper of {@link ActivityOptions}. 27 * @hide 28 */ 29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 30 public final class ActivityOptionsWrapper { 31 private final ActivityOptions mOptions; 32 33 /** See {@link android.app.WindowConfiguration#WINDOWING_MODE_UNDEFINED}. */ 34 public static final int WINDOWING_MODE_UNDEFINED = 0; 35 ActivityOptionsWrapper(ActivityOptions options)36 private ActivityOptionsWrapper(ActivityOptions options) { 37 mOptions = options; 38 } 39 40 /** 41 * Creates a new instance of {@link ActivityOptionsWrapper}. 42 */ create(ActivityOptions options)43 public static ActivityOptionsWrapper create(ActivityOptions options) { 44 if (options == null) return null; 45 return new ActivityOptionsWrapper(options); 46 } 47 48 /** 49 * Gets caller display. See {@link ActivityOptions#getCallerDisplayId()} for more info. 50 */ getCallerDisplayId()51 public int getCallerDisplayId() { 52 return mOptions.getCallerDisplayId(); 53 } 54 55 /** 56 * Gets the underlying {@link ActivityOptions} that is wrapped by this instance. 57 */ 58 // Exposed the original object in order to allow to use the public accessors. getOptions()59 public ActivityOptions getOptions() { 60 return mOptions; 61 } 62 63 /** 64 * Gets the windowing mode to launch the Activity into 65 */ getLaunchWindowingMode()66 public int getLaunchWindowingMode() { 67 return mOptions.getLaunchWindowingMode(); 68 } 69 70 /** 71 * Gets {@link TaskDisplayAreaWrapper} to launch the Activity into 72 */ getLaunchTaskDisplayArea()73 public TaskDisplayAreaWrapper getLaunchTaskDisplayArea() { 74 WindowContainerToken daToken = mOptions.getLaunchTaskDisplayArea(); 75 if (daToken == null) return null; 76 TaskDisplayArea tda = (TaskDisplayArea) WindowContainer.fromBinder(daToken.asBinder()); 77 return TaskDisplayAreaWrapper.create(tda); 78 } 79 80 @Override toString()81 public String toString() { 82 StringBuilder sb = new StringBuilder(mOptions.toString()); 83 sb.append(", mLaunchDisplayId="); 84 sb.append(mOptions.getLaunchDisplayId()); 85 return sb.toString(); 86 } 87 88 /** 89 * Sets the given {@code windowContainerToken} as the launch root task. See 90 * {@link ActivityOptions#setLaunchRootTask(WindowContainerToken)} for more info. 91 */ setLaunchRootTask(IBinder windowContainerToken)92 public void setLaunchRootTask(IBinder windowContainerToken) { 93 WindowContainerToken launchRootTaskToken = WindowContainer.fromBinder(windowContainerToken) 94 .mRemoteToken.toWindowContainerToken(); 95 mOptions.setLaunchRootTask(launchRootTaskToken); 96 } 97 98 /** 99 * Sets launch display. See {@link ActivityOptions#setLaunchDisplayId(int)} for more info. 100 */ setLaunchDisplayId(int displayId)101 public void setLaunchDisplayId(int displayId) { 102 mOptions.setLaunchDisplayId(displayId); 103 } 104 } 105