Skip to content

Commit eb1cdc5

Browse files
TreeHugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "Fix check for nullptr surface IBinder"
2 parents 1aa60c1 + 09e6005 commit eb1cdc5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5663,7 +5663,10 @@ void SurfaceFlinger::SetInputWindowsListener::onSetInputWindowsFinished() {
56635663
}
56645664

56655665
sp<Layer> SurfaceFlinger::fromHandle(const sp<IBinder>& handle) {
5666-
BBinder *b = handle->localBinder();
5666+
BBinder* b = nullptr;
5667+
if (handle) {
5668+
b = handle->localBinder();
5669+
}
56675670
if (b == nullptr) {
56685671
return nullptr;
56695672
}

services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,11 @@ class TestableSurfaceFlinger {
393393
auto& mutableInternalHwcDisplayId() { return getHwComposer().mInternalHwcDisplayId; }
394394
auto& mutableExternalHwcDisplayId() { return getHwComposer().mExternalHwcDisplayId; }
395395

396+
auto fromHandle(const sp<IBinder>& handle) {
397+
Mutex::Autolock _l(mFlinger->mStateLock);
398+
return mFlinger->fromHandle(handle);
399+
}
400+
396401
~TestableSurfaceFlinger() {
397402
// All these pointer and container clears help ensure that GMock does
398403
// not report a leaked object, since the SurfaceFlinger instance may

services/surfaceflinger/tests/unittests/TransactionApplicationTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,9 @@ TEST_F(TransactionApplicationTest, BlockWithPriorTransaction_SyncInputWindows) {
315315
BlockedByPriorTransaction(/*flags*/ 0, /*syncInputWindows*/ true);
316316
}
317317

318+
TEST_F(TransactionApplicationTest, FromHandle) {
319+
sp<IBinder> badHandle;
320+
auto ret = mFlinger.fromHandle(badHandle);
321+
EXPECT_EQ(nullptr, ret.get());
322+
}
318323
} // namespace android

0 commit comments

Comments
 (0)