Set stability for unset interfaces.
This specifically has handwritten interfaces in mind. This CL ensures
that if there is a handwritten interface, it'll be marked with 'local'
stability before it is sent out. This means that a handwritten interface
won't accidentally be interpretted as a stable interface.
Bug: 136027762
Test: boot
Merged-In: I97e3e7c72f99e12dbf00996ff0c68fb683f3c494
Change-Id: I97e3e7c72f99e12dbf00996ff0c68fb683f3c494
diff --git a/libs/binder/Stability.cpp b/libs/binder/Stability.cpp
index d6d312a..f18bdca 100644
--- a/libs/binder/Stability.cpp
+++ b/libs/binder/Stability.cpp
@@ -13,29 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
#include <binder/Stability.h>
namespace android {
namespace internal {
void Stability::markCompilationUnit(IBinder* binder) {
-#ifdef __ANDROID_VNDK__
-constexpr Stability::Level kLocalStability = Stability::Level::VENDOR;
-#else
-constexpr Stability::Level kLocalStability = Stability::Level::SYSTEM;
-#endif
-
- status_t result = set(binder, kLocalStability);
+ status_t result = set(binder, kLocalStability, true /*log*/);
LOG_ALWAYS_FATAL_IF(result != OK, "Should only mark known object.");
}
void Stability::markVintf(IBinder* binder) {
- status_t result = set(binder, Level::VINTF);
+ status_t result = set(binder, Level::VINTF, true /*log*/);
LOG_ALWAYS_FATAL_IF(result != OK, "Should only mark known object.");
}
-status_t Stability::set(IBinder* binder, int32_t stability) {
+void Stability::tryMarkCompilationUnit(IBinder* binder) {
+ (void) set(binder, kLocalStability, false /*log*/);
+}
+
+status_t Stability::set(IBinder* binder, int32_t stability, bool log) {
Level currentStability = get(binder);
// null binder is always written w/ 'UNDECLARED' stability
@@ -43,23 +40,26 @@
if (stability == UNDECLARED) {
return OK;
} else {
- ALOGE("Null binder written with stability %s.", stabilityString(stability).c_str());
+ if (log) {
+ ALOGE("Null binder written with stability %s.",
+ stabilityString(stability).c_str());
+ }
return BAD_TYPE;
}
}
if (!isDeclaredStability(stability)) {
- // There are UNDECLARED sets because some binder interfaces don't set their stability, and
- // then UNDECLARED stability is sent on the other side.
- if (stability != UNDECLARED) {
+ if (log) {
ALOGE("Can only set known stability, not %d.", stability);
- return BAD_TYPE;
}
+ return BAD_TYPE;
}
if (currentStability != Level::UNDECLARED && currentStability != stability) {
- ALOGE("Interface being set with %s but it is already marked as %s.",
- stabilityString(stability).c_str(), stabilityString(stability).c_str());
+ if (log) {
+ ALOGE("Interface being set with %s but it is already marked as %s.",
+ stabilityString(stability).c_str(), stabilityString(stability).c_str());
+ }
return BAD_TYPE;
}