Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 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 | |
| 17 | package com.android.server.am; |
| 18 | |
| 19 | import android.app.ActivityOptions; |
| 20 | import android.content.pm.ActivityInfo; |
| 21 | import android.graphics.Rect; |
| 22 | import com.android.server.am.LaunchingBoundsController.LaunchingBoundsPositioner; |
| 23 | |
| 24 | /** |
| 25 | * An implementation of {@link LaunchingBoundsPositioner}, which applies the launch bounds specified |
| 26 | * inside {@link ActivityOptions#getLaunchBounds()}. |
| 27 | */ |
| 28 | public class LaunchingActivityPositioner implements LaunchingBoundsPositioner { |
| 29 | private final ActivityStackSupervisor mSupervisor; |
| 30 | |
| 31 | LaunchingActivityPositioner(ActivityStackSupervisor activityStackSupervisor) { |
| 32 | mSupervisor = activityStackSupervisor; |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public int onCalculateBounds(TaskRecord task, ActivityInfo.WindowLayout layout, |
Bryce Lee | e4ad745 | 2017-10-26 08:44:04 -0700 | [diff] [blame] | 37 | ActivityRecord activity, ActivityRecord source, |
| 38 | ActivityOptions options, Rect current, Rect result) { |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 39 | // We only care about figuring out bounds for activities. |
| 40 | if (activity == null) { |
| 41 | return RESULT_SKIP; |
| 42 | } |
| 43 | |
| 44 | // Activity must be resizeable in the specified task. |
| 45 | if (!(mSupervisor.canUseActivityOptionsLaunchBounds(options) |
| 46 | && (activity.isResizeable() || (task != null && task.isResizeable())))) { |
| 47 | return RESULT_SKIP; |
| 48 | } |
| 49 | |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 50 | final Rect bounds = options.getLaunchBounds(); |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 51 | |
| 52 | // Bounds weren't valid. |
Bryce Lee | f3c6a47 | 2017-11-14 14:53:06 -0800 | [diff] [blame] | 53 | if (bounds == null || bounds.isEmpty()) { |
Bryce Lee | dacefc4 | 2017-10-10 12:56:02 -0700 | [diff] [blame] | 54 | return RESULT_SKIP; |
| 55 | } |
| 56 | |
| 57 | result.set(bounds); |
| 58 | |
| 59 | // When this is the most explicit position specification so we should not allow further |
| 60 | // modification of the position. |
| 61 | return RESULT_DONE; |
| 62 | } |
| 63 | } |