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.hoststubgen.test.tinyframework; 17 18 import android.hosttest.annotation.HostSideTestClassLoadHook; 19 import android.hosttest.annotation.HostSideTestIgnore; 20 import android.hosttest.annotation.HostSideTestKeep; 21 import android.hosttest.annotation.HostSideTestRemove; 22 import android.hosttest.annotation.HostSideTestSubstitute; 23 import android.hosttest.annotation.HostSideTestThrow; 24 25 /** 26 * Test without class-wide annotations. 27 */ 28 @HostSideTestKeep 29 @HostSideTestClassLoadHook( 30 "com.android.hoststubgen.test.tinyframework.TinyFrameworkClassLoadHook.onClassLoaded") 31 public final class TinyFrameworkAnnotations { 32 @HostSideTestKeep TinyFrameworkAnnotations()33 public TinyFrameworkAnnotations() { 34 } 35 36 @HostSideTestKeep 37 public int keep = 1; 38 39 // Members will be deleted by default. 40 // Deleted fields cannot have an initial value, because otherwise .ctor will fail to set it at 41 // runtime. 42 public int remove; 43 44 @HostSideTestKeep addOne(int value)45 public final int addOne(int value) { 46 return value + 1; 47 } 48 49 @HostSideTestRemove // Explicitly remove toBeRemoved(String foo)50 public void toBeRemoved(String foo) { 51 throw new RuntimeException(); 52 } 53 54 @HostSideTestSubstitute(suffix = "_host") addTwo(int value)55 public int addTwo(int value) { 56 throw new RuntimeException("not supported on host side"); 57 } 58 addTwo_host(int value)59 public int addTwo_host(int value) { 60 return value + 2; 61 } 62 63 @HostSideTestSubstitute(suffix = "_host") nativeAddThree(int value)64 public final static native int nativeAddThree(int value); 65 66 // This method is private, but at runtime, it'll inherit the visibility of the original method nativeAddThree_host(int value)67 private final static int nativeAddThree_host(int value) { 68 return value + 3; 69 } 70 71 @HostSideTestThrow unsupportedMethod()72 public String unsupportedMethod() { 73 return "This value shouldn't be seen on the host side."; 74 } 75 76 @HostSideTestIgnore toBeIgnored()77 public int toBeIgnored() { 78 throw new RuntimeException("not supported on host side"); 79 } 80 } 81