Migrate off of streaming logging
Bug: 302723053
Test: mma
Change-Id: Idbd42915fb515021b3de5062fa1d1b55d5899583
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index 47da296..bf7a0ba 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <android-base/logging.h>
#include <android/binder_ibinder.h>
#include <android/binder_ibinder_platform.h>
#include <android/binder_stability.h>
@@ -48,8 +47,8 @@
void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/){/* do nothing */};
static void attach(const sp<IBinder>& binder) {
- // can only attach once
- CHECK_EQ(nullptr, binder->attachObject(kId, kValue, nullptr /*cookie*/, clean));
+ auto alreadyAttached = binder->attachObject(kId, kValue, nullptr /*cookie*/, clean);
+ LOG_ALWAYS_FATAL_IF(alreadyAttached != nullptr, "can only attach once");
}
static bool has(const sp<IBinder>& binder) {
return binder != nullptr && binder->findObject(kId) == kValue;
@@ -65,9 +64,9 @@
};
void clean(const void* id, void* obj, void* cookie) {
// be weary of leaks!
- // LOG(INFO) << "Deleting an ABpBinder";
+ // ALOGI("Deleting an ABpBinder");
- CHECK(id == kId) << id << " " << obj << " " << cookie;
+ LOG_ALWAYS_FATAL_IF(id != kId, "%p %p %p", id, obj, cookie);
delete static_cast<Value*>(obj);
};
@@ -121,14 +120,13 @@
if (mClazz != nullptr && !asABpBinder()) {
const String16& currentDescriptor = mClazz->getInterfaceDescriptor();
if (newDescriptor == currentDescriptor) {
- LOG(ERROR) << __func__ << ": Class descriptors '" << currentDescriptor
- << "' match during associateClass, but they are different class objects ("
- << clazz << " vs " << mClazz << "). Class descriptor collision?";
+ ALOGE("Class descriptors '%s' match during associateClass, but they are different class"
+ " objects (%p vs %p). Class descriptor collision?",
+ String8(currentDescriptor).c_str(), clazz, mClazz);
} else {
- LOG(ERROR) << __func__
- << ": Class cannot be associated on object which already has a class. "
- "Trying to associate to '"
- << newDescriptor << "' but already set to '" << currentDescriptor << "'.";
+ ALOGE("%s: Class cannot be associated on object which already has a class. "
+ "Trying to associate to '%s' but already set to '%s'.",
+ __func__, String8(newDescriptor).c_str(), String8(currentDescriptor).c_str());
}
// always a failure because we know mClazz != clazz
@@ -141,13 +139,12 @@
// more flake-proof. However, the check is not dependent on the lock.
if (descriptor != newDescriptor && !(asABpBinder() && asABpBinder()->isServiceFuzzing())) {
if (getBinder()->isBinderAlive()) {
- LOG(ERROR) << __func__ << ": Expecting binder to have class '" << newDescriptor
- << "' but descriptor is actually '" << SanitizeString(descriptor) << "'.";
+ ALOGE("%s: Expecting binder to have class '%s' but descriptor is actually '%s'.",
+ __func__, String8(newDescriptor).c_str(), SanitizeString(descriptor).c_str());
} else {
// b/155793159
- LOG(ERROR) << __func__ << ": Cannot associate class '" << newDescriptor
- << "' to dead binder with cached descriptor '" << SanitizeString(descriptor)
- << "'.";
+ ALOGE("%s: Cannot associate class '%s' to dead binder with cached descriptor '%s'.",
+ __func__, String8(newDescriptor).c_str(), SanitizeString(descriptor).c_str());
}
return false;
}
@@ -164,7 +161,7 @@
ABBinder::ABBinder(const AIBinder_Class* clazz, void* userData)
: AIBinder(clazz), BBinder(), mUserData(userData) {
- CHECK(clazz != nullptr);
+ LOG_ALWAYS_FATAL_IF(clazz == nullptr, "clazz == nullptr");
}
ABBinder::~ABBinder() {
getClass()->onDestroy(mUserData);
@@ -184,7 +181,7 @@
// technically UINT32_MAX would be okay here, but INT32_MAX is expected since this may be
// null in Java
if (args.size() > INT32_MAX) {
- LOG(ERROR) << "ABBinder::dump received too many arguments: " << args.size();
+ ALOGE("ABBinder::dump received too many arguments: %zu", args.size());
return STATUS_BAD_VALUE;
}
@@ -263,7 +260,7 @@
ABpBinder::ABpBinder(const ::android::sp<::android::IBinder>& binder)
: AIBinder(nullptr /*clazz*/), mRemote(binder) {
- CHECK(binder != nullptr);
+ LOG_ALWAYS_FATAL_IF(binder == nullptr, "binder == nullptr");
}
ABpBinder::~ABpBinder() {}
@@ -373,27 +370,27 @@
}
void AIBinder_Class_setOnDump(AIBinder_Class* clazz, AIBinder_onDump onDump) {
- CHECK(clazz != nullptr) << "setOnDump requires non-null clazz";
+ LOG_ALWAYS_FATAL_IF(clazz == nullptr, "setOnDump requires non-null clazz");
// this is required to be called before instances are instantiated
clazz->onDump = onDump;
}
void AIBinder_Class_disableInterfaceTokenHeader(AIBinder_Class* clazz) {
- CHECK(clazz != nullptr) << "disableInterfaceTokenHeader requires non-null clazz";
+ LOG_ALWAYS_FATAL_IF(clazz == nullptr, "disableInterfaceTokenHeader requires non-null clazz");
clazz->writeHeader = false;
}
void AIBinder_Class_setHandleShellCommand(AIBinder_Class* clazz,
AIBinder_handleShellCommand handleShellCommand) {
- CHECK(clazz != nullptr) << "setHandleShellCommand requires non-null clazz";
+ LOG_ALWAYS_FATAL_IF(clazz == nullptr, "setHandleShellCommand requires non-null clazz");
clazz->handleShellCommand = handleShellCommand;
}
const char* AIBinder_Class_getDescriptor(const AIBinder_Class* clazz) {
- CHECK(clazz != nullptr) << "getDescriptor requires non-null clazz";
+ LOG_ALWAYS_FATAL_IF(clazz == nullptr, "getDescriptor requires non-null clazz");
return clazz->getInterfaceDescriptorUtf8();
}
@@ -405,8 +402,8 @@
}
void AIBinder_DeathRecipient::TransferDeathRecipient::binderDied(const wp<IBinder>& who) {
- CHECK(who == mWho) << who.unsafe_get() << "(" << who.get_refs() << ") vs " << mWho.unsafe_get()
- << " (" << mWho.get_refs() << ")";
+ LOG_ALWAYS_FATAL_IF(who != mWho, "%p (%p) vs %p (%p)", who.unsafe_get(), who.get_refs(),
+ mWho.unsafe_get(), mWho.get_refs());
mOnDied(mCookie);
@@ -417,7 +414,7 @@
if (recipient != nullptr && strongWho != nullptr) {
status_t result = recipient->unlinkToDeath(strongWho, mCookie);
if (result != ::android::DEAD_OBJECT) {
- LOG(WARNING) << "Unlinking to dead binder resulted in: " << result;
+ ALOGW("Unlinking to dead binder resulted in: %d", result);
}
}
@@ -426,7 +423,7 @@
AIBinder_DeathRecipient::AIBinder_DeathRecipient(AIBinder_DeathRecipient_onBinderDied onDied)
: mOnDied(onDied), mOnUnlinked(nullptr) {
- CHECK(onDied != nullptr);
+ LOG_ALWAYS_FATAL_IF(onDied == nullptr, "onDied == nullptr");
}
void AIBinder_DeathRecipient::pruneDeadTransferEntriesLocked() {
@@ -438,7 +435,7 @@
}
binder_status_t AIBinder_DeathRecipient::linkToDeath(const sp<IBinder>& binder, void* cookie) {
- CHECK(binder != nullptr);
+ LOG_ALWAYS_FATAL_IF(binder == nullptr, "binder == nullptr");
std::lock_guard<std::mutex> l(mDeathRecipientsMutex);
@@ -459,7 +456,7 @@
}
binder_status_t AIBinder_DeathRecipient::unlinkToDeath(const sp<IBinder>& binder, void* cookie) {
- CHECK(binder != nullptr);
+ LOG_ALWAYS_FATAL_IF(binder == nullptr, "binder == nullptr");
std::lock_guard<std::mutex> l(mDeathRecipientsMutex);
@@ -471,9 +468,8 @@
status_t status = binder->unlinkToDeath(recipient, cookie, 0 /*flags*/);
if (status != ::android::OK) {
- LOG(ERROR) << __func__
- << ": removed reference to death recipient but unlink failed: "
- << statusToString(status);
+ ALOGE("%s: removed reference to death recipient but unlink failed: %s", __func__,
+ statusToString(status).c_str());
}
return PruneStatusT(status);
}
@@ -490,7 +486,7 @@
AIBinder* AIBinder_new(const AIBinder_Class* clazz, void* args) {
if (clazz == nullptr) {
- LOG(ERROR) << __func__ << ": Must provide class to construct local binder.";
+ ALOGE("%s: Must provide class to construct local binder.", __func__);
return nullptr;
}
@@ -554,8 +550,7 @@
binder_status_t AIBinder_linkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
void* cookie) {
if (binder == nullptr || recipient == nullptr) {
- LOG(ERROR) << __func__ << ": Must provide binder (" << binder << ") and recipient ("
- << recipient << ")";
+ ALOGE("%s: Must provide binder (%p) and recipient (%p)", __func__, binder, recipient);
return STATUS_UNEXPECTED_NULL;
}
@@ -566,8 +561,7 @@
binder_status_t AIBinder_unlinkToDeath(AIBinder* binder, AIBinder_DeathRecipient* recipient,
void* cookie) {
if (binder == nullptr || recipient == nullptr) {
- LOG(ERROR) << __func__ << ": Must provide binder (" << binder << ") and recipient ("
- << recipient << ")";
+ ALOGE("%s: Must provide binder (%p) and recipient (%p)", __func__, binder, recipient);
return STATUS_UNEXPECTED_NULL;
}
@@ -596,7 +590,7 @@
}
void AIBinder_decStrong(AIBinder* binder) {
if (binder == nullptr) {
- LOG(ERROR) << __func__ << ": on null binder";
+ ALOGE("%s: on null binder", __func__);
return;
}
@@ -604,7 +598,7 @@
}
int32_t AIBinder_debugGetRefCount(AIBinder* binder) {
if (binder == nullptr) {
- LOG(ERROR) << __func__ << ": on null binder";
+ ALOGE("%s: on null binder", __func__);
return -1;
}
@@ -642,15 +636,14 @@
binder_status_t AIBinder_prepareTransaction(AIBinder* binder, AParcel** in) {
if (binder == nullptr || in == nullptr) {
- LOG(ERROR) << __func__ << ": requires non-null parameters binder (" << binder
- << ") and in (" << in << ").";
+ ALOGE("%s: requires non-null parameters binder (%p) and in (%p).", __func__, binder, in);
return STATUS_UNEXPECTED_NULL;
}
const AIBinder_Class* clazz = binder->getClass();
if (clazz == nullptr) {
- LOG(ERROR) << __func__
- << ": Class must be defined for a remote binder transaction. See "
- "AIBinder_associateClass.";
+ ALOGE("%s: Class must be defined for a remote binder transaction. See "
+ "AIBinder_associateClass.",
+ __func__);
return STATUS_INVALID_OPERATION;
}
@@ -683,7 +676,7 @@
binder_status_t AIBinder_transact(AIBinder* binder, transaction_code_t code, AParcel** in,
AParcel** out, binder_flags_t flags) {
if (in == nullptr) {
- LOG(ERROR) << __func__ << ": requires non-null in parameter";
+ ALOGE("%s: requires non-null in parameter", __func__);
return STATUS_UNEXPECTED_NULL;
}
@@ -693,27 +686,26 @@
AutoParcelDestroyer forIn(in, DestroyParcel);
if (!isUserCommand(code)) {
- LOG(ERROR) << __func__
- << ": Only user-defined transactions can be made from the NDK, but requested: "
- << code;
+ ALOGE("%s: Only user-defined transactions can be made from the NDK, but requested: %d",
+ __func__, code);
return STATUS_UNKNOWN_TRANSACTION;
}
constexpr binder_flags_t kAllFlags = FLAG_PRIVATE_VENDOR | FLAG_ONEWAY | FLAG_CLEAR_BUF;
if ((flags & ~kAllFlags) != 0) {
- LOG(ERROR) << __func__ << ": Unrecognized flags sent: " << flags;
+ ALOGE("%s: Unrecognized flags sent: %d", __func__, flags);
return STATUS_BAD_VALUE;
}
if (binder == nullptr || *in == nullptr || out == nullptr) {
- LOG(ERROR) << __func__ << ": requires non-null parameters binder (" << binder << "), in ("
- << in << "), and out (" << out << ").";
+ ALOGE("%s: requires non-null parameters binder (%p), in (%p), and out (%p).", __func__,
+ binder, in, out);
return STATUS_UNEXPECTED_NULL;
}
if ((*in)->getBinder() != binder) {
- LOG(ERROR) << __func__ << ": parcel is associated with binder object " << binder
- << " but called with " << (*in)->getBinder();
+ ALOGE("%s: parcel is associated with binder object %p but called with %p", __func__, binder,
+ (*in)->getBinder());
return STATUS_BAD_VALUE;
}
@@ -733,7 +725,7 @@
AIBinder_DeathRecipient* AIBinder_DeathRecipient_new(
AIBinder_DeathRecipient_onBinderDied onBinderDied) {
if (onBinderDied == nullptr) {
- LOG(ERROR) << __func__ << ": requires non-null onBinderDied parameter.";
+ ALOGE("%s: requires non-null onBinderDied parameter.", __func__);
return nullptr;
}
auto ret = new AIBinder_DeathRecipient(onBinderDied);
@@ -799,9 +791,8 @@
void AIBinder_setRequestingSid(AIBinder* binder, bool requestingSid) {
ABBinder* localBinder = binder->asABBinder();
- if (localBinder == nullptr) {
- LOG(FATAL) << "AIBinder_setRequestingSid must be called on a local binder";
- }
+ LOG_ALWAYS_FATAL_IF(localBinder == nullptr,
+ "AIBinder_setRequestingSid must be called on a local binder");
localBinder->setRequestingSid(requestingSid);
}
@@ -816,9 +807,8 @@
void AIBinder_setInheritRt(AIBinder* binder, bool inheritRt) {
ABBinder* localBinder = binder->asABBinder();
- if (localBinder == nullptr) {
- LOG(FATAL) << "AIBinder_setInheritRt must be called on a local binder";
- }
+ LOG_ALWAYS_FATAL_IF(localBinder == nullptr,
+ "AIBinder_setInheritRt must be called on a local binder");
localBinder->setInheritRt(inheritRt);
}
diff --git a/libs/binder/ndk/parcel.cpp b/libs/binder/ndk/parcel.cpp
index 037aa2e..c15bcf9 100644
--- a/libs/binder/ndk/parcel.cpp
+++ b/libs/binder/ndk/parcel.cpp
@@ -14,20 +14,19 @@
* limitations under the License.
*/
+#include <android-base/unique_fd.h>
#include <android/binder_parcel.h>
#include <android/binder_parcel_platform.h>
-#include "parcel_internal.h"
-
-#include "ibinder_internal.h"
-#include "status_internal.h"
+#include <binder/Parcel.h>
+#include <binder/ParcelFileDescriptor.h>
+#include <inttypes.h>
+#include <utils/Unicode.h>
#include <limits>
-#include <android-base/logging.h>
-#include <android-base/unique_fd.h>
-#include <binder/Parcel.h>
-#include <binder/ParcelFileDescriptor.h>
-#include <utils/Unicode.h>
+#include "ibinder_internal.h"
+#include "parcel_internal.h"
+#include "status_internal.h"
using ::android::IBinder;
using ::android::Parcel;
@@ -52,11 +51,11 @@
if (length < -1) return STATUS_BAD_VALUE;
if (!isNullArray && length < 0) {
- LOG(ERROR) << __func__ << ": non-null array but length is " << length;
+ ALOGE("non-null array but length is %" PRIi32, length);
return STATUS_BAD_VALUE;
}
if (isNullArray && length > 0) {
- LOG(ERROR) << __func__ << ": null buffer cannot be for size " << length << " array.";
+ ALOGE("null buffer cannot be for size %" PRIi32 " array.", length);
return STATUS_BAD_VALUE;
}
@@ -325,7 +324,7 @@
binder_status_t AParcel_writeString(AParcel* parcel, const char* string, int32_t length) {
if (string == nullptr) {
if (length != -1) {
- LOG(WARNING) << __func__ << ": null string must be used with length == -1.";
+ ALOGW("null string must be used with length == -1.");
return STATUS_BAD_VALUE;
}
@@ -334,7 +333,7 @@
}
if (length < 0) {
- LOG(WARNING) << __func__ << ": Negative string length: " << length;
+ ALOGW("Negative string length: %" PRIi32, length);
return STATUS_BAD_VALUE;
}
@@ -342,7 +341,7 @@
const ssize_t len16 = utf8_to_utf16_length(str8, length);
if (len16 < 0 || len16 >= std::numeric_limits<int32_t>::max()) {
- LOG(WARNING) << __func__ << ": Invalid string length: " << len16;
+ ALOGW("Invalid string length: %zd", len16);
return STATUS_BAD_VALUE;
}
@@ -383,7 +382,7 @@
}
if (len8 <= 0 || len8 > std::numeric_limits<int32_t>::max()) {
- LOG(WARNING) << __func__ << ": Invalid string length: " << len8;
+ ALOGW("Invalid string length: %zd", len8);
return STATUS_BAD_VALUE;
}
@@ -391,7 +390,7 @@
bool success = allocator(stringData, len8, &str8);
if (!success || str8 == nullptr) {
- LOG(WARNING) << __func__ << ": AParcel_stringAllocator failed to allocate.";
+ ALOGW("AParcel_stringAllocator failed to allocate.");
return STATUS_NO_MEMORY;
}
diff --git a/libs/binder/ndk/process.cpp b/libs/binder/ndk/process.cpp
index 0fea57b..0072ac3 100644
--- a/libs/binder/ndk/process.cpp
+++ b/libs/binder/ndk/process.cpp
@@ -15,12 +15,10 @@
*/
#include <android/binder_process.h>
+#include <binder/IPCThreadState.h>
#include <mutex>
-#include <android-base/logging.h>
-#include <binder/IPCThreadState.h>
-
using ::android::IPCThreadState;
using ::android::ProcessState;
diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp
index 2977786..3bfdc59 100644
--- a/libs/binder/ndk/service_manager.cpp
+++ b/libs/binder/ndk/service_manager.cpp
@@ -15,14 +15,12 @@
*/
#include <android/binder_manager.h>
+#include <binder/IServiceManager.h>
+#include <binder/LazyServiceRegistrar.h>
#include "ibinder_internal.h"
#include "status_internal.h"
-#include <android-base/logging.h>
-#include <binder/IServiceManager.h>
-#include <binder/LazyServiceRegistrar.h>
-
using ::android::defaultServiceManager;
using ::android::IBinder;
using ::android::IServiceManager;
@@ -115,7 +113,8 @@
std::lock_guard<std::mutex> l(m);
if (onRegister == nullptr) return;
- CHECK_EQ(String8(smInstance), instance);
+ LOG_ALWAYS_FATAL_IF(String8(smInstance) != instance, "onServiceRegistration: %s != %s",
+ String8(smInstance).c_str(), instance);
sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(binder);
AIBinder_incStrong(ret.get());
@@ -135,8 +134,8 @@
AServiceManager_registerForServiceNotifications(const char* instance,
AServiceManager_onRegister onRegister,
void* cookie) {
- CHECK_NE(instance, nullptr);
- CHECK_NE(onRegister, nullptr) << instance;
+ LOG_ALWAYS_FATAL_IF(instance == nullptr, "instance == nullptr");
+ LOG_ALWAYS_FATAL_IF(onRegister == nullptr, "onRegister == nullptr for %s", instance);
// cookie can be nullptr
auto cb = sp<AServiceManager_NotificationRegistration>::make();
@@ -146,8 +145,8 @@
sp<IServiceManager> sm = defaultServiceManager();
if (status_t res = sm->registerForNotifications(String16(instance), cb); res != STATUS_OK) {
- LOG(ERROR) << "Failed to register for service notifications for " << instance << ": "
- << statusToString(res);
+ ALOGE("Failed to register for service notifications for %s: %s", instance,
+ statusToString(res).c_str());
return nullptr;
}
@@ -157,7 +156,7 @@
void AServiceManager_NotificationRegistration_delete(
AServiceManager_NotificationRegistration* notification) {
- CHECK_NE(notification, nullptr);
+ LOG_ALWAYS_FATAL_IF(notification == nullptr, "notification == nullptr");
notification->clear();
notification->decStrong(nullptr);
}
@@ -172,9 +171,9 @@
}
void AServiceManager_forEachDeclaredInstance(const char* interface, void* context,
void (*callback)(const char*, void*)) {
- CHECK(interface != nullptr);
+ LOG_ALWAYS_FATAL_IF(interface == nullptr, "interface == nullptr");
// context may be nullptr
- CHECK(callback != nullptr);
+ LOG_ALWAYS_FATAL_IF(callback == nullptr, "callback == nullptr");
sp<IServiceManager> sm = defaultServiceManager();
for (const String16& instance : sm->getDeclaredInstances(String16(interface))) {
@@ -191,9 +190,9 @@
}
void AServiceManager_getUpdatableApexName(const char* instance, void* context,
void (*callback)(const char*, void*)) {
- CHECK_NE(instance, nullptr);
+ LOG_ALWAYS_FATAL_IF(instance == nullptr, "instance == nullptr");
// context may be nullptr
- CHECK_NE(callback, nullptr);
+ LOG_ALWAYS_FATAL_IF(callback == nullptr, "callback == nullptr");
sp<IServiceManager> sm = defaultServiceManager();
std::optional<String16> updatableViaApex = sm->updatableViaApex(String16(instance));
diff --git a/libs/binder/ndk/status.cpp b/libs/binder/ndk/status.cpp
index 8ed91a5..3aac3c0 100644
--- a/libs/binder/ndk/status.cpp
+++ b/libs/binder/ndk/status.cpp
@@ -17,8 +17,6 @@
#include <android/binder_status.h>
#include "status_internal.h"
-#include <android-base/logging.h>
-
using ::android::status_t;
using ::android::statusToString;
using ::android::binder::Status;
@@ -127,8 +125,8 @@
return STATUS_UNKNOWN_ERROR;
default:
- LOG(WARNING) << __func__ << ": Unknown status_t (" << statusToString(status)
- << ") pruned into STATUS_UNKNOWN_ERROR";
+ ALOGW("%s: Unknown status_t (%s) pruned into STATUS_UNKNOWN_ERROR", __func__,
+ statusToString(status).c_str());
return STATUS_UNKNOWN_ERROR;
}
}
@@ -159,8 +157,8 @@
return EX_TRANSACTION_FAILED;
default:
- LOG(WARNING) << __func__ << ": Unknown binder exception (" << exception
- << ") pruned into EX_TRANSACTION_FAILED";
+ ALOGW("%s: Unknown binder exception (%d) pruned into EX_TRANSACTION_FAILED", __func__,
+ exception);
return EX_TRANSACTION_FAILED;
}
}