1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package lockedregioncodeinjection; 15 16 public class TestScopedTarget { 17 18 public final TestScopedLock mLock;; 19 20 private boolean mNextEnterThrows = false; 21 private boolean mNextExitThrows = false; 22 TestScopedTarget()23 TestScopedTarget() { 24 mLock = new TestScopedLock(this); 25 } 26 scopedLock()27 TestScopedLock scopedLock() { 28 return mLock; 29 } 30 untypedLock()31 Object untypedLock() { 32 return mLock; 33 } 34 enter(int level)35 void enter(int level) { 36 if (mNextEnterThrows) { 37 mNextEnterThrows = false; 38 throw new RuntimeException(); 39 } 40 } 41 exit(int level)42 void exit(int level) { 43 if (mNextExitThrows) { 44 mNextExitThrows = false; 45 throw new RuntimeException(); 46 } 47 } 48 throwOnEnter(boolean b)49 void throwOnEnter(boolean b) { 50 mNextEnterThrows = b; 51 } 52 throwOnExit(boolean b)53 void throwOnExit(boolean b) { 54 mNextExitThrows = b; 55 } 56 } 57