Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 android.os; |
| 18 | |
Tadashi G. Takaoka | b4470f2 | 2019-01-15 18:29:15 +0900 | [diff] [blame] | 19 | import androidx.test.filters.SmallTest; |
Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 20 | |
| 21 | import junit.framework.TestCase; |
| 22 | |
| 23 | public class BinderTest extends TestCase { |
Olivier Gaillard | d542b1c | 2018-11-14 15:24:35 +0000 | [diff] [blame] | 24 | private static final int UID = 100; |
Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 25 | |
| 26 | @SmallTest |
| 27 | public void testSetWorkSource() throws Exception { |
Olivier Gaillard | d542b1c | 2018-11-14 15:24:35 +0000 | [diff] [blame] | 28 | Binder.setCallingWorkSourceUid(UID); |
| 29 | assertEquals(UID, Binder.getCallingWorkSourceUid()); |
Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @SmallTest |
| 33 | public void testClearWorkSource() throws Exception { |
Olivier Gaillard | d542b1c | 2018-11-14 15:24:35 +0000 | [diff] [blame] | 34 | Binder.setCallingWorkSourceUid(UID); |
| 35 | Binder.clearCallingWorkSource(); |
| 36 | assertEquals(-1, Binder.getCallingWorkSourceUid()); |
| 37 | } |
| 38 | |
| 39 | @SmallTest |
| 40 | public void testRestoreWorkSource() throws Exception { |
| 41 | Binder.setCallingWorkSourceUid(UID); |
| 42 | long token = Binder.clearCallingWorkSource(); |
| 43 | Binder.restoreCallingWorkSource(token); |
| 44 | assertEquals(UID, Binder.getCallingWorkSourceUid()); |
Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 45 | } |
Nikita Ioffe | a929cf0 | 2019-01-03 13:35:22 +0000 | [diff] [blame] | 46 | |
| 47 | @SmallTest |
| 48 | public void testGetCallingUidOrThrow() throws Exception { |
| 49 | try { |
| 50 | Binder.getCallingUidOrThrow(); |
| 51 | throw new AssertionError("IllegalStateException expected"); |
| 52 | } catch (IllegalStateException expected) { |
| 53 | } |
| 54 | } |
Yo Chiang | b031685 | 2020-01-21 16:10:20 +0800 | [diff] [blame^] | 55 | |
| 56 | @SmallTest |
| 57 | public void testGetExtension() throws Exception { |
| 58 | Binder binder = new Binder(); |
| 59 | assertNull(binder.getExtension()); |
| 60 | |
| 61 | IBinder extension = new Binder(); |
| 62 | binder.setExtension(extension); |
| 63 | assertNotNull(binder.getExtension()); |
| 64 | assertSame(binder.getExtension(), extension); |
| 65 | |
| 66 | binder.setExtension(null); |
| 67 | assertNull(binder.getExtension()); |
| 68 | } |
Olivier Gaillard | e4ff397 | 2018-08-16 14:01:58 +0100 | [diff] [blame] | 69 | } |