1/* 2 * Copyright (C) 2017 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 17package com.android.server.am; 18 19import android.app.ActivityOptions; 20import android.content.pm.ActivityInfo; 21import android.graphics.Rect; 22 23import com.android.server.am.LaunchParamsController.LaunchParams; 24import com.android.server.am.LaunchParamsController.LaunchParamsModifier; 25 26/** 27 * An implementation of {@link LaunchParamsModifier}, which applies the launch bounds specified 28 * inside {@link ActivityOptions#getLaunchBounds()}. 29 */ 30public class ActivityLaunchParamsModifier implements LaunchParamsModifier { 31 private final ActivityStackSupervisor mSupervisor; 32 33 ActivityLaunchParamsModifier(ActivityStackSupervisor activityStackSupervisor) { 34 mSupervisor = activityStackSupervisor; 35 } 36 37 @Override 38 public int onCalculate(TaskRecord task, ActivityInfo.WindowLayout layout, 39 ActivityRecord activity, ActivityRecord source, ActivityOptions options, 40 LaunchParams currentParams, LaunchParams outParams) { 41 // We only care about figuring out bounds for activities. 42 if (activity == null) { 43 return RESULT_SKIP; 44 } 45 46 // Activity must be resizeable in the specified task. 47 if (!(mSupervisor.canUseActivityOptionsLaunchBounds(options) 48 && (activity.isResizeable() || (task != null && task.isResizeable())))) { 49 return RESULT_SKIP; 50 } 51 52 final Rect bounds = options.getLaunchBounds(); 53 54 // Bounds weren't valid. 55 if (bounds == null || bounds.isEmpty()) { 56 return RESULT_SKIP; 57 } 58 59 outParams.mBounds.set(bounds); 60 61 // When this is the most explicit position specification so we should not allow further 62 // modification of the position. 63 return RESULT_DONE; 64 } 65} 66