1 /*
2 * Copyright (C) 2019 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 #pragma once
18
19 #include <android/binder_ibinder.h>
20
21 __BEGIN_DECLS
22
23 /**
24 * Indicates that this transaction is coupled w/ vendor.img
25 */
26 constexpr binder_flags_t FLAG_PRIVATE_VENDOR = 0x10000000;
27
28 #if defined(__ANDROID_VENDOR__)
29
30 /**
31 * Private addition to binder_flag_t.
32 */
33 enum {
34 FLAG_PRIVATE_LOCAL = FLAG_PRIVATE_VENDOR,
35 };
36
37 /**
38 * This interface has the stability of the vendor image.
39 */
40 void AIBinder_markVendorStability(AIBinder* binder);
41
AIBinder_markCompilationUnitStability(AIBinder * binder)42 static inline void AIBinder_markCompilationUnitStability(AIBinder* binder) {
43 AIBinder_markVendorStability(binder);
44 }
45
46 /**
47 * Given a binder interface at a certain stability, there may be some
48 * requirements associated with that higher stability level. For instance, a
49 * VINTF stability binder is required to be in the VINTF manifest. This API
50 * can be called to use that same interface within the vendor partition.
51 *
52 * WARNING: you must hold on to a binder instance after this is set, while you
53 * are using it. If you get a binder (e.g. `...->asBinder().get()`), you must
54 * save this binder and then
55 * use it. For instance:
56 *
57 * auto binder = ...->asBinder();
58 * AIBinder_forceDowngradeToVendorStability(binder.get());
59 * doSomething(binder);
60 */
61 void AIBinder_forceDowngradeToVendorStability(AIBinder* binder);
62
AIBinder_forceDowngradeToLocalStability(AIBinder * binder)63 static inline void AIBinder_forceDowngradeToLocalStability(AIBinder* binder) {
64 AIBinder_forceDowngradeToVendorStability(binder);
65 }
66
67 #else // defined(__ANDROID_VENDOR__)
68
69 enum {
70 FLAG_PRIVATE_LOCAL = 0,
71 };
72
73 /**
74 * This interface has the stability of the system image.
75 */
76 __attribute__((weak)) void AIBinder_markSystemStability(AIBinder* binder);
77
AIBinder_markCompilationUnitStability(AIBinder * binder)78 static inline void AIBinder_markCompilationUnitStability(AIBinder* binder) {
79 if (AIBinder_markSystemStability == nullptr) return;
80
81 AIBinder_markSystemStability(binder);
82 }
83
84 /**
85 * Given a binder interface at a certain stability, there may be some
86 * requirements associated with that higher stability level. For instance, a
87 * VINTF stability binder is required to be in the VINTF manifest. This API
88 * can be called to use that same interface within the system partition.
89 *
90 * WARNING: you must hold on to a binder instance after this is set, while you
91 * are using it. If you get a binder (e.g. `...->asBinder().get()`), you must
92 * save this binder and then
93 * use it. For instance:
94 *
95 * auto binder = ...->asBinder();
96 * AIBinder_forceDowngradeToSystemStability(binder.get());
97 * doSomething(binder);
98 */
99 void AIBinder_forceDowngradeToSystemStability(AIBinder* binder);
100
AIBinder_forceDowngradeToLocalStability(AIBinder * binder)101 static inline void AIBinder_forceDowngradeToLocalStability(AIBinder* binder) {
102 AIBinder_forceDowngradeToSystemStability(binder);
103 }
104
105 #endif // defined(__ANDROID_VENDOR__)
106
107 /**
108 * WARNING: this is not expected to be used manually. When the build system has
109 * versioned checks in place for an interface that prevent it being changed year
110 * over year (specifically like those for @VintfStability stable AIDL
111 * interfaces), this could be called. Calling this without this or equivalent
112 * infrastructure will lead to de facto frozen APIs or GSI test failures.
113 *
114 * This interface has system<->vendor stability
115 */
116 // b/227835797 - can't use __INTRODUCED_IN(30) because old targets load this code
117 #if defined(__ANDROID_MIN_SDK_VERSION__) && __ANDROID_MIN_SDK_VERSION__ < 30
118 __attribute__((weak))
119 #endif // defined(__ANDROID_MIN_SDK_VERSION__) && __ANDROID_MIN_SDK_VERSION__ < 30
120 void AIBinder_markVintfStability(AIBinder* binder);
121
122 __END_DECLS
123