blob: f44ee7a234ca4ceb6538689ee60f89662c4378a3 [file] [log] [blame]
Bryce Leedacefc42017-10-10 12:56:02 -07001/*
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;
Bryce Leeec55eb02017-12-05 20:51:27 -080022
23import com.android.server.am.LaunchParamsController.LaunchParams;
24import com.android.server.am.LaunchParamsController.LaunchParamsModifier;
Bryce Leedacefc42017-10-10 12:56:02 -070025
26/**
Bryce Leeec55eb02017-12-05 20:51:27 -080027 * An implementation of {@link LaunchParamsModifier}, which applies the launch bounds specified
Bryce Leedacefc42017-10-10 12:56:02 -070028 * inside {@link ActivityOptions#getLaunchBounds()}.
29 */
Bryce Leeec55eb02017-12-05 20:51:27 -080030public class ActivityLaunchParamsModifier implements LaunchParamsModifier {
Bryce Leedacefc42017-10-10 12:56:02 -070031 private final ActivityStackSupervisor mSupervisor;
32
Bryce Leeec55eb02017-12-05 20:51:27 -080033 ActivityLaunchParamsModifier(ActivityStackSupervisor activityStackSupervisor) {
Bryce Leedacefc42017-10-10 12:56:02 -070034 mSupervisor = activityStackSupervisor;
35 }
36
37 @Override
Bryce Leeec55eb02017-12-05 20:51:27 -080038 public int onCalculate(TaskRecord task, ActivityInfo.WindowLayout layout,
39 ActivityRecord activity, ActivityRecord source, ActivityOptions options,
40 LaunchParams currentParams, LaunchParams outParams) {
Bryce Leedacefc42017-10-10 12:56:02 -070041 // 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)
Bryce Leeec55eb02017-12-05 20:51:27 -080048 && (activity.isResizeable() || (task != null && task.isResizeable())))) {
Bryce Leedacefc42017-10-10 12:56:02 -070049 return RESULT_SKIP;
50 }
51
Bryce Leef3c6a472017-11-14 14:53:06 -080052 final Rect bounds = options.getLaunchBounds();
Bryce Leedacefc42017-10-10 12:56:02 -070053
54 // Bounds weren't valid.
Bryce Leef3c6a472017-11-14 14:53:06 -080055 if (bounds == null || bounds.isEmpty()) {
Bryce Leedacefc42017-10-10 12:56:02 -070056 return RESULT_SKIP;
57 }
58
Bryce Leeec55eb02017-12-05 20:51:27 -080059 outParams.mBounds.set(bounds);
Bryce Leedacefc42017-10-10 12:56:02 -070060
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}