Merge "Winscope: Prevent layers trace from capturing entries once its disabled"
diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp
index fa23d3a..0fd2dd4 100644
--- a/cmds/installd/dexopt.cpp
+++ b/cmds/installd/dexopt.cpp
@@ -773,7 +773,8 @@
}
// program name, reference profile fd, the final NULL and the profile fds
- const char* argv[3 + profile_args.size() + apk_args.size() + (copy_and_update ? 1 : 0)];
+ const char* argv[3 + profile_args.size() + apk_args.size()
+ + dex_location_args.size() + (copy_and_update ? 1 : 0)];
int i = 0;
argv[i++] = profman_bin;
argv[i++] = reference_profile_arg.c_str();
diff --git a/libs/binder/ActivityManager.cpp b/libs/binder/ActivityManager.cpp
index 2728f35..28d0e4f 100644
--- a/libs/binder/ActivityManager.cpp
+++ b/libs/binder/ActivityManager.cpp
@@ -34,16 +34,16 @@
std::lock_guard<Mutex> scoped_lock(mLock);
int64_t startTime = 0;
sp<IActivityManager> service = mService;
- while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
+ while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
sp<IBinder> binder = defaultServiceManager()->checkService(String16("activity"));
- if (binder == NULL) {
+ if (binder == nullptr) {
// Wait for the activity service to come back...
if (startTime == 0) {
startTime = uptimeMillis();
ALOGI("Waiting for activity service");
} else if ((uptimeMillis() - startTime) > 1000000) {
ALOGW("Waiting too long for activity service, giving up");
- service = NULL;
+ service = nullptr;
break;
}
usleep(25000);
@@ -58,7 +58,7 @@
int ActivityManager::openContentUri(const String16& stringUri)
{
sp<IActivityManager> service = getService();
- return service != NULL ? service->openContentUri(stringUri) : -1;
+ return service != nullptr ? service->openContentUri(stringUri) : -1;
}
void ActivityManager::registerUidObserver(const sp<IUidObserver>& observer,
@@ -67,7 +67,7 @@
const String16& callingPackage)
{
sp<IActivityManager> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
service->registerUidObserver(observer, event, cutpoint, callingPackage);
}
}
@@ -75,7 +75,7 @@
void ActivityManager::unregisterUidObserver(const sp<IUidObserver>& observer)
{
sp<IActivityManager> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
service->unregisterUidObserver(observer);
}
}
@@ -83,7 +83,7 @@
bool ActivityManager::isUidActive(const uid_t uid, const String16& callingPackage)
{
sp<IActivityManager> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
return service->isUidActive(uid, callingPackage);
}
return false;
@@ -91,7 +91,7 @@
status_t ActivityManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) {
sp<IActivityManager> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
return IInterface::asBinder(service)->linkToDeath(recipient);
}
return INVALID_OPERATION;
@@ -99,7 +99,7 @@
status_t ActivityManager::unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient) {
sp<IActivityManager> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
return IInterface::asBinder(service)->unlinkToDeath(recipient);
}
return INVALID_OPERATION;
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index b8d6c78..d642a48 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -63,6 +63,7 @@
"MemoryDealer.cpp",
"MemoryHeapBase.cpp",
"Parcel.cpp",
+ "ParcelFileDescriptor.cpp",
"PermissionCache.cpp",
"PermissionController.cpp",
"PersistableBundle.cpp",
diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp
index 62c8987..a494e22 100644
--- a/libs/binder/AppOpsManager.cpp
+++ b/libs/binder/AppOpsManager.cpp
@@ -42,7 +42,7 @@
static const sp<IBinder>& getToken(const sp<IAppOpsService>& service) {
pthread_mutex_lock(&gTokenMutex);
- if (gToken == NULL || gToken->pingBinder() != NO_ERROR) {
+ if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) {
gToken = service->getToken(new BBinder());
}
pthread_mutex_unlock(&gTokenMutex);
@@ -63,16 +63,16 @@
std::lock_guard<Mutex> scoped_lock(mLock);
int64_t startTime = 0;
sp<IAppOpsService> service = mService;
- while (service == NULL || !IInterface::asBinder(service)->isBinderAlive()) {
+ while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
sp<IBinder> binder = defaultServiceManager()->checkService(_appops);
- if (binder == NULL) {
+ if (binder == nullptr) {
// Wait for the app ops service to come back...
if (startTime == 0) {
startTime = uptimeMillis();
ALOGI("Waiting for app ops service");
} else if ((uptimeMillis()-startTime) > 10000) {
ALOGW("Waiting too long for app ops service, giving up");
- service = NULL;
+ service = nullptr;
break;
}
sleep(1);
@@ -88,14 +88,14 @@
int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage)
{
sp<IAppOpsService> service = getService();
- return service != NULL
+ return service != nullptr
? service->checkOperation(op, uid, callingPackage)
: APP_OPS_MANAGER_UNAVAILABLE_MODE;
}
int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) {
sp<IAppOpsService> service = getService();
- return service != NULL
+ return service != nullptr
? service->noteOperation(op, uid, callingPackage)
: APP_OPS_MANAGER_UNAVAILABLE_MODE;
}
@@ -103,14 +103,14 @@
int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
bool startIfModeDefault) {
sp<IAppOpsService> service = getService();
- return service != NULL
+ return service != nullptr
? service->startOperation(getToken(service), op, uid, callingPackage,
startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE;
}
void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) {
sp<IAppOpsService> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
service->finishOperation(getToken(service), op, uid, callingPackage);
}
}
@@ -118,21 +118,21 @@
void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName,
const sp<IAppOpsCallback>& callback) {
sp<IAppOpsService> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
service->startWatchingMode(op, packageName, callback);
}
}
void AppOpsManager::stopWatchingMode(const sp<IAppOpsCallback>& callback) {
sp<IAppOpsService> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
service->stopWatchingMode(callback);
}
}
int32_t AppOpsManager::permissionToOpCode(const String16& permission) {
sp<IAppOpsService> service = getService();
- if (service != NULL) {
+ if (service != nullptr) {
return service->permissionToOpCode(permission);
}
return -1;
diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp
index a81f44e..1bd7c4f 100644
--- a/libs/binder/Binder.cpp
+++ b/libs/binder/Binder.cpp
@@ -43,17 +43,17 @@
sp<IInterface> IBinder::queryLocalInterface(const String16& /*descriptor*/)
{
- return NULL;
+ return nullptr;
}
BBinder* IBinder::localBinder()
{
- return NULL;
+ return nullptr;
}
BpBinder* IBinder::remoteBinder()
{
- return NULL;
+ return nullptr;
}
bool IBinder::checkSubclass(const void* /*subclassID*/) const
@@ -76,8 +76,8 @@
for (size_t i = 0; i < numArgs; i++) {
send.writeString16(args[i]);
}
- send.writeStrongBinder(callback != NULL ? IInterface::asBinder(callback) : NULL);
- send.writeStrongBinder(resultReceiver != NULL ? IInterface::asBinder(resultReceiver) : NULL);
+ send.writeStrongBinder(callback != nullptr ? IInterface::asBinder(callback) : nullptr);
+ send.writeStrongBinder(resultReceiver != nullptr ? IInterface::asBinder(resultReceiver) : nullptr);
return target->transact(SHELL_COMMAND_TRANSACTION, send, &reply);
}
@@ -130,7 +130,7 @@
break;
}
- if (reply != NULL) {
+ if (reply != nullptr) {
reply->setDataPosition(0);
}
@@ -171,7 +171,7 @@
delete e;
e = expected; // Filled in by CAS
}
- if (e == 0) return; // out of memory
+ if (e == nullptr) return; // out of memory
}
AutoMutex _l(e->mLock);
@@ -181,7 +181,7 @@
void* BBinder::findObject(const void* objectID) const
{
Extras* e = mExtras.load(std::memory_order_acquire);
- if (!e) return NULL;
+ if (!e) return nullptr;
AutoMutex _l(e->mLock);
return e->mObjects.find(objectID);
@@ -246,7 +246,7 @@
(void)out;
(void)err;
- if (resultReceiver != NULL) {
+ if (resultReceiver != nullptr) {
resultReceiver->send(INVALID_OPERATION);
}
@@ -273,7 +273,7 @@
};
BpRefBase::BpRefBase(const sp<IBinder>& o)
- : mRemote(o.get()), mRefs(NULL), mState(0)
+ : mRemote(o.get()), mRefs(nullptr), mState(0)
{
extendObjectLifetime(OBJECT_LIFETIME_WEAK);
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 449a9e9..7342126 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -80,7 +80,7 @@
void* BpBinder::ObjectManager::find(const void* objectID) const
{
const ssize_t i = mObjects.indexOfKey(objectID);
- if (i < 0) return NULL;
+ if (i < 0) return nullptr;
return mObjects.valueAt(i).object;
}
@@ -95,7 +95,7 @@
ALOGV("Killing %zu objects in manager %p", N, this);
for (size_t i=0; i<N; i++) {
const entry_t& e = mObjects.valueAt(i);
- if (e.func != NULL) {
+ if (e.func != nullptr) {
e.func(mObjects.keyAt(i), e.object, e.cleanupCookie);
}
}
@@ -139,7 +139,7 @@
: mHandle(handle)
, mAlive(1)
, mObitsSent(0)
- , mObituaries(NULL)
+ , mObituaries(nullptr)
, mTrackedUid(trackedUid)
{
ALOGV("Creating BpBinder %p handle %d\n", this, mHandle);
@@ -228,7 +228,7 @@
ob.cookie = cookie;
ob.flags = flags;
- LOG_ALWAYS_FATAL_IF(recipient == NULL,
+ LOG_ALWAYS_FATAL_IF(recipient == nullptr,
"linkToDeath(): recipient must be non-NULL");
{
@@ -268,9 +268,9 @@
for (size_t i=0; i<N; i++) {
const Obituary& obit = mObituaries->itemAt(i);
if ((obit.recipient == recipient
- || (recipient == NULL && obit.cookie == cookie))
+ || (recipient == nullptr && obit.cookie == cookie))
&& obit.flags == flags) {
- if (outRecipient != NULL) {
+ if (outRecipient != nullptr) {
*outRecipient = mObituaries->itemAt(i).recipient;
}
mObituaries->removeAt(i);
@@ -280,7 +280,7 @@
self->clearDeathNotification(mHandle, this);
self->flushCommands();
delete mObituaries;
- mObituaries = NULL;
+ mObituaries = nullptr;
}
return NO_ERROR;
}
@@ -299,12 +299,12 @@
mLock.lock();
Vector<Obituary>* obits = mObituaries;
- if(obits != NULL) {
+ if(obits != nullptr) {
ALOGV("Clearing sent death notification: %p handle %d\n", this, mHandle);
IPCThreadState* self = IPCThreadState::self();
self->clearDeathNotification(mHandle, this);
self->flushCommands();
- mObituaries = NULL;
+ mObituaries = nullptr;
}
mObitsSent = 1;
mLock.unlock();
@@ -312,7 +312,7 @@
ALOGV("Reporting death of proxy %p for %zu recipients\n",
this, obits ? obits->size() : 0U);
- if (obits != NULL) {
+ if (obits != nullptr) {
const size_t N = obits->size();
for (size_t i=0; i<N; i++) {
reportOneDeath(obits->itemAt(i));
@@ -326,7 +326,7 @@
{
sp<DeathRecipient> recipient = obit.recipient.promote();
ALOGV("Reporting death to recipient: %p\n", recipient.get());
- if (recipient == NULL) return;
+ if (recipient == nullptr) return;
recipient->binderDied(this);
}
@@ -386,13 +386,13 @@
mLock.lock();
Vector<Obituary>* obits = mObituaries;
- if(obits != NULL) {
+ if(obits != nullptr) {
if (ipc) ipc->clearDeathNotification(mHandle, this);
- mObituaries = NULL;
+ mObituaries = nullptr;
}
mLock.unlock();
- if (obits != NULL) {
+ if (obits != nullptr) {
// XXX Should we tell any remaining DeathRecipient
// objects that the last strong ref has gone away, so they
// are no longer linked?
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 30e70b0..0946aca 100644
--- a/libs/binder/BufferedTextOutput.cpp
+++ b/libs/binder/BufferedTextOutput.cpp
@@ -36,7 +36,7 @@
{
explicit BufferState(int32_t _seq)
: seq(_seq)
- , buffer(NULL)
+ , buffer(nullptr)
, bufferPos(0)
, bufferSize(0)
, atFront(true)
@@ -266,13 +266,13 @@
if ((mFlags&MULTITHREADED) != 0) {
ThreadState* ts = getThreadState();
if (ts) {
- while (ts->states.size() <= (size_t)mIndex) ts->states.add(NULL);
+ while (ts->states.size() <= (size_t)mIndex) ts->states.add(nullptr);
BufferState* bs = ts->states[mIndex].get();
- if (bs != NULL && bs->seq == mSeq) return bs;
+ if (bs != nullptr && bs->seq == mSeq) return bs;
ts->states.editItemAt(mIndex) = new BufferState(mIndex);
bs = ts->states[mIndex].get();
- if (bs != NULL) return bs;
+ if (bs != nullptr) return bs;
}
}
diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp
index 4ac61a3..f38bbb2 100644
--- a/libs/binder/Debug.cpp
+++ b/libs/binder/Debug.cpp
@@ -165,13 +165,13 @@
else if (bytesPerLine >= 8) alignment = 2;
else alignment = 1;
}
- if (func == NULL) func = defaultPrintFunc;
+ if (func == nullptr) func = defaultPrintFunc;
size_t offset;
unsigned char *pos = (unsigned char *)buf;
- if (pos == NULL) {
+ if (pos == nullptr) {
if (singleLineBytesCutoff < 0) func(cookie, "\n");
func(cookie, "(NULL)");
return;
@@ -297,7 +297,7 @@
ssize_t getBinderKernelReferences(size_t count, uintptr_t* buf) {
sp<ProcessState> proc = ProcessState::selfOrNull();
- if (proc.get() == NULL) {
+ if (proc.get() == nullptr) {
return 0;
}
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp
index 9c76350..068664b 100644
--- a/libs/binder/IAppOpsService.cpp
+++ b/libs/binder/IAppOpsService.cpp
@@ -109,7 +109,7 @@
data.writeStrongBinder(clientToken);
remote()->transact(GET_TOKEN_TRANSACTION, data, &reply);
// fail on exception
- if (reply.readExceptionCode() != 0) return NULL;
+ if (reply.readExceptionCode() != 0) return nullptr;
return reply.readStrongBinder();
}
diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp
index 2fcd3d9..6b77291 100644
--- a/libs/binder/IInterface.cpp
+++ b/libs/binder/IInterface.cpp
@@ -32,14 +32,14 @@
// static
sp<IBinder> IInterface::asBinder(const IInterface* iface)
{
- if (iface == NULL) return NULL;
+ if (iface == nullptr) return nullptr;
return const_cast<IInterface*>(iface)->onAsBinder();
}
// static
sp<IBinder> IInterface::asBinder(const sp<IInterface>& iface)
{
- if (iface == NULL) return NULL;
+ if (iface == nullptr) return nullptr;
return iface->onAsBinder();
}
diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp
index 5c1a4f4..7afec45 100644
--- a/libs/binder/IMemory.cpp
+++ b/libs/binder/IMemory.cpp
@@ -130,7 +130,7 @@
public:
explicit BpMemory(const sp<IBinder>& impl);
virtual ~BpMemory();
- virtual sp<IMemoryHeap> getMemory(ssize_t* offset=0, size_t* size=0) const;
+ virtual sp<IMemoryHeap> getMemory(ssize_t* offset=nullptr, size_t* size=nullptr) const;
private:
mutable sp<IMemoryHeap> mHeap;
@@ -145,22 +145,22 @@
sp<IMemoryHeap> realHeap = BpMemoryHeap::get_heap(binder);
void* const base = realHeap->base();
if (base == MAP_FAILED)
- return 0;
+ return nullptr;
return static_cast<char*>(base) + offset;
}
void* IMemory::pointer() const {
ssize_t offset;
sp<IMemoryHeap> heap = getMemory(&offset);
- void* const base = heap!=0 ? heap->base() : MAP_FAILED;
+ void* const base = heap!=nullptr ? heap->base() : MAP_FAILED;
if (base == MAP_FAILED)
- return 0;
+ return nullptr;
return static_cast<char*>(base) + offset;
}
size_t IMemory::size() const {
size_t size;
- getMemory(NULL, &size);
+ getMemory(nullptr, &size);
return size;
}
@@ -183,16 +183,16 @@
sp<IMemoryHeap> BpMemory::getMemory(ssize_t* offset, size_t* size) const
{
- if (mHeap == 0) {
+ if (mHeap == nullptr) {
Parcel data, reply;
data.writeInterfaceToken(IMemory::getInterfaceDescriptor());
if (remote()->transact(GET_MEMORY, data, &reply) == NO_ERROR) {
sp<IBinder> heap = reply.readStrongBinder();
ssize_t o = reply.readInt32();
size_t s = reply.readInt32();
- if (heap != 0) {
+ if (heap != nullptr) {
mHeap = interface_cast<IMemoryHeap>(heap);
- if (mHeap != 0) {
+ if (mHeap != nullptr) {
size_t heapSize = mHeap->getSize();
if (s <= heapSize
&& o >= 0
@@ -202,7 +202,7 @@
} else {
// Hm.
android_errorWriteWithInfoLog(0x534e4554,
- "26877992", -1, NULL, 0);
+ "26877992", -1, nullptr, 0);
mOffset = 0;
mSize = 0;
}
@@ -212,7 +212,7 @@
}
if (offset) *offset = mOffset;
if (size) *size = mSize;
- return (mSize > 0) ? mHeap : 0;
+ return (mSize > 0) ? mHeap : nullptr;
}
// ---------------------------------------------------------------------------
@@ -334,7 +334,7 @@
access |= PROT_WRITE;
}
mRealHeap = true;
- mBase = mmap(0, size, access, MAP_SHARED, fd, offset);
+ mBase = mmap(nullptr, size, access, MAP_SHARED, fd, offset);
if (mBase == MAP_FAILED) {
ALOGE("cannot map BpMemoryHeap (binder=%p), size=%zd, fd=%d (%s)",
IInterface::asBinder(this).get(), size, fd, strerror(errno));
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index fd552b4..b2217b5 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -289,7 +289,7 @@
if (gShutdown) {
ALOGW("Calling IPCThreadState::self() during shutdown is dangerous, expect a crash.\n");
- return NULL;
+ return nullptr;
}
pthread_mutex_lock(&gTLSMutex);
@@ -299,7 +299,7 @@
pthread_mutex_unlock(&gTLSMutex);
ALOGW("IPCThreadState::self() unable to create TLS key, expect a crash: %s\n",
strerror(key_create_value));
- return NULL;
+ return nullptr;
}
gHaveTLS = true;
}
@@ -314,7 +314,7 @@
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(k);
return st;
}
- return NULL;
+ return nullptr;
}
void IPCThreadState::shutdown()
@@ -326,7 +326,7 @@
IPCThreadState* st = (IPCThreadState*)pthread_getspecific(gTLS);
if (st) {
delete st;
- pthread_setspecific(gTLS, NULL);
+ pthread_setspecific(gTLS, nullptr);
}
pthread_key_delete(gTLS);
gHaveTLS = false;
@@ -608,7 +608,7 @@
LOG_ONEWAY(">>>> SEND from pid %d uid %d %s", getpid(), getuid(),
(flags & TF_ONE_WAY) == 0 ? "READ REPLY" : "ONE WAY");
- err = writeTransactionData(BC_TRANSACTION, flags, handle, code, data, NULL);
+ err = writeTransactionData(BC_TRANSACTION, flags, handle, code, data, nullptr);
if (err != NO_ERROR) {
if (reply) reply->setError(err);
@@ -645,7 +645,7 @@
else alog << "(none requested)" << endl;
}
} else {
- err = waitForResponse(NULL, NULL);
+ err = waitForResponse(nullptr, nullptr);
}
return err;
@@ -755,7 +755,7 @@
err = writeTransactionData(BC_REPLY, flags, -1, 0, reply, &statusBuffer);
if (err < NO_ERROR) return err;
- return waitForResponse(NULL, NULL);
+ return waitForResponse(nullptr, nullptr);
}
status_t IPCThreadState::waitForResponse(Parcel *reply, status_t *acquireResult)
@@ -815,14 +815,14 @@
freeBuffer, this);
} else {
err = *reinterpret_cast<const status_t*>(tr.data.ptr.buffer);
- freeBuffer(NULL,
+ freeBuffer(nullptr,
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
tr.offsets_size/sizeof(binder_size_t), this);
}
} else {
- freeBuffer(NULL,
+ freeBuffer(nullptr,
reinterpret_cast<const uint8_t*>(tr.data.ptr.buffer),
tr.data_size,
reinterpret_cast<const binder_size_t*>(tr.data.ptr.offsets),
@@ -1217,7 +1217,7 @@
alog << "Writing BC_FREE_BUFFER for " << data << endl;
}
ALOG_ASSERT(data != NULL, "Called with NULL data");
- if (parcel != NULL) parcel->closeFileDescriptors();
+ if (parcel != nullptr) parcel->closeFileDescriptors();
IPCThreadState* state = self();
state->mOut.writeInt32(BC_FREE_BUFFER);
state->mOut.writePointer((uintptr_t)data);
diff --git a/libs/binder/IResultReceiver.cpp b/libs/binder/IResultReceiver.cpp
index 646809e..14b5259 100644
--- a/libs/binder/IResultReceiver.cpp
+++ b/libs/binder/IResultReceiver.cpp
@@ -40,7 +40,7 @@
Parcel data;
data.writeInterfaceToken(IResultReceiver::getInterfaceDescriptor());
data.writeInt32(resultCode);
- remote()->transact(OP_SEND, data, NULL, IBinder::FLAG_ONEWAY);
+ remote()->transact(OP_SEND, data, nullptr, IBinder::FLAG_ONEWAY);
}
};
@@ -56,7 +56,7 @@
CHECK_INTERFACE(IResultReceiver, data, reply);
int32_t resultCode = data.readInt32();
send(resultCode);
- if (reply != NULL) {
+ if (reply != nullptr) {
reply->writeNoException();
}
return NO_ERROR;
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index be3bbf7..17e098c 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -37,14 +37,14 @@
sp<IServiceManager> defaultServiceManager()
{
- if (gDefaultServiceManager != NULL) return gDefaultServiceManager;
+ if (gDefaultServiceManager != nullptr) return gDefaultServiceManager;
{
AutoMutex _l(gDefaultServiceManagerLock);
- while (gDefaultServiceManager == NULL) {
+ while (gDefaultServiceManager == nullptr) {
gDefaultServiceManager = interface_cast<IServiceManager>(
- ProcessState::self()->getContextObject(NULL));
- if (gDefaultServiceManager == NULL)
+ ProcessState::self()->getContextObject(nullptr));
+ if (gDefaultServiceManager == nullptr)
sleep(1);
}
}
@@ -57,7 +57,7 @@
bool checkCallingPermission(const String16& permission)
{
- return checkCallingPermission(permission, NULL, NULL);
+ return checkCallingPermission(permission, nullptr, nullptr);
}
static String16 _permission("permission");
@@ -83,7 +83,7 @@
int64_t startTime = 0;
while (true) {
- if (pc != NULL) {
+ if (pc != nullptr) {
bool res = pc->checkPermission(permission, pid, uid);
if (res) {
if (startTime != 0) {
@@ -104,14 +104,14 @@
// Object is dead!
gDefaultServiceManagerLock.lock();
if (gPermissionController == pc) {
- gPermissionController = NULL;
+ gPermissionController = nullptr;
}
gDefaultServiceManagerLock.unlock();
}
// Need to retrieve the permission controller.
sp<IBinder> binder = defaultServiceManager()->checkService(_permission);
- if (binder == NULL) {
+ if (binder == nullptr) {
// Wait for the permission controller to come back...
if (startTime == 0) {
startTime = uptimeMillis();
@@ -144,7 +144,7 @@
virtual sp<IBinder> getService(const String16& name) const
{
sp<IBinder> svc = checkService(name);
- if (svc != NULL) return svc;
+ if (svc != nullptr) return svc;
const bool isVendorService =
strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0;
@@ -169,10 +169,10 @@
usleep(1000*sleepTime);
sp<IBinder> svc = checkService(name);
- if (svc != NULL) return svc;
+ if (svc != nullptr) return svc;
}
ALOGW("Service %s didn't start. Returning NULL", String8(name).string());
- return NULL;
+ return nullptr;
}
virtual sp<IBinder> checkService( const String16& name) const
diff --git a/libs/binder/IShellCallback.cpp b/libs/binder/IShellCallback.cpp
index 23b83a6..dd4a65e 100644
--- a/libs/binder/IShellCallback.cpp
+++ b/libs/binder/IShellCallback.cpp
@@ -68,7 +68,7 @@
String16 seLinuxContext(data.readString16());
String16 mode(data.readString16());
int fd = openFile(path, seLinuxContext, mode);
- if (reply != NULL) {
+ if (reply != nullptr) {
reply->writeNoException();
if (fd >= 0) {
reply->writeInt32(1);
diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp
index 1cfe02a..eacad3b 100644
--- a/libs/binder/MemoryDealer.cpp
+++ b/libs/binder/MemoryDealer.cpp
@@ -52,8 +52,8 @@
NODE* mLast;
public:
- LinkedList() : mFirst(0), mLast(0) { }
- bool isEmpty() const { return mFirst == 0; }
+ LinkedList() : mFirst(nullptr), mLast(nullptr) { }
+ bool isEmpty() const { return mFirst == nullptr; }
NODE const* head() const { return mFirst; }
NODE* head() { return mFirst; }
NODE const* tail() const { return mLast; }
@@ -62,7 +62,7 @@
void insertAfter(NODE* node, NODE* newNode) {
newNode->prev = node;
newNode->next = node->next;
- if (node->next == 0) mLast = newNode;
+ if (node->next == nullptr) mLast = newNode;
else node->next->prev = newNode;
node->next = newNode;
}
@@ -70,17 +70,17 @@
void insertBefore(NODE* node, NODE* newNode) {
newNode->prev = node->prev;
newNode->next = node;
- if (node->prev == 0) mFirst = newNode;
+ if (node->prev == nullptr) mFirst = newNode;
else node->prev->next = newNode;
node->prev = newNode;
}
void insertHead(NODE* newNode) {
- if (mFirst == 0) {
+ if (mFirst == nullptr) {
mFirst = mLast = newNode;
- newNode->prev = newNode->next = 0;
+ newNode->prev = newNode->next = nullptr;
} else {
- newNode->prev = 0;
+ newNode->prev = nullptr;
newNode->next = mFirst;
mFirst->prev = newNode;
mFirst = newNode;
@@ -99,9 +99,9 @@
}
NODE* remove(NODE* node) {
- if (node->prev == 0) mFirst = node->next;
+ if (node->prev == nullptr) mFirst = node->next;
else node->prev->next = node->next;
- if (node->next == 0) mLast = node->prev;
+ if (node->next == nullptr) mLast = node->prev;
else node->next->prev = node->prev;
return node;
}
@@ -141,7 +141,7 @@
struct chunk_t {
chunk_t(size_t start, size_t size)
- : start(start), size(size), free(1), prev(0), next(0) {
+ : start(start), size(size), free(1), prev(nullptr), next(nullptr) {
}
size_t start;
size_t size : 28;
@@ -329,7 +329,7 @@
return 0;
}
size = (size + kMemoryAlign-1) / kMemoryAlign;
- chunk_t* free_chunk = 0;
+ chunk_t* free_chunk = nullptr;
chunk_t* cur = mList.head();
size_t pagesize = getpagesize();
@@ -418,7 +418,7 @@
}
cur = cur->next;
}
- return 0;
+ return nullptr;
}
void SimpleBestFitAllocator::dump(const char* what) const
diff --git a/libs/binder/MemoryHeapBase.cpp b/libs/binder/MemoryHeapBase.cpp
index 03f00be..9850ad9 100644
--- a/libs/binder/MemoryHeapBase.cpp
+++ b/libs/binder/MemoryHeapBase.cpp
@@ -36,17 +36,17 @@
MemoryHeapBase::MemoryHeapBase()
: mFD(-1), mSize(0), mBase(MAP_FAILED),
- mDevice(NULL), mNeedUnmap(false), mOffset(0)
+ mDevice(nullptr), mNeedUnmap(false), mOffset(0)
{
}
MemoryHeapBase::MemoryHeapBase(size_t size, uint32_t flags, char const * name)
: mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags),
- mDevice(0), mNeedUnmap(false), mOffset(0)
+ mDevice(nullptr), mNeedUnmap(false), mOffset(0)
{
const size_t pagesize = getpagesize();
size = ((size + pagesize-1) & ~(pagesize-1));
- int fd = ashmem_create_region(name == NULL ? "MemoryHeapBase" : name, size);
+ int fd = ashmem_create_region(name == nullptr ? "MemoryHeapBase" : name, size);
ALOGE_IF(fd<0, "error creating ashmem region: %s", strerror(errno));
if (fd >= 0) {
if (mapfd(fd, size) == NO_ERROR) {
@@ -59,7 +59,7 @@
MemoryHeapBase::MemoryHeapBase(const char* device, size_t size, uint32_t flags)
: mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags),
- mDevice(0), mNeedUnmap(false), mOffset(0)
+ mDevice(nullptr), mNeedUnmap(false), mOffset(0)
{
int open_flags = O_RDWR;
if (flags & NO_CACHING)
@@ -78,7 +78,7 @@
MemoryHeapBase::MemoryHeapBase(int fd, size_t size, uint32_t flags, uint32_t offset)
: mFD(-1), mSize(0), mBase(MAP_FAILED), mFlags(flags),
- mDevice(0), mNeedUnmap(false), mOffset(0)
+ mDevice(nullptr), mNeedUnmap(false), mOffset(0)
{
const size_t pagesize = getpagesize();
size = ((size + pagesize-1) & ~(pagesize-1));
@@ -109,7 +109,7 @@
}
if ((mFlags & DONT_MAP_LOCALLY) == 0) {
- void* base = (uint8_t*)mmap(0, size,
+ void* base = (uint8_t*)mmap(nullptr, size,
PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset);
if (base == MAP_FAILED) {
ALOGE("mmap(fd=%d, size=%u) failed (%s)",
@@ -121,7 +121,7 @@
mBase = base;
mNeedUnmap = true;
} else {
- mBase = 0; // not MAP_FAILED
+ mBase = nullptr; // not MAP_FAILED
mNeedUnmap = false;
}
mFD = fd;
@@ -143,7 +143,7 @@
//ALOGD("munmap(fd=%d, base=%p, size=%lu)", fd, mBase, mSize);
munmap(mBase, mSize);
}
- mBase = 0;
+ mBase = nullptr;
mSize = 0;
close(fd);
}
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp
index 2e7edd7..9f08f23 100644
--- a/libs/binder/Parcel.cpp
+++ b/libs/binder/Parcel.cpp
@@ -117,7 +117,7 @@
return;
case BINDER_TYPE_HANDLE: {
const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
- if (b != NULL) {
+ if (b != nullptr) {
LOG_REFS("Parcel %p acquiring reference on remote %p", who, b.get());
b->incStrong(who);
}
@@ -125,11 +125,11 @@
}
case BINDER_TYPE_WEAK_HANDLE: {
const wp<IBinder> b = proc->getWeakProxyForHandle(obj.handle);
- if (b != NULL) b.get_refs()->incWeak(who);
+ if (b != nullptr) b.get_refs()->incWeak(who);
return;
}
case BINDER_TYPE_FD: {
- if ((obj.cookie != 0) && (outAshmemSize != NULL) && ashmem_valid(obj.handle)) {
+ if ((obj.cookie != 0) && (outAshmemSize != nullptr) && ashmem_valid(obj.handle)) {
// If we own an ashmem fd, keep track of how much memory it refers to.
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
@@ -146,7 +146,7 @@
void acquire_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who)
{
- acquire_object(proc, obj, who, NULL);
+ acquire_object(proc, obj, who, nullptr);
}
static void release_object(const sp<ProcessState>& proc,
@@ -165,7 +165,7 @@
return;
case BINDER_TYPE_HANDLE: {
const sp<IBinder> b = proc->getStrongProxyForHandle(obj.handle);
- if (b != NULL) {
+ if (b != nullptr) {
LOG_REFS("Parcel %p releasing reference on remote %p", who, b.get());
b->decStrong(who);
}
@@ -173,12 +173,12 @@
}
case BINDER_TYPE_WEAK_HANDLE: {
const wp<IBinder> b = proc->getWeakProxyForHandle(obj.handle);
- if (b != NULL) b.get_refs()->decWeak(who);
+ if (b != nullptr) b.get_refs()->decWeak(who);
return;
}
case BINDER_TYPE_FD: {
if (obj.cookie != 0) { // owned
- if ((outAshmemSize != NULL) && ashmem_valid(obj.handle)) {
+ if ((outAshmemSize != nullptr) && ashmem_valid(obj.handle)) {
int size = ashmem_get_size_region(obj.handle);
if (size > 0) {
*outAshmemSize -= size;
@@ -197,7 +197,7 @@
void release_object(const sp<ProcessState>& proc,
const flat_binder_object& obj, const void* who)
{
- release_object(proc, obj, who, NULL);
+ release_object(proc, obj, who, nullptr);
}
inline static status_t finish_flatten_binder(
@@ -219,11 +219,11 @@
obj.flags = 0x13 | FLAT_BINDER_FLAG_ACCEPTS_FDS;
}
- if (binder != NULL) {
+ if (binder != nullptr) {
IBinder *local = binder->localBinder();
if (!local) {
BpBinder *proxy = binder->remoteBinder();
- if (proxy == NULL) {
+ if (proxy == nullptr) {
ALOGE("null proxy");
}
const int32_t handle = proxy ? proxy->handle() : 0;
@@ -251,13 +251,13 @@
flat_binder_object obj;
obj.flags = 0x7f | FLAT_BINDER_FLAG_ACCEPTS_FDS;
- if (binder != NULL) {
+ if (binder != nullptr) {
sp<IBinder> real = binder.promote();
- if (real != NULL) {
+ if (real != nullptr) {
IBinder *local = real->localBinder();
if (!local) {
BpBinder *proxy = real->remoteBinder();
- if (proxy == NULL) {
+ if (proxy == nullptr) {
ALOGE("null proxy");
}
const int32_t handle = proxy ? proxy->handle() : 0;
@@ -284,13 +284,13 @@
obj.hdr.type = BINDER_TYPE_BINDER;
obj.binder = 0;
obj.cookie = 0;
- return finish_flatten_binder(NULL, obj, out);
+ return finish_flatten_binder(nullptr, obj, out);
} else {
obj.hdr.type = BINDER_TYPE_BINDER;
obj.binder = 0;
obj.cookie = 0;
- return finish_flatten_binder(NULL, obj, out);
+ return finish_flatten_binder(nullptr, obj, out);
}
}
@@ -310,7 +310,7 @@
switch (flat->hdr.type) {
case BINDER_TYPE_BINDER:
*out = reinterpret_cast<IBinder*>(flat->cookie);
- return finish_unflatten_binder(NULL, *flat, in);
+ return finish_unflatten_binder(nullptr, *flat, in);
case BINDER_TYPE_HANDLE:
*out = proc->getStrongProxyForHandle(flat->handle);
return finish_unflatten_binder(
@@ -329,16 +329,16 @@
switch (flat->hdr.type) {
case BINDER_TYPE_BINDER:
*out = reinterpret_cast<IBinder*>(flat->cookie);
- return finish_unflatten_binder(NULL, *flat, in);
+ return finish_unflatten_binder(nullptr, *flat, in);
case BINDER_TYPE_WEAK_BINDER:
if (flat->binder != 0) {
out->set_object_and_refs(
reinterpret_cast<IBinder*>(flat->cookie),
reinterpret_cast<RefBase::weakref_type*>(flat->binder));
} else {
- *out = NULL;
+ *out = nullptr;
}
- return finish_unflatten_binder(NULL, *flat, in);
+ return finish_unflatten_binder(nullptr, *flat, in);
case BINDER_TYPE_HANDLE:
case BINDER_TYPE_WEAK_HANDLE:
*out = proc->getWeakProxyForHandle(flat->handle);
@@ -526,7 +526,7 @@
if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
binder_size_t *objects =
(binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
- if (objects == (binder_size_t*)0) {
+ if (objects == (binder_size_t*)nullptr) {
return NO_MEMORY;
}
mObjects = objects;
@@ -614,7 +614,7 @@
IPCThreadState* threadState) const
{
int32_t strictPolicy = readInt32();
- if (threadState == NULL) {
+ if (threadState == nullptr) {
threadState = IPCThreadState::self();
}
if ((threadState->getLastTransactionBinderFlags() &
@@ -722,14 +722,14 @@
if (len > INT32_MAX) {
// don't accept size_t values which may have come from an
// inadvertent conversion from a negative int.
- return NULL;
+ return nullptr;
}
const size_t padded = pad_size(len);
// sanity check for integer overflow
if (mDataPos+padded < mDataPos) {
- return NULL;
+ return nullptr;
}
if ((mDataPos+padded) <= mDataCapacity) {
@@ -760,7 +760,7 @@
status_t err = growData(padded);
if (err == NO_ERROR) goto restart_write;
- return NULL;
+ return nullptr;
}
status_t Parcel::writeUtf8AsUtf16(const std::string& str) {
@@ -1063,7 +1063,7 @@
status_t Parcel::writeString16(const char16_t* str, size_t len)
{
- if (str == NULL) return writeInt32(-1);
+ if (str == nullptr) return writeInt32(-1);
status_t err = writeInt32(len);
if (err == NO_ERROR) {
@@ -1180,6 +1180,19 @@
return writeFileDescriptor(fd, takeOwnership);
}
+status_t Parcel::writeDupParcelFileDescriptor(int fd)
+{
+ int dupFd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+ if (dupFd < 0) {
+ return -errno;
+ }
+ status_t err = writeParcelFileDescriptor(dupFd, true /*takeOwnership*/);
+ if (err != OK) {
+ close(dupFd);
+ }
+ return err;
+}
+
status_t Parcel::writeUniqueFileDescriptor(const base::unique_fd& fd) {
return writeDupFileDescriptor(fd.get());
}
@@ -1221,7 +1234,7 @@
if (result < 0) {
status = result;
} else {
- void* ptr = ::mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ void* ptr = ::mmap(nullptr, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) {
status = -errno;
} else {
@@ -1278,10 +1291,10 @@
// payload
void* const buf = this->writeInplace(len);
- if (buf == NULL)
+ if (buf == nullptr)
return BAD_VALUE;
- int* fds = NULL;
+ int* fds = nullptr;
if (fd_count) {
fds = new (std::nothrow) int[fd_count];
if (fds == nullptr) {
@@ -1337,7 +1350,7 @@
size_t newSize = ((mObjectsSize+2)*3)/2;
if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
- if (objects == NULL) return NO_MEMORY;
+ if (objects == nullptr) return NO_MEMORY;
mObjects = objects;
mObjectsCapacity = newSize;
}
@@ -1383,7 +1396,7 @@
status_t Parcel::writeNullableMap(const std::unique_ptr<binder::Map>& map)
{
- if (map == NULL) {
+ if (map == nullptr) {
return writeInt32(-1);
}
@@ -1555,7 +1568,7 @@
if (len > INT32_MAX) {
// don't accept size_t values which may have come from an
// inadvertent conversion from a negative int.
- return NULL;
+ return nullptr;
}
if ((mDataPos+pad_size(len)) >= mDataPos && (mDataPos+pad_size(len)) <= mDataSize
@@ -1566,7 +1579,7 @@
// Still increment the data position by the expected length
mDataPos += pad_size(len);
ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos);
- return NULL;
+ return nullptr;
}
}
@@ -1575,7 +1588,7 @@
ALOGV("readInplace Setting data pos of %p to %zu", this, mDataPos);
return data;
}
- return NULL;
+ return nullptr;
}
template<class T>
@@ -2025,7 +2038,7 @@
return str;
}
}
- return NULL;
+ return nullptr;
}
String8 Parcel::readString8() const
@@ -2056,7 +2069,7 @@
return OK;
}
const char* str = (const char*)readInplace(size + 1);
- if (str == NULL) {
+ if (str == nullptr) {
return BAD_VALUE;
}
pArg->setTo(str, size);
@@ -2115,12 +2128,12 @@
if (size >= 0 && size < INT32_MAX) {
*outLen = size;
const char16_t* str = (const char16_t*)readInplace((size+1)*sizeof(char16_t));
- if (str != NULL) {
+ if (str != nullptr) {
return str;
}
}
*outLen = 0;
- return NULL;
+ return nullptr;
}
status_t Parcel::readStrongBinder(sp<IBinder>* val) const
@@ -2182,13 +2195,13 @@
int numFds, numInts;
status_t err;
err = readInt32(&numFds);
- if (err != NO_ERROR) return 0;
+ if (err != NO_ERROR) return nullptr;
err = readInt32(&numInts);
- if (err != NO_ERROR) return 0;
+ if (err != NO_ERROR) return nullptr;
native_handle* h = native_handle_create(numFds, numInts);
if (!h) {
- return 0;
+ return nullptr;
}
for (int i=0 ; err==NO_ERROR && i<numFds ; i++) {
@@ -2198,14 +2211,14 @@
close(h->data[j]);
}
native_handle_delete(h);
- return 0;
+ return nullptr;
}
}
err = read(h->data + numFds, sizeof(int)*numInts);
if (err != NO_ERROR) {
native_handle_close(h);
native_handle_delete(h);
- h = 0;
+ h = nullptr;
}
return h;
}
@@ -2249,6 +2262,22 @@
return OK;
}
+status_t Parcel::readUniqueParcelFileDescriptor(base::unique_fd* val) const
+{
+ int got = readParcelFileDescriptor();
+
+ if (got == BAD_TYPE) {
+ return BAD_TYPE;
+ }
+
+ val->reset(fcntl(got, F_DUPFD_CLOEXEC, 0));
+
+ if (val->get() < 0) {
+ return BAD_VALUE;
+ }
+
+ return OK;
+}
status_t Parcel::readUniqueFileDescriptorVector(std::unique_ptr<std::vector<base::unique_fd>>* val) const {
return readNullableTypedVector(val, &Parcel::readUniqueFileDescriptor);
@@ -2278,7 +2307,16 @@
int fd = readFileDescriptor();
if (fd == int(BAD_TYPE)) return BAD_VALUE;
- void* ptr = ::mmap(NULL, len, isMutable ? PROT_READ | PROT_WRITE : PROT_READ,
+ if (!ashmem_valid(fd)) {
+ ALOGE("invalid fd");
+ return BAD_VALUE;
+ }
+ int size = ashmem_get_size_region(fd);
+ if (size < 0 || size_t(size) < len) {
+ ALOGE("request size %zu does not match fd size %d", len, size);
+ return BAD_VALUE;
+ }
+ void* ptr = ::mmap(nullptr, len, isMutable ? PROT_READ | PROT_WRITE : PROT_READ,
MAP_SHARED, fd, 0);
if (ptr == MAP_FAILED) return NO_MEMORY;
@@ -2300,10 +2338,10 @@
// payload
void const* const buf = this->readInplace(pad_size(len));
- if (buf == NULL)
+ if (buf == nullptr)
return BAD_VALUE;
- int* fds = NULL;
+ int* fds = nullptr;
if (fd_count) {
fds = new (std::nothrow) int[fd_count];
if (fds == nullptr) {
@@ -2394,7 +2432,7 @@
ALOGW("Attempt to read object from Parcel %p at offset %zu that is not in the object list",
this, DPOS);
}
- return NULL;
+ return nullptr;
}
void Parcel::closeFileDescriptors()
@@ -2604,7 +2642,7 @@
ALOGV("restartWrite Setting data pos of %p to %zu", this, mDataPos);
free(mObjects);
- mObjects = NULL;
+ mObjects = nullptr;
mObjectsSize = mObjectsCapacity = 0;
mNextObjectHint = 0;
mObjectsSorted = false;
@@ -2652,7 +2690,7 @@
mError = NO_MEMORY;
return NO_MEMORY;
}
- binder_size_t* objects = NULL;
+ binder_size_t* objects = nullptr;
if (objectsSize) {
objects = (binder_size_t*)calloc(objectsSize, sizeof(binder_size_t));
@@ -2679,7 +2717,7 @@
}
//ALOGI("Freeing data ref of %p (pid=%d)", this, getpid());
mOwner(this, mData, mDataSize, mObjects, mObjectsSize, mOwnerCookie);
- mOwner = NULL;
+ mOwner = nullptr;
LOG_ALLOC("Parcel %p: taking ownership of %zu capacity", this, desired);
pthread_mutex_lock(&gParcelGlobalAllocSizeLock);
@@ -2754,7 +2792,7 @@
return NO_MEMORY;
}
- if(!(mDataCapacity == 0 && mObjects == NULL
+ if(!(mDataCapacity == 0 && mObjects == nullptr
&& mObjectsCapacity == 0)) {
ALOGE("continueWrite: %zu/%p/%zu/%zu", mDataCapacity, mObjects, mObjectsCapacity, desired);
}
@@ -2779,13 +2817,13 @@
{
LOG_ALLOC("Parcel %p: initState", this);
mError = NO_ERROR;
- mData = 0;
+ mData = nullptr;
mDataSize = 0;
mDataCapacity = 0;
mDataPos = 0;
ALOGV("initState Setting data size of %p to %zu", this, mDataSize);
ALOGV("initState Setting data pos of %p to %zu", this, mDataPos);
- mObjects = NULL;
+ mObjects = nullptr;
mObjectsSize = 0;
mObjectsCapacity = 0;
mNextObjectHint = 0;
@@ -2793,7 +2831,7 @@
mHasFds = false;
mFdsKnown = true;
mAllowFds = true;
- mOwner = NULL;
+ mOwner = nullptr;
mOpenAshmemSize = 0;
// racing multiple init leads only to multiple identical write
@@ -2840,7 +2878,7 @@
// --- Parcel::Blob ---
Parcel::Blob::Blob() :
- mFd(-1), mData(NULL), mSize(0), mMutable(false) {
+ mFd(-1), mData(nullptr), mSize(0), mMutable(false) {
}
Parcel::Blob::~Blob() {
@@ -2863,7 +2901,7 @@
void Parcel::Blob::clear() {
mFd = -1;
- mData = NULL;
+ mData = nullptr;
mSize = 0;
mMutable = false;
}
diff --git a/libs/binder/ParcelFileDescriptor.cpp b/libs/binder/ParcelFileDescriptor.cpp
new file mode 100644
index 0000000..4f8b76f
--- /dev/null
+++ b/libs/binder/ParcelFileDescriptor.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <binder/ParcelFileDescriptor.h>
+
+namespace android {
+namespace os {
+
+ParcelFileDescriptor::ParcelFileDescriptor() = default;
+
+ParcelFileDescriptor::ParcelFileDescriptor(android::base::unique_fd fd) : mFd(std::move(fd)) {}
+
+ParcelFileDescriptor::~ParcelFileDescriptor() = default;
+
+status_t ParcelFileDescriptor::writeToParcel(Parcel* parcel) const {
+ return parcel->writeDupParcelFileDescriptor(mFd.get());
+}
+
+status_t ParcelFileDescriptor::readFromParcel(const Parcel* parcel) {
+ return parcel->readUniqueParcelFileDescriptor(&mFd);
+}
+
+} // namespace os
+} // namespace android
diff --git a/libs/binder/PermissionCache.cpp b/libs/binder/PermissionCache.cpp
index a503be8..a4c28ad 100644
--- a/libs/binder/PermissionCache.cpp
+++ b/libs/binder/PermissionCache.cpp
@@ -75,7 +75,7 @@
}
bool PermissionCache::checkCallingPermission(const String16& permission) {
- return PermissionCache::checkCallingPermission(permission, NULL, NULL);
+ return PermissionCache::checkCallingPermission(permission, nullptr, nullptr);
}
bool PermissionCache::checkCallingPermission(
diff --git a/libs/binder/PermissionController.cpp b/libs/binder/PermissionController.cpp
index 96df33c..34b2ca5 100644
--- a/libs/binder/PermissionController.cpp
+++ b/libs/binder/PermissionController.cpp
@@ -41,7 +41,7 @@
ALOGI("Waiting for permission service");
} else if ((uptimeMillis() - startTime) > 10000) {
ALOGW("Waiting too long for permission service, giving up");
- service = NULL;
+ service = nullptr;
break;
}
sleep(1);
@@ -56,13 +56,13 @@
bool PermissionController::checkPermission(const String16& permission, int32_t pid, int32_t uid)
{
sp<IPermissionController> service = getService();
- return service != NULL ? service->checkPermission(permission, pid, uid) : false;
+ return service != nullptr ? service->checkPermission(permission, pid, uid) : false;
}
int32_t PermissionController::noteOp(const String16& op, int32_t uid, const String16& packageName)
{
sp<IPermissionController> service = getService();
- return service != NULL ? service->noteOp(op, uid, packageName) : MODE_ERRORED;
+ return service != nullptr ? service->noteOp(op, uid, packageName) : MODE_ERRORED;
}
void PermissionController::getPackagesForUid(const uid_t uid, Vector<String16> &packages)
diff --git a/libs/binder/ProcessInfoService.cpp b/libs/binder/ProcessInfoService.cpp
index 8939d9c..5cb2033 100644
--- a/libs/binder/ProcessInfoService.cpp
+++ b/libs/binder/ProcessInfoService.cpp
@@ -36,7 +36,7 @@
for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) {
- if (pis != NULL) {
+ if (pis != nullptr) {
err = pis->getProcessStatesFromPids(length, /*in*/ pids, /*out*/ states);
if (err == NO_ERROR) return NO_ERROR; // success
if (IInterface::asBinder(pis)->isBinderAlive()) return err;
@@ -68,7 +68,7 @@
for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) {
- if (pis != NULL) {
+ if (pis != nullptr) {
err = pis->getProcessStatesAndOomScoresFromPids(length,
/*in*/ pids, /*out*/ states, /*out*/ scores);
if (err == NO_ERROR) return NO_ERROR; // success
@@ -93,7 +93,7 @@
void ProcessInfoService::updateBinderLocked() {
const sp<IServiceManager> sm(defaultServiceManager());
- if (sm != NULL) {
+ if (sm != nullptr) {
const String16 name("processinfo");
mProcessInfoService = interface_cast<IProcessInfoService>(sm->checkService(name));
}
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index d1c6f84..3e871f8 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -68,7 +68,7 @@
sp<ProcessState> ProcessState::self()
{
Mutex::Autolock _l(gProcessMutex);
- if (gProcess != NULL) {
+ if (gProcess != nullptr) {
return gProcess;
}
gProcess = new ProcessState("/dev/binder");
@@ -78,7 +78,7 @@
sp<ProcessState> ProcessState::initWithDriver(const char* driver)
{
Mutex::Autolock _l(gProcessMutex);
- if (gProcess != NULL) {
+ if (gProcess != nullptr) {
// Allow for initWithDriver to be called repeatedly with the same
// driver.
if (!strcmp(gProcess->getDriverName().c_str(), driver)) {
@@ -122,18 +122,18 @@
{
mLock.lock();
sp<IBinder> object(
- mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : NULL);
+ mContexts.indexOfKey(name) >= 0 ? mContexts.valueFor(name) : nullptr);
mLock.unlock();
//printf("Getting context object %s for %p\n", String8(name).string(), caller.get());
- if (object != NULL) return object;
+ if (object != nullptr) return object;
// Don't attempt to retrieve contexts if we manage them
if (mManagesContexts) {
ALOGE("getContextObject(%s) failed, but we manage the contexts!\n",
String8(name).string());
- return NULL;
+ return nullptr;
}
IPCThreadState* ipc = IPCThreadState::self();
@@ -150,7 +150,7 @@
ipc->flushCommands();
- if (object != NULL) setContextObject(object, name);
+ if (object != nullptr) setContextObject(object, name);
return object;
}
@@ -180,8 +180,8 @@
if (result == 0) {
mManagesContexts = true;
} else if (result == -1) {
- mBinderContextCheckFunc = NULL;
- mBinderContextUserData = NULL;
+ mBinderContextCheckFunc = nullptr;
+ mBinderContextUserData = nullptr;
ALOGE("Binder ioctl to become context manager failed: %s\n", strerror(errno));
}
}
@@ -207,7 +207,7 @@
binder_node_debug_info info = {};
- uintptr_t* end = buf ? buf + buf_count : NULL;
+ uintptr_t* end = buf ? buf + buf_count : nullptr;
size_t count = 0;
do {
@@ -233,10 +233,10 @@
const size_t N=mHandleToObject.size();
if (N <= (size_t)handle) {
handle_entry e;
- e.binder = NULL;
- e.refs = NULL;
+ e.binder = nullptr;
+ e.refs = nullptr;
status_t err = mHandleToObject.insertAt(e, N, handle+1-N);
- if (err < NO_ERROR) return NULL;
+ if (err < NO_ERROR) return nullptr;
}
return &mHandleToObject.editItemAt(handle);
}
@@ -249,12 +249,12 @@
handle_entry* e = lookupHandleLocked(handle);
- if (e != NULL) {
+ if (e != nullptr) {
// We need to create a new BpBinder if there isn't currently one, OR we
// are unable to acquire a weak reference on this current one. See comment
// in getWeakProxyForHandle() for more info about this.
IBinder* b = e->binder;
- if (b == NULL || !e->refs->attemptIncWeak(this)) {
+ if (b == nullptr || !e->refs->attemptIncWeak(this)) {
if (handle == 0) {
// Special case for context manager...
// The context manager is the only object for which we create
@@ -277,9 +277,9 @@
Parcel data;
status_t status = IPCThreadState::self()->transact(
- 0, IBinder::PING_TRANSACTION, data, NULL, 0);
+ 0, IBinder::PING_TRANSACTION, data, nullptr, 0);
if (status == DEAD_OBJECT)
- return NULL;
+ return nullptr;
}
b = BpBinder::create(handle);
@@ -306,7 +306,7 @@
handle_entry* e = lookupHandleLocked(handle);
- if (e != NULL) {
+ if (e != nullptr) {
// We need to create a new BpBinder if there isn't currently one, OR we
// are unable to acquire a weak reference on this current one. The
// attemptIncWeak() is safe because we know the BpBinder destructor will always
@@ -315,7 +315,7 @@
// releasing a reference on this BpBinder, and a new reference on its handle
// arriving from the driver.
IBinder* b = e->binder;
- if (b == NULL || !e->refs->attemptIncWeak(this)) {
+ if (b == nullptr || !e->refs->attemptIncWeak(this)) {
b = BpBinder::create(handle);
result = b;
e->binder = b;
@@ -338,7 +338,7 @@
// This handle may have already been replaced with a new BpBinder
// (if someone failed the AttemptIncWeak() above); we don't want
// to overwrite it.
- if (e && e->binder == binder) e->binder = NULL;
+ if (e && e->binder == binder) e->binder = nullptr;
}
String8 ProcessState::makeBinderThreadName() {
@@ -416,14 +416,14 @@
, mMaxThreads(DEFAULT_MAX_BINDER_THREADS)
, mStarvationStartTimeMs(0)
, mManagesContexts(false)
- , mBinderContextCheckFunc(NULL)
- , mBinderContextUserData(NULL)
+ , mBinderContextCheckFunc(nullptr)
+ , mBinderContextUserData(nullptr)
, mThreadPoolStarted(false)
, mThreadPoolSeq(1)
{
if (mDriverFD >= 0) {
// mmap the binder, providing a chunk of virtual address space to receive transactions.
- mVMStart = mmap(0, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
+ mVMStart = mmap(nullptr, BINDER_VM_SIZE, PROT_READ, MAP_PRIVATE | MAP_NORESERVE, mDriverFD, 0);
if (mVMStart == MAP_FAILED) {
// *sigh*
ALOGE("Using %s failed: unable to mmap transaction memory.\n", mDriverName.c_str());
diff --git a/libs/binder/Static.cpp b/libs/binder/Static.cpp
index df0fcae..bd0e6f9 100644
--- a/libs/binder/Static.cpp
+++ b/libs/binder/Static.cpp
@@ -72,7 +72,7 @@
// ------------ ProcessState.cpp
-Mutex gProcessMutex;
+Mutex& gProcessMutex = *new Mutex;
sp<ProcessState> gProcess;
// ------------ IServiceManager.cpp
diff --git a/libs/binder/Value.cpp b/libs/binder/Value.cpp
index 85cd739..2b263ed 100644
--- a/libs/binder/Value.cpp
+++ b/libs/binder/Value.cpp
@@ -143,12 +143,12 @@
// ====================================================================
-Value::Value() : mContent(NULL)
+Value::Value() : mContent(nullptr)
{
}
Value::Value(const Value& value)
- : mContent(value.mContent ? value.mContent->clone() : NULL)
+ : mContent(value.mContent ? value.mContent->clone() : nullptr)
{
}
@@ -165,8 +165,8 @@
return true;
}
- if ( (lhs.mContent == NULL)
- || (rhs.mContent == NULL)
+ if ( (lhs.mContent == nullptr)
+ || (rhs.mContent == nullptr)
) {
return false;
}
@@ -186,25 +186,25 @@
delete mContent;
mContent = rhs.mContent
? rhs.mContent->clone()
- : NULL;
+ : nullptr;
}
return *this;
}
bool Value::empty() const
{
- return mContent == NULL;
+ return mContent == nullptr;
}
void Value::clear()
{
delete mContent;
- mContent = NULL;
+ mContent = nullptr;
}
int32_t Value::parcelType() const
{
- const void* t_info(mContent ? mContent->type_ptr() : NULL);
+ const void* t_info(mContent ? mContent->type_ptr() : nullptr);
if (t_info == internal_type_ptr<bool>()) return VAL_BOOLEAN;
if (t_info == internal_type_ptr<uint8_t>()) return VAL_BYTE;
@@ -381,7 +381,7 @@
int32_t value_type = VAL_NULL;
delete mContent;
- mContent = NULL;
+ mContent = nullptr;
RETURN_IF_FAILED(parcel->readInt32(&value_type));
diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h
index dede78f..c5fede6 100644
--- a/libs/binder/include/binder/Parcel.h
+++ b/libs/binder/include/binder/Parcel.h
@@ -205,6 +205,10 @@
// The Parcel does not take ownership of the given fd unless you ask it to.
status_t writeParcelFileDescriptor(int fd, bool takeOwnership = false);
+ // Place a Java "parcel file descriptor" into the parcel. A dup of the fd is made, which will
+ // be closed once the parcel is destroyed.
+ status_t writeDupParcelFileDescriptor(int fd);
+
// Place a file descriptor into the parcel. This will not affect the
// semantics of the smart file descriptor. A new descriptor will be
// created, and will be closed when the parcel is destroyed.
@@ -364,6 +368,9 @@
status_t readUniqueFileDescriptor(
base::unique_fd* val) const;
+ // Retrieve a Java "parcel file descriptor" from the parcel.
+ status_t readUniqueParcelFileDescriptor(base::unique_fd* val) const;
+
// Retrieve a vector of smart file descriptors from the parcel.
status_t readUniqueFileDescriptorVector(
diff --git a/libs/binder/include/binder/ParcelFileDescriptor.h b/libs/binder/include/binder/ParcelFileDescriptor.h
new file mode 100644
index 0000000..455462b
--- /dev/null
+++ b/libs/binder/include/binder/ParcelFileDescriptor.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_PARCEL_FILE_DESCRIPTOR_H_
+#define ANDROID_PARCEL_FILE_DESCRIPTOR_H_
+
+#include <android-base/unique_fd.h>
+#include <binder/Parcel.h>
+#include <binder/Parcelable.h>
+
+namespace android {
+namespace os {
+
+/*
+ * C++ implementation of the Java class android.os.ParcelFileDescriptor
+ */
+class ParcelFileDescriptor : public android::Parcelable {
+public:
+ ParcelFileDescriptor();
+ explicit ParcelFileDescriptor(android::base::unique_fd fd);
+ ~ParcelFileDescriptor() override;
+
+ int get() const { return mFd.get(); }
+ android::base::unique_fd release() { return std::move(mFd); }
+ void reset(android::base::unique_fd fd = android::base::unique_fd()) { mFd = std::move(fd); }
+
+ // android::Parcelable override:
+ android::status_t writeToParcel(android::Parcel* parcel) const override;
+ android::status_t readFromParcel(const android::Parcel* parcel) override;
+
+private:
+ android::base::unique_fd mFd;
+};
+
+} // namespace os
+} // namespace android
+
+#endif // ANDROID_OS_PARCEL_FILE_DESCRIPTOR_H_
diff --git a/libs/binder/include/private/binder/Static.h b/libs/binder/include/private/binder/Static.h
index 6ca7592..171be77 100644
--- a/libs/binder/include/private/binder/Static.h
+++ b/libs/binder/include/private/binder/Static.h
@@ -32,7 +32,7 @@
extern Vector<int32_t> gTextBuffers;
// For ProcessState.cpp
-extern Mutex gProcessMutex;
+extern Mutex& gProcessMutex;
extern sp<ProcessState> gProcess;
// For IServiceManager.cpp
diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp
index 4f00bc1..77ebac8 100644
--- a/libs/binder/tests/binderDriverInterfaceTest.cpp
+++ b/libs/binder/tests/binderDriverInterfaceTest.cpp
@@ -36,8 +36,8 @@
m_binderFd = open(BINDER_DEV_NAME, O_RDWR | O_NONBLOCK | O_CLOEXEC);
ASSERT_GE(m_binderFd, 0);
- m_buffer = mmap(NULL, 64*1024, PROT_READ, MAP_SHARED, m_binderFd, 0);
- ASSERT_NE(m_buffer, (void *)NULL);
+ m_buffer = mmap(nullptr, 64*1024, PROT_READ, MAP_SHARED, m_binderFd, 0);
+ ASSERT_NE(m_buffer, (void *)nullptr);
ret = ioctl(m_binderFd, BINDER_SET_MAX_THREADS, &max_threads);
EXPECT_EQ(0, ret);
EnterLooper();
@@ -156,23 +156,23 @@
}
TEST_F(BinderDriverInterfaceTest, WriteReadNull) {
- binderTestIoctlErr1(BINDER_WRITE_READ, NULL, EFAULT);
+ binderTestIoctlErr1(BINDER_WRITE_READ, nullptr, EFAULT);
}
TEST_F(BinderDriverInterfaceTest, SetIdleTimeoutNull) {
- binderTestIoctlErr2(BINDER_SET_IDLE_TIMEOUT, NULL, EFAULT, EINVAL);
+ binderTestIoctlErr2(BINDER_SET_IDLE_TIMEOUT, nullptr, EFAULT, EINVAL);
}
TEST_F(BinderDriverInterfaceTest, SetMaxThreadsNull) {
- binderTestIoctlErr2(BINDER_SET_MAX_THREADS, NULL, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
+ binderTestIoctlErr2(BINDER_SET_MAX_THREADS, nullptr, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
}
TEST_F(BinderDriverInterfaceTest, SetIdlePriorityNull) {
- binderTestIoctlErr2(BINDER_SET_IDLE_PRIORITY, NULL, EFAULT, EINVAL);
+ binderTestIoctlErr2(BINDER_SET_IDLE_PRIORITY, nullptr, EFAULT, EINVAL);
}
TEST_F(BinderDriverInterfaceTest, VersionNull) {
- binderTestIoctlErr2(BINDER_VERSION, NULL, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
+ binderTestIoctlErr2(BINDER_VERSION, nullptr, EFAULT, EINVAL); /* TODO: don't accept EINVAL */
}
TEST_F(BinderDriverInterfaceTest, SetIdleTimeoutNoTest) {
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 1611e11..f23ac52 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -65,6 +65,7 @@
BINDER_LIB_TEST_ADD_STRONG_REF_TRANSACTION,
BINDER_LIB_TEST_LINK_DEATH_TRANSACTION,
BINDER_LIB_TEST_WRITE_FILE_TRANSACTION,
+ BINDER_LIB_TEST_WRITE_PARCEL_FILE_DESCRIPTOR_TRANSACTION,
BINDER_LIB_TEST_PROMOTE_WEAK_REF_TRANSACTION,
BINDER_LIB_TEST_EXIT_TRANSACTION,
BINDER_LIB_TEST_DELAYED_EXIT_TRANSACTION,
@@ -88,7 +89,7 @@
strpipefd1,
usepoll,
binderserversuffix,
- NULL
+ nullptr
};
ret = pipe(pipefd);
@@ -123,7 +124,7 @@
}
}
if (ret < 0) {
- wait(NULL);
+ wait(nullptr);
return ret;
}
return pid;
@@ -145,7 +146,7 @@
sp<IServiceManager> sm = defaultServiceManager();
//printf("%s: pid %d, get service\n", __func__, m_pid);
m_server = sm->getService(binderLibTestServiceName);
- ASSERT_TRUE(m_server != NULL);
+ ASSERT_TRUE(m_server != nullptr);
//printf("%s: pid %d, get service done\n", __func__, m_pid);
}
virtual void TearDown() {
@@ -155,7 +156,7 @@
pid_t pid;
//printf("%s: pid %d\n", __func__, m_pid);
- if (m_server != NULL) {
+ if (m_server != nullptr) {
ret = m_server->transact(BINDER_LIB_TEST_GET_STATUS_TRANSACTION, data, &reply);
EXPECT_EQ(0, ret);
ret = m_server->transact(BINDER_LIB_TEST_EXIT_TRANSACTION, data, &reply, TF_ONE_WAY);
@@ -192,9 +193,9 @@
ret = m_server->transact(code, data, &reply);
EXPECT_EQ(NO_ERROR, ret);
- EXPECT_FALSE(binder != NULL);
+ EXPECT_FALSE(binder != nullptr);
binder = reply.readStrongBinder();
- EXPECT_TRUE(binder != NULL);
+ EXPECT_TRUE(binder != nullptr);
ret = reply.readInt32(&id);
EXPECT_EQ(NO_ERROR, ret);
if (idPtr)
@@ -202,12 +203,12 @@
return binder;
}
- sp<IBinder> addServer(int32_t *idPtr = NULL)
+ sp<IBinder> addServer(int32_t *idPtr = nullptr)
{
return addServerEtc(idPtr, BINDER_LIB_TEST_ADD_SERVER);
}
- sp<IBinder> addPollServer(int32_t *idPtr = NULL)
+ sp<IBinder> addPollServer(int32_t *idPtr = nullptr)
{
return addServerEtc(idPtr, BINDER_LIB_TEST_ADD_POLL_SERVER);
}
@@ -274,8 +275,8 @@
BinderLibTestEvent(void)
: m_eventTriggered(false)
{
- pthread_mutex_init(&m_waitMutex, NULL);
- pthread_cond_init(&m_waitCond, NULL);
+ pthread_mutex_init(&m_waitMutex, nullptr);
+ pthread_cond_init(&m_waitCond, nullptr);
}
int waitEvent(int timeout_s)
{
@@ -315,7 +316,7 @@
public:
BinderLibTestCallBack()
: m_result(NOT_ENOUGH_DATA)
- , m_prev_end(NULL)
+ , m_prev_end(nullptr)
{
}
status_t getResult(void)
@@ -413,7 +414,7 @@
int32_t ptrsize;
Parcel data, reply;
sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
+ ASSERT_TRUE(server != nullptr);
ret = server->transact(BINDER_LIB_TEST_GET_PTR_SIZE_TRANSACTION, data, &reply);
EXPECT_EQ(NO_ERROR, ret);
ret = reply.readInt32(&ptrsize);
@@ -436,7 +437,7 @@
BinderLibTestBundle datai;
server = addServer(&serverId[i]);
- ASSERT_TRUE(server != NULL);
+ ASSERT_TRUE(server != nullptr);
data.writeStrongBinder(server);
data.writeInt32(BINDER_LIB_TEST_GET_ID_TRANSACTION);
datai.appendTo(&data);
@@ -480,7 +481,7 @@
BinderLibTestBundle datai2;
server = addServer(&serverId[i]);
- ASSERT_TRUE(server != NULL);
+ ASSERT_TRUE(server != nullptr);
data.writeStrongBinder(server);
data.writeInt32(BINDER_LIB_TEST_INDIRECT_TRANSACTION);
@@ -546,7 +547,7 @@
TEST_F(BinderLibTest, AddServer)
{
sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
+ ASSERT_TRUE(server != nullptr);
}
TEST_F(BinderLibTest, DeathNotificationNoRefs)
@@ -557,7 +558,7 @@
{
sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != NULL);
+ ASSERT_TRUE(binder != nullptr);
ret = binder->linkToDeath(testDeathRecipient);
EXPECT_EQ(NO_ERROR, ret);
}
@@ -579,7 +580,7 @@
{
sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != NULL);
+ ASSERT_TRUE(binder != nullptr);
ret = binder->linkToDeath(testDeathRecipient);
EXPECT_EQ(NO_ERROR, ret);
wbinder = binder;
@@ -602,7 +603,7 @@
{
sp<IBinder> binder = addServer();
- ASSERT_TRUE(binder != NULL);
+ ASSERT_TRUE(binder != nullptr);
ret = binder->linkToDeath(testDeathRecipient);
EXPECT_EQ(NO_ERROR, ret);
sbinder = binder;
@@ -629,13 +630,13 @@
sp<IBinder> passiveclient[clientcount];
target = addServer();
- ASSERT_TRUE(target != NULL);
+ ASSERT_TRUE(target != nullptr);
for (int i = 0; i < clientcount; i++) {
{
Parcel data, reply;
linkedclient[i] = addServer();
- ASSERT_TRUE(linkedclient[i] != NULL);
+ ASSERT_TRUE(linkedclient[i] != nullptr);
callBack[i] = new BinderLibTestCallBack();
data.writeStrongBinder(target);
data.writeStrongBinder(callBack[i]);
@@ -646,7 +647,7 @@
Parcel data, reply;
passiveclient[i] = addServer();
- ASSERT_TRUE(passiveclient[i] != NULL);
+ ASSERT_TRUE(passiveclient[i] != nullptr);
data.writeStrongBinder(target);
ret = passiveclient[i]->transact(BINDER_LIB_TEST_ADD_STRONG_REF_TRANSACTION, data, &reply, TF_ONE_WAY);
EXPECT_EQ(NO_ERROR, ret);
@@ -671,9 +672,9 @@
status_t ret;
sp<BinderLibTestCallBack> callback;
sp<IBinder> target = addServer();
- ASSERT_TRUE(target != NULL);
+ ASSERT_TRUE(target != nullptr);
sp<IBinder> client = addServer();
- ASSERT_TRUE(client != NULL);
+ ASSERT_TRUE(client != nullptr);
sp<TestDeathRecipient> testDeathRecipient = new TestDeathRecipient();
@@ -763,16 +764,51 @@
close(pipefd[0]);
}
+TEST_F(BinderLibTest, PassParcelFileDescriptor) {
+ const int datasize = 123;
+ std::vector<uint8_t> writebuf(datasize);
+ for (size_t i = 0; i < writebuf.size(); ++i) {
+ writebuf[i] = i;
+ }
+
+ android::base::unique_fd read_end, write_end;
+ {
+ int pipefd[2];
+ ASSERT_EQ(0, pipe2(pipefd, O_NONBLOCK));
+ read_end.reset(pipefd[0]);
+ write_end.reset(pipefd[1]);
+ }
+ {
+ Parcel data;
+ EXPECT_EQ(NO_ERROR, data.writeDupParcelFileDescriptor(write_end.get()));
+ write_end.reset();
+ EXPECT_EQ(NO_ERROR, data.writeInt32(datasize));
+ EXPECT_EQ(NO_ERROR, data.write(writebuf.data(), datasize));
+
+ Parcel reply;
+ EXPECT_EQ(NO_ERROR,
+ m_server->transact(BINDER_LIB_TEST_WRITE_PARCEL_FILE_DESCRIPTOR_TRANSACTION, data,
+ &reply));
+ }
+ std::vector<uint8_t> readbuf(datasize);
+ EXPECT_EQ(datasize, read(read_end.get(), readbuf.data(), datasize));
+ EXPECT_EQ(writebuf, readbuf);
+
+ waitForReadData(read_end.get(), 5000); /* wait for other proccess to close pipe */
+
+ EXPECT_EQ(0, read(read_end.get(), readbuf.data(), datasize));
+}
+
TEST_F(BinderLibTest, PromoteLocal) {
sp<IBinder> strong = new BBinder();
wp<IBinder> weak = strong;
sp<IBinder> strong_from_weak = weak.promote();
- EXPECT_TRUE(strong != NULL);
+ EXPECT_TRUE(strong != nullptr);
EXPECT_EQ(strong, strong_from_weak);
- strong = NULL;
- strong_from_weak = NULL;
+ strong = nullptr;
+ strong_from_weak = nullptr;
strong_from_weak = weak.promote();
- EXPECT_TRUE(strong_from_weak == NULL);
+ EXPECT_TRUE(strong_from_weak == nullptr);
}
TEST_F(BinderLibTest, PromoteRemote) {
@@ -781,8 +817,8 @@
sp<IBinder> strong = new BBinder();
sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
- ASSERT_TRUE(strong != NULL);
+ ASSERT_TRUE(server != nullptr);
+ ASSERT_TRUE(strong != nullptr);
ret = data.writeWeakBinder(strong);
EXPECT_EQ(NO_ERROR, ret);
@@ -799,7 +835,7 @@
EXPECT_EQ(NO_ERROR, ret);
const flat_binder_object *fb = reply.readObject(false);
- ASSERT_TRUE(fb != NULL);
+ ASSERT_TRUE(fb != nullptr);
EXPECT_EQ(BINDER_TYPE_HANDLE, fb->hdr.type);
EXPECT_EQ(m_server, ProcessState::self()->getStrongProxyForHandle(fb->handle));
EXPECT_EQ((binder_uintptr_t)0, fb->cookie);
@@ -810,7 +846,7 @@
status_t ret;
sp<IBinder> server = addServer();
- ASSERT_TRUE(server != NULL);
+ ASSERT_TRUE(server != nullptr);
__u32 freedHandle;
wp<IBinder> keepFreedBinder;
@@ -881,12 +917,12 @@
data2.writeStrongBinder(callBack2);
data2.writeInt32(0); // delay in us
- ret = pollServer->transact(BINDER_LIB_TEST_DELAYED_CALL_BACK, data, NULL, TF_ONE_WAY);
+ ret = pollServer->transact(BINDER_LIB_TEST_DELAYED_CALL_BACK, data, nullptr, TF_ONE_WAY);
EXPECT_EQ(NO_ERROR, ret);
// The delay ensures that this second transaction will end up on the async_todo list
// (for a single-threaded server)
- ret = pollServer->transact(BINDER_LIB_TEST_DELAYED_CALL_BACK, data2, NULL, TF_ONE_WAY);
+ ret = pollServer->transact(BINDER_LIB_TEST_DELAYED_CALL_BACK, data2, nullptr, TF_ONE_WAY);
EXPECT_EQ(NO_ERROR, ret);
// The server will ensure that the two transactions are handled in the expected order;
@@ -909,10 +945,10 @@
: m_id(id)
, m_nextServerId(id + 1)
, m_serverStartRequested(false)
- , m_callback(NULL)
+ , m_callback(nullptr)
{
- pthread_mutex_init(&m_serverWaitMutex, NULL);
- pthread_cond_init(&m_serverWaitCond, NULL);
+ pthread_mutex_init(&m_serverWaitMutex, nullptr);
+ pthread_cond_init(&m_serverWaitCond, nullptr);
}
~BinderLibTestService()
{
@@ -920,11 +956,11 @@
}
void processPendingCall() {
- if (m_callback != NULL) {
+ if (m_callback != nullptr) {
Parcel data;
data.writeInt32(NO_ERROR);
m_callback->transact(BINDER_LIB_TEST_CALL_BACK, data, nullptr, TF_ONE_WAY);
- m_callback = NULL;
+ m_callback = nullptr;
}
}
@@ -943,7 +979,7 @@
sp<IBinder> binder;
id = data.readInt32();
binder = data.readStrongBinder();
- if (binder == NULL) {
+ if (binder == nullptr) {
return BAD_VALUE;
}
@@ -993,7 +1029,7 @@
} else {
reply->writeStrongBinder(m_serverStarted);
reply->writeInt32(serverid);
- m_serverStarted = NULL;
+ m_serverStarted = nullptr;
ret = NO_ERROR;
}
} else if (ret >= 0) {
@@ -1008,7 +1044,7 @@
case BINDER_LIB_TEST_DELAYED_CALL_BACK: {
// Note: this transaction is only designed for use with a
// poll() server. See comments around epoll_wait().
- if (m_callback != NULL) {
+ if (m_callback != nullptr) {
// A callback was already pending; this means that
// we received a second call while still processing
// the first one. Fail the test.
@@ -1016,7 +1052,7 @@
Parcel data2;
data2.writeInt32(UNKNOWN_ERROR);
- callback->transact(BINDER_LIB_TEST_CALL_BACK, data2, NULL, TF_ONE_WAY);
+ callback->transact(BINDER_LIB_TEST_CALL_BACK, data2, nullptr, TF_ONE_WAY);
} else {
m_callback = data.readStrongBinder();
int32_t delayUs = data.readInt32();
@@ -1045,7 +1081,7 @@
Parcel data2, reply2;
sp<IBinder> binder;
binder = data.readStrongBinder();
- if (binder == NULL) {
+ if (binder == nullptr) {
return BAD_VALUE;
}
data2.writeInt32(NO_ERROR);
@@ -1068,7 +1104,7 @@
reply->writeInt32(count);
for (int i = 0; i < count; i++) {
binder = data.readStrongBinder();
- if (binder == NULL) {
+ if (binder == nullptr) {
return BAD_VALUE;
}
indirect_code = data.readInt32();
@@ -1101,11 +1137,11 @@
sp<IBinder> callback;
target = data.readStrongBinder();
- if (target == NULL) {
+ if (target == nullptr) {
return BAD_VALUE;
}
callback = data.readStrongBinder();
- if (callback == NULL) {
+ if (callback == nullptr) {
return BAD_VALUE;
}
ret = target->linkToDeath(testDeathRecipient);
@@ -1130,7 +1166,7 @@
return ret;
}
buf = data.readInplace(size);
- if (buf == NULL) {
+ if (buf == nullptr) {
return BAD_VALUE;
}
ret = write(fd, buf, size);
@@ -1138,6 +1174,28 @@
return UNKNOWN_ERROR;
return NO_ERROR;
}
+ case BINDER_LIB_TEST_WRITE_PARCEL_FILE_DESCRIPTOR_TRANSACTION: {
+ int ret;
+ int32_t size;
+ const void *buf;
+ android::base::unique_fd fd;
+
+ ret = data.readUniqueParcelFileDescriptor(&fd);
+ if (ret != NO_ERROR) {
+ return ret;
+ }
+ ret = data.readInt32(&size);
+ if (ret != NO_ERROR) {
+ return ret;
+ }
+ buf = data.readInplace(size);
+ if (buf == NULL) {
+ return BAD_VALUE;
+ }
+ ret = write(fd.get(), buf, size);
+ if (ret != size) return UNKNOWN_ERROR;
+ return NO_ERROR;
+ }
case BINDER_LIB_TEST_PROMOTE_WEAK_REF_TRANSACTION: {
int ret;
wp<IBinder> weak;
@@ -1147,7 +1205,7 @@
sp<IBinder> server = sm->getService(binderLibTestServiceName);
weak = data.readWeakBinder();
- if (weak == NULL) {
+ if (weak == nullptr) {
return BAD_VALUE;
}
strong = weak.promote();
@@ -1156,7 +1214,7 @@
if (ret != NO_ERROR)
exit(EXIT_FAILURE);
- if (strong == NULL) {
+ if (strong == nullptr) {
reply->setError(1);
}
return NO_ERROR;
@@ -1165,7 +1223,7 @@
alarm(10);
return NO_ERROR;
case BINDER_LIB_TEST_EXIT_TRANSACTION:
- while (wait(NULL) != -1 || errno != ECHILD)
+ while (wait(nullptr) != -1 || errno != ECHILD)
;
exit(EXIT_SUCCESS);
case BINDER_LIB_TEST_CREATE_BINDER_TRANSACTION: {
@@ -1300,4 +1358,3 @@
ProcessState::self()->startThreadPool();
return RUN_ALL_TESTS();
}
-
diff --git a/libs/binder/tests/binderThroughputTest.cpp b/libs/binder/tests/binderThroughputTest.cpp
index bf41e0b..b790997 100644
--- a/libs/binder/tests/binderThroughputTest.cpp
+++ b/libs/binder/tests/binderThroughputTest.cpp
@@ -380,7 +380,7 @@
// Caller specified the max latency in microseconds.
// No need to run training round in this case.
if (atoi(argv[i+1]) > 0) {
- max_time_bucket = strtoull(argv[i+1], (char **)NULL, 10) * 1000;
+ max_time_bucket = strtoull(argv[i+1], (char **)nullptr, 10) * 1000;
time_per_bucket = max_time_bucket / num_buckets;
i++;
} else {
diff --git a/libs/binder/tests/schd-dbg.cpp b/libs/binder/tests/schd-dbg.cpp
index 13f03b1..6cf7f36 100644
--- a/libs/binder/tests/schd-dbg.cpp
+++ b/libs/binder/tests/schd-dbg.cpp
@@ -295,7 +295,7 @@
no_inherent += reply.readInt32();
no_sync += reply.readInt32();
- return 0;
+ return nullptr;
}
// create a fifo thread to transact and wait it to finished
diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp
index 01e90e0..02064c6 100644
--- a/libs/gui/tests/Android.bp
+++ b/libs/gui/tests/Android.bp
@@ -50,9 +50,12 @@
],
}
-// Build a separate binary for each source file to $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
+// Build a separate binary to $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
+// This test has a main method, and requires a separate binary to be built.
+// To add move tests like this, just add additional cc_test statements,
+// as opposed to adding more source files to this one.
cc_test {
- name: "libgui_separate_binary_test",
+ name: "SurfaceParcelable_test",
test_suites: ["device-tests"],
clang: true,
@@ -61,7 +64,6 @@
"-Werror",
],
- test_per_src: true,
srcs: [
"SurfaceParcelable_test.cpp",
],
diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp
index aca9521..f06119f 100644
--- a/libs/input/tests/Android.bp
+++ b/libs/input/tests/Android.bp
@@ -1,7 +1,6 @@
// Build the unit tests.
cc_test {
name: "libinput_tests",
- test_per_src: true,
srcs: [
"InputChannel_test.cpp",
"InputEvent_test.cpp",
diff --git a/libs/vr/libdvr/dvr_api.cpp b/libs/vr/libdvr/dvr_api.cpp
index d14f040..e099f6a 100644
--- a/libs/vr/libdvr/dvr_api.cpp
+++ b/libs/vr/libdvr/dvr_api.cpp
@@ -12,6 +12,7 @@
#include <dvr/dvr_display_manager.h>
#include <dvr/dvr_performance.h>
#include <dvr/dvr_surface.h>
+#include <dvr/dvr_tracking.h>
#include <dvr/dvr_vsync.h>
// Headers not yet moved into libdvr.
diff --git a/libs/vr/libdvr/include/dvr/dvr_api.h b/libs/vr/libdvr/include/dvr/dvr_api.h
index 024cae9..fef8512 100644
--- a/libs/vr/libdvr/include/dvr/dvr_api.h
+++ b/libs/vr/libdvr/include/dvr/dvr_api.h
@@ -10,7 +10,7 @@
#include <dvr/dvr_display_types.h>
#include <dvr/dvr_hardware_composer_types.h>
#include <dvr/dvr_pose.h>
-#include <dvr/dvr_tracking.h>
+#include <dvr/dvr_tracking_types.h>
#ifdef __cplusplus
extern "C" {
@@ -51,6 +51,12 @@
typedef struct DvrSurfaceAttributeValue DvrSurfaceAttributeValue;
typedef struct DvrSurfaceAttribute DvrSurfaceAttribute;
+typedef struct DvrReadBuffer DvrReadBuffer;
+typedef struct DvrTrackingCamera DvrTrackingCamera;
+typedef struct DvrTrackingFeatureExtractor DvrTrackingFeatureExtractor;
+typedef struct DvrTrackingSensors DvrTrackingSensors;
+typedef struct DvrWriteBufferQueue DvrWriteBufferQueue;
+
// Note: To avoid breaking others during active development, only modify this
// struct by appending elements to the end.
// If you do feel we should to re-arrange or remove elements, please make a
@@ -379,6 +385,8 @@
DvrTrackingFeatureExtractor** out_extractor);
typedef void (*DvrTrackingFeatureExtractorDestroyPtr)(
DvrTrackingFeatureExtractor* extractor);
+typedef void (*DvrTrackingFeatureCallback)(void* context,
+ const DvrTrackingFeatures* event);
typedef int (*DvrTrackingFeatureExtractorStartPtr)(
DvrTrackingFeatureExtractor* extractor,
DvrTrackingFeatureCallback callback, void* context);
@@ -388,6 +396,8 @@
DvrTrackingFeatureExtractor* extractor, DvrReadBuffer* buffer,
const DvrTrackingBufferMetadata* metadata, bool* out_skipped);
+typedef void (*DvrTrackingSensorEventCallback)(void* context,
+ DvrTrackingSensorEvent* event);
typedef int (*DvrTrackingSensorsCreatePtr)(DvrTrackingSensors** out_sensors,
const char* mode);
typedef void (*DvrTrackingSensorsDestroyPtr)(DvrTrackingSensors* sensors);
diff --git a/libs/vr/libdvr/include/dvr/dvr_tracking.h b/libs/vr/libdvr/include/dvr/dvr_tracking.h
index b5591a0..5e388f3 100644
--- a/libs/vr/libdvr/include/dvr/dvr_tracking.h
+++ b/libs/vr/libdvr/include/dvr/dvr_tracking.h
@@ -59,7 +59,10 @@
// populate the buffer into. The queue must be empty and the camera stack
// will request buffer allocation with proper buffer dimension, format, and
// usage. Note that the write queue must be created with user_metadata_size
-// set to sizeof(DvrTrackingBufferMetadata).
+// set to sizeof(DvrTrackingBufferMetadata). On success, the write_queue
+// handle will become invalid and the ownership of the queue handle will be
+// transferred into the camera; otherwise, the write_queue handle will keep
+// untouched and the caller still has the ownership.
// @return Zero on success, or negative error code.
int dvrTrackingCameraStart(DvrTrackingCamera* camera,
DvrWriteBufferQueue* write_queue);
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index b1d5e61..2faa794 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -6,7 +6,6 @@
"InputReader_test.cpp",
"InputDispatcher_test.cpp",
],
- test_per_src: true,
cflags: [
"-Wall",
"-Werror",
diff --git a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
index 90404fa..0048000 100644
--- a/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/GLES20RenderEngine.cpp
@@ -112,7 +112,10 @@
using ui::Dataspace;
GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags)
- : mVpWidth(0), mVpHeight(0), mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) {
+ : RenderEngine(featureFlags),
+ mVpWidth(0),
+ mVpHeight(0),
+ mPlatformHasWideColor((featureFlags & WIDE_COLOR_SUPPORT) != 0) {
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
index 5b61db9..796901a 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp
@@ -14,10 +14,13 @@
* limitations under the License.
*/
+#define ATRACE_TAG ATRACE_TAG_GRAPHICS
+
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <utils/String8.h>
+#include <utils/Trace.h>
#include "Description.h"
#include "Program.h"
@@ -75,15 +78,11 @@
ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache)
-ProgramCache::ProgramCache() {
- // Until surfaceflinger has a dependable blob cache on the filesystem,
- // generate shaders on initialization so as to avoid jank.
- primeCache();
-}
+ProgramCache::ProgramCache() {}
ProgramCache::~ProgramCache() {}
-void ProgramCache::primeCache() {
+void ProgramCache::primeCache(bool hasWideColor) {
uint32_t shaderCount = 0;
uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | Key::ALPHA_MASK | Key::TEXTURE_MASK;
// Prime the cache for all combinations of the above masks,
@@ -104,6 +103,27 @@
shaderCount++;
}
}
+
+ // Prime for sRGB->P3 conversion
+ if (hasWideColor) {
+ Key shaderKey;
+ shaderKey.set(Key::BLEND_MASK | Key::TEXTURE_MASK | Key::OUTPUT_TRANSFORM_MATRIX_MASK |
+ Key::INPUT_TF_MASK | Key::OUTPUT_TF_MASK,
+ Key::BLEND_PREMULT | Key::TEXTURE_EXT | Key::OUTPUT_TRANSFORM_MATRIX_ON |
+ Key::INPUT_TF_SRGB | Key::OUTPUT_TF_SRGB);
+ for (int i = 0; i < 4; i++) {
+ shaderKey.set(Key::OPACITY_MASK,
+ (i & 1) ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT);
+ shaderKey.set(Key::ALPHA_MASK, (i & 2) ? Key::ALPHA_LT_ONE : Key::ALPHA_EQ_ONE);
+ Program* program = mCache.valueFor(shaderKey);
+ if (program == nullptr) {
+ program = generateProgram(shaderKey);
+ mCache.add(shaderKey, program);
+ shaderCount++;
+ }
+ }
+ }
+
nsecs_t timeAfter = systemTime();
float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6;
ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs);
@@ -631,6 +651,8 @@
}
Program* ProgramCache::generateProgram(const Key& needs) {
+ ATRACE_CALL();
+
// vertex shader
String8 vs = generateVertexShader(needs);
@@ -654,8 +676,8 @@
mCache.add(needs, program);
time += systemTime();
- // ALOGD(">>> generated new program: needs=%08X, time=%u ms (%d programs)",
- // needs.mNeeds, uint32_t(ns2ms(time)), mCache.size());
+ ALOGV(">>> generated new program: needs=%08X, time=%u ms (%zu programs)", needs.mKey,
+ uint32_t(ns2ms(time)), mCache.size());
}
// here we have a suitable program for this description
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.h b/services/surfaceflinger/RenderEngine/ProgramCache.h
index 864bc3f..983e7ba 100644
--- a/services/surfaceflinger/RenderEngine/ProgramCache.h
+++ b/services/surfaceflinger/RenderEngine/ProgramCache.h
@@ -160,13 +160,14 @@
ProgramCache();
~ProgramCache();
+ // Generate shaders to populate the cache
+ void primeCache(bool hasWideColor);
+
// useProgram lookup a suitable program in the cache or generates one
// if none can be found.
void useProgram(const Description& description);
private:
- // Generate shaders to populate the cache
- void primeCache();
// compute a cache Key from a Description
static Key computeKey(const Description& description);
// Generate EOTF based from Key.
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.cpp b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
index c2233f9..d745770 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.cpp
@@ -150,8 +150,11 @@
}
}
-RenderEngine::RenderEngine()
- : mEGLDisplay(EGL_NO_DISPLAY), mEGLConfig(nullptr), mEGLContext(EGL_NO_CONTEXT) {}
+RenderEngine::RenderEngine(uint32_t featureFlags)
+ : mEGLDisplay(EGL_NO_DISPLAY),
+ mEGLConfig(nullptr),
+ mEGLContext(EGL_NO_CONTEXT),
+ mFeatureFlags(featureFlags) {}
RenderEngine::~RenderEngine() {
eglMakeCurrent(mEGLDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -588,9 +591,7 @@
}
void RenderEngine::primeCache() const {
- // Getting the ProgramCache instance causes it to prime its shader cache,
- // which is performed in its constructor
- ProgramCache::getInstance();
+ ProgramCache::getInstance().primeCache(mFeatureFlags & WIDE_COLOR_SUPPORT);
}
// ---------------------------------------------------------------------------
diff --git a/services/surfaceflinger/RenderEngine/RenderEngine.h b/services/surfaceflinger/RenderEngine/RenderEngine.h
index a14acaa..1196216 100644
--- a/services/surfaceflinger/RenderEngine/RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/RenderEngine.h
@@ -172,7 +172,9 @@
static bool overrideUseContextPriorityFromConfig(bool useContextPriority);
protected:
- RenderEngine();
+ RenderEngine(uint32_t featureFlags);
+
+ const uint32_t mFeatureFlags;
public:
virtual ~RenderEngine() = 0;
diff --git a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
index de78c3f..f2874d6 100644
--- a/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
+++ b/services/surfaceflinger/tests/SurfaceInterceptor_test.cpp
@@ -48,7 +48,10 @@
const Rect CROP_UPDATE(16, 16, 32, 32);
const String8 DISPLAY_NAME("SurfaceInterceptor Display Test");
+constexpr auto TEST_SURFACE_NAME = "BG Interceptor Test Surface";
+constexpr auto UNIQUE_TEST_SURFACE_NAME = "BG Interceptor Test Surface#0";
constexpr auto LAYER_NAME = "Layer Create and Delete Test";
+constexpr auto UNIQUE_LAYER_NAME = "Layer Create and Delete Test#0";
constexpr auto DEFAULT_FILENAME = "/data/SurfaceTrace.dat";
@@ -146,11 +149,11 @@
// Background surface
mBGSurfaceControl = mComposerClient->createSurface(
- String8("BG Interceptor Test Surface"), displayWidth, displayHeight,
+ String8(TEST_SURFACE_NAME), displayWidth, displayHeight,
PIXEL_FORMAT_RGBA_8888, 0);
ASSERT_TRUE(mBGSurfaceControl != nullptr);
ASSERT_TRUE(mBGSurfaceControl->isValid());
- mBGLayerId = getSurfaceId("BG Interceptor Test Surface");
+ mBGLayerId = getSurfaceId(UNIQUE_TEST_SURFACE_NAME);
Transaction t;
t.setDisplayLayerStack(display, 0);
@@ -338,8 +341,8 @@
void SurfaceInterceptorTest::displayDeletion(Transaction&) {
sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, false);
- mTargetId = getDisplayId(DISPLAY_NAME.string());
SurfaceComposerClient::destroyDisplay(testDisplay);
+ mTargetId = getDisplayId(DISPLAY_NAME.string());
}
void SurfaceInterceptorTest::runAllUpdates() {
@@ -455,8 +458,8 @@
bool SurfaceInterceptorTest::matrixUpdateFound(const SurfaceChange& change, bool foundMatrix) {
bool hasSx((float)change.matrix().dsdx() == (float)M_SQRT1_2);
bool hasTx((float)change.matrix().dtdx() == (float)M_SQRT1_2);
- bool hasSy((float)change.matrix().dsdy() == (float)-M_SQRT1_2);
- bool hasTy((float)change.matrix().dtdy() == (float)M_SQRT1_2);
+ bool hasSy((float)change.matrix().dsdy() == (float)M_SQRT1_2);
+ bool hasTy((float)change.matrix().dtdy() == (float)-M_SQRT1_2);
if (hasSx && hasTx && hasSy && hasTy && !foundMatrix) {
foundMatrix = true;
}
@@ -642,7 +645,7 @@
}
bool SurfaceInterceptorTest::surfaceCreationFound(const Increment& increment, bool foundSurface) {
- bool isMatch(increment.surface_creation().name() == LAYER_NAME &&
+ bool isMatch(increment.surface_creation().name() == UNIQUE_LAYER_NAME &&
increment.surface_creation().w() == SIZE_UPDATE &&
increment.surface_creation().h() == SIZE_UPDATE);
if (isMatch && !foundSurface) {
@@ -810,7 +813,7 @@
TEST_F(SurfaceInterceptorTest, InterceptSurfaceDeletionWorks) {
sp<SurfaceControl> layerToDelete = mComposerClient->createSurface(String8(LAYER_NAME),
SIZE_UPDATE, SIZE_UPDATE, PIXEL_FORMAT_RGBA_8888, 0);
- this->mTargetId = getSurfaceId(LAYER_NAME);
+ this->mTargetId = getSurfaceId(UNIQUE_LAYER_NAME);
enableInterceptor();
mComposerClient->destroySurface(layerToDelete->getHandle());
disableInterceptor();
@@ -831,7 +834,9 @@
}
TEST_F(SurfaceInterceptorTest, InterceptBufferUpdateWorks) {
+ enableInterceptor();
nBufferUpdates();
+ disableInterceptor();
Trace capturedTrace;
ASSERT_EQ(NO_ERROR, readProtoFile(&capturedTrace));
ASSERT_TRUE(bufferUpdatesFound(&capturedTrace));
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 3db8a39..def1eca 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -575,15 +575,10 @@
break;
}
- // USAGE_CPU_READ_MASK 0xFUL
- // USAGE_CPU_WRITE_MASK (0xFUL << 4)
- // The currently used bits are as below:
- // USAGE_CPU_READ_RARELY = 2UL
- // USAGE_CPU_READ_OFTEN = 3UL
- // USAGE_CPU_WRITE_RARELY = (2UL << 4)
- // USAGE_CPU_WRITE_OFTEN = (3UL << 4)
- *supported = static_cast<VkBool32>(format_supported ||
- (surface->consumer_usage & 0xFFUL) == 0);
+ *supported = static_cast<VkBool32>(
+ format_supported || (surface->consumer_usage &
+ (AHARDWAREBUFFER_USAGE_CPU_READ_MASK |
+ AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) == 0);
return VK_SUCCESS;
}