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 package com.android.systemui.util.display; 17 18 import android.content.Context; 19 import android.graphics.Rect; 20 import android.hardware.display.DisplayManager; 21 import android.view.Display; 22 import android.view.WindowManager; 23 24 import javax.inject.Inject; 25 26 /** 27 * Utility class for working with displays. 28 */ 29 public class DisplayHelper { 30 private final Context mContext; 31 private final DisplayManager mDisplayManager; 32 33 /** 34 * Default constructor. 35 */ 36 @Inject DisplayHelper(Context context, DisplayManager displayManager)37 public DisplayHelper(Context context, DisplayManager displayManager) { 38 mContext = context; 39 mDisplayManager = displayManager; 40 } 41 42 43 /** 44 * Returns the maximum display bounds for the given window context type. 45 */ getMaxBounds(int displayId, int windowContextType)46 public Rect getMaxBounds(int displayId, int windowContextType) { 47 final Display display = mDisplayManager.getDisplay(displayId); 48 WindowManager windowManager = mContext.createDisplayContext(display) 49 .createWindowContext(windowContextType, null) 50 .getSystemService(WindowManager.class); 51 return windowManager.getMaximumWindowMetrics().getBounds(); 52 } 53 } 54