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 android.server.wm; 17 18 19 import static org.junit.Assert.assertThrows; 20 21 import android.platform.test.annotations.Presubmit; 22 23 import org.junit.Test; 24 import org.junit.function.ThrowingRunnable; 25 26 import java.lang.reflect.InvocationTargetException; 27 28 @Presubmit 29 public class WindowManagerReflectionTests { 30 31 /** Regression test for b/273906410. */ 32 @Test requestAppKeyboardShortcuts_requiresPermission_b273906410()33 public void requestAppKeyboardShortcuts_requiresPermission_b273906410() throws Throwable { 34 Object wms = Class.forName("android.view.WindowManagerGlobal") 35 .getMethod("getWindowManagerService") 36 .invoke(null); 37 38 assertThrows(SecurityException.class, () -> { 39 runAndUnwrapTargetException(() -> { 40 Class.forName("android.view.IWindowManager") 41 .getMethod("requestAppKeyboardShortcuts", 42 Class.forName("com.android.internal.os.IResultReceiver"), 43 Integer.TYPE) 44 .invoke(wms, null, 0); 45 }); 46 }); 47 } 48 runAndUnwrapTargetException(ThrowingRunnable r)49 private void runAndUnwrapTargetException(ThrowingRunnable r) throws Throwable { 50 try { 51 r.run(); 52 } catch (InvocationTargetException e) { 53 throw e.getTargetException(); 54 } 55 } 56 } 57