1 /* 2 * Copyright (C) 2024 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.wallpaper.util 17 18 import android.content.Context 19 import android.hardware.display.DisplayManager 20 import android.util.Log 21 import android.view.Display 22 import dagger.hilt.android.qualifiers.ApplicationContext 23 import javax.inject.Inject 24 import javax.inject.Singleton 25 26 @Singleton 27 class DisplaysProviderImpl 28 @Inject 29 constructor(@ApplicationContext private val appContext: Context) : DisplaysProvider { <lambda>null30 private val displayManager: DisplayManager by lazy { 31 appContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager 32 } 33 getInternalDisplaysnull34 override fun getInternalDisplays(): List<Display> { 35 val allDisplays: Array<out Display> = 36 displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED) 37 if (allDisplays.isEmpty()) { 38 Log.e(TAG, "No displays found on context $appContext") 39 throw RuntimeException("No displays found!") 40 } 41 return allDisplays.filter { it.type == Display.TYPE_INTERNAL } 42 } 43 companion object { 44 private const val TAG = "DisplaysProviderImpl" 45 } 46 } 47