1 /* 2 * Copyright (C) 2023 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.wm.shell.common.pip; 18 19 import android.graphics.Rect; 20 21 import java.util.Set; 22 23 /** 24 * Interface for interacting with keep clear algorithm used to move PiP window out of the way of 25 * keep clear areas. 26 */ 27 public interface PipKeepClearAlgorithmInterface { 28 29 /** 30 * Adjust the position of picture in picture window based on the registered keep clear areas. 31 * @param pipBoundsState state of the PiP to use for the calculations 32 * @param pipBoundsAlgorithm algorithm implementation used to get the entry destination bounds 33 * @return 34 */ adjust(PipBoundsState pipBoundsState, PipBoundsAlgorithm pipBoundsAlgorithm)35 default Rect adjust(PipBoundsState pipBoundsState, PipBoundsAlgorithm pipBoundsAlgorithm) { 36 return pipBoundsState.getBounds(); 37 } 38 39 /** 40 * Calculate the bounds so that none of the keep clear areas are occluded, while the bounds stay 41 * within the allowed bounds. If such position is not feasible, return original bounds. 42 * @param defaultBounds initial bounds used in the calculation 43 * @param restrictedKeepClearAreas registered restricted keep clear areas 44 * @param unrestrictedKeepClearAreas registered unrestricted keep clear areas 45 * @param allowedBounds bounds that define the allowed space for the output, result will always 46 * be inside those bounds 47 * @return bounds that don't cover any of the keep clear areas and are within allowed bounds 48 */ findUnoccludedPosition(Rect defaultBounds, Set<Rect> restrictedKeepClearAreas, Set<Rect> unrestrictedKeepClearAreas, Rect allowedBounds)49 default Rect findUnoccludedPosition(Rect defaultBounds, Set<Rect> restrictedKeepClearAreas, 50 Set<Rect> unrestrictedKeepClearAreas, Rect allowedBounds) { 51 return defaultBounds; 52 } 53 } 54