1 /* <lambda>null2 * Copyright 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 androidx.window.area.utils 18 19 import android.annotation.SuppressLint 20 import android.view.Window 21 import androidx.window.extensions.area.ExtensionWindowAreaPresentation 22 import java.lang.reflect.Method 23 24 internal object PresentationWindowCompatUtils { 25 26 // We perform our own extensions vendor API level check at the call-site 27 @SuppressLint("BanUncheckedReflection") 28 fun getWindowBeforeVendorApiLevel4( 29 extensionPresentation: ExtensionWindowAreaPresentation 30 ): Window? { 31 val getWindowMethod = getWindowMethod(extensionPresentation) 32 return if (getWindowMethod == null) null 33 else (getWindowMethod.invoke(extensionPresentation) as Window?) 34 } 35 36 private fun getWindowMethod(extensionPresentation: ExtensionWindowAreaPresentation): Method? { 37 return extensionPresentation.javaClass.methods.firstOrNull { method: Method? -> 38 method?.name == "getWindow" && method.returnType == android.view.Window::class.java 39 } 40 } 41 } 42