1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #define LOG_TAG "Cts-NdkBinderTest"
17 
18 #include <android/binder_ibinder.h>
19 #include <gtest/gtest.h>
20 
21 #include "utilities.h"
22 
23 class NdkBinderTest_AIBinder : public NdkBinderTest {};
24 
TEST_F(NdkBinderTest_AIBinder,Destruction)25 TEST_F(NdkBinderTest_AIBinder, Destruction) {
26   bool destroyed = false;
27   AIBinder* binder =
28       SampleData::newBinder(nullptr, [&](SampleData*) { destroyed = true; });
29   EXPECT_FALSE(destroyed);
30   AIBinder_incStrong(binder);  // 1 -> 2
31   EXPECT_FALSE(destroyed);
32   AIBinder_decStrong(binder);  // 2 -> 1
33   EXPECT_FALSE(destroyed);
34   AIBinder_decStrong(binder);  // 1 -> 0
35   EXPECT_TRUE(destroyed);
36 }
37 
TEST_F(NdkBinderTest_AIBinder,GetClass)38 TEST_F(NdkBinderTest_AIBinder, GetClass) {
39   AIBinder* binder = SampleData::newBinder();
40   // class is already set since this local binder is contructed with it
41   EXPECT_EQ(SampleData::kClass, AIBinder_getClass(binder));
42   AIBinder_decStrong(binder);
43 }
44 
TEST_F(NdkBinderTest_AIBinder,AssociateClass)45 TEST_F(NdkBinderTest_AIBinder, AssociateClass) {
46   AIBinder* binder = SampleData::newBinder();
47   EXPECT_TRUE(AIBinder_associateClass(binder, SampleData::kClass));
48   AIBinder_decStrong(binder);
49 }
50 
TEST_F(NdkBinderTest_AIBinder,AssociateUnrelatedClassWithSameDescriptorFails)51 TEST_F(NdkBinderTest_AIBinder, AssociateUnrelatedClassWithSameDescriptorFails) {
52   AIBinder* binder = SampleData::newBinder();
53   EXPECT_FALSE(AIBinder_associateClass(binder, SampleData::kAnotherClassWithSameDescriptor));
54   AIBinder_decStrong(binder);
55 }
56 
TEST_F(NdkBinderTest_AIBinder,AssociateWrongClassFails)57 TEST_F(NdkBinderTest_AIBinder, AssociateWrongClassFails) {
58   AIBinder* binder = SampleData::newBinder();
59   EXPECT_FALSE(AIBinder_associateClass(binder, SampleData::kAnotherClass));
60   AIBinder_decStrong(binder);
61 }
62 
TEST_F(NdkBinderTest_AIBinder,ClassGetDescriptor)63 TEST_F(NdkBinderTest_AIBinder, ClassGetDescriptor) {
64   EXPECT_NE(SampleData::kClass, SampleData::kAnotherClassWithSameDescriptor);
65   EXPECT_STREQ(SampleData::kDescriptor, AIBinder_Class_getDescriptor(SampleData::kClass));
66   EXPECT_STREQ(SampleData::kDescriptor,
67                AIBinder_Class_getDescriptor(SampleData::kAnotherClassWithSameDescriptor));
68 
69   AIBinder* binder = SampleData::newBinder();
70   EXPECT_STREQ(SampleData::kDescriptor, AIBinder_Class_getDescriptor(AIBinder_getClass(binder)));
71   AIBinder_decStrong(binder);
72 }
73 
TEST_F(NdkBinderTest_AIBinder,GetUserData)74 TEST_F(NdkBinderTest_AIBinder, GetUserData) {
75   // This test can't use the helper utility since SampleData isn't exposed
76   SampleData* data = new SampleData;
77   // Takes ownership of data
78   AIBinder* binder = AIBinder_new(SampleData::kClass, static_cast<void*>(data));
79   EXPECT_EQ(data, AIBinder_getUserData(binder));
80   AIBinder_decStrong(binder);
81 }
82 
TEST_F(NdkBinderTest_AIBinder,DestructionGivesUserData)83 TEST_F(NdkBinderTest_AIBinder, DestructionGivesUserData) {
84   // This test can't use the helper utility since SampleData isn't exposed
85   SampleData* destroyedPointer = nullptr;
86   SampleData* data = new SampleData(
87       nullptr, [&](SampleData* data) { destroyedPointer = data; });
88   // Takes ownership of data
89   AIBinder* binder = AIBinder_new(SampleData::kClass, static_cast<void*>(data));
90   EXPECT_EQ(nullptr, destroyedPointer);
91   AIBinder_decStrong(binder);
92 
93   // These pointers no longer reference valid memory locations, but the pointers
94   // themselves are valid
95   EXPECT_EQ(data, destroyedPointer);
96 }
97 
onBinderDied(void *)98 void onBinderDied(void* /*cookie*/) {}
99 
TEST_F(NdkBinderTest_AIBinder,LinkInProcess)100 TEST_F(NdkBinderTest_AIBinder, LinkInProcess) {
101   AIBinder* binder = SampleData::newBinder();
102   AIBinder_DeathRecipient* recipient =
103       AIBinder_DeathRecipient_new(onBinderDied);
104 
105   EXPECT_EQ(STATUS_INVALID_OPERATION,
106             AIBinder_linkToDeath(binder, recipient, nullptr /*cookie*/));
107 
108   AIBinder_DeathRecipient_delete(recipient);
109   AIBinder_decStrong(binder);
110 }
111 
TEST_F(NdkBinderTest_AIBinder,GetCallingWhenNoCalling)112 TEST_F(NdkBinderTest_AIBinder, GetCallingWhenNoCalling) {
113   // Calling UID/PID are current calling UID/PID if there isn't an incoming
114   // call.
115   EXPECT_EQ(getuid(), AIBinder_getCallingUid());
116   EXPECT_EQ(getpid(), AIBinder_getCallingPid());
117 }
118 
TEST_F(NdkBinderTest_AIBinder,DebugRefCount)119 TEST_F(NdkBinderTest_AIBinder, DebugRefCount) {
120   AIBinder* binder = SampleData::newBinder();
121   EXPECT_EQ(1, AIBinder_debugGetRefCount(binder));
122   AIBinder_decStrong(binder);
123 }
124 
TEST_F(NdkBinderTest_AIBinder,WeakPointerCanPromote)125 TEST_F(NdkBinderTest_AIBinder, WeakPointerCanPromote) {
126   AIBinder* binder = SampleData::newBinder();
127   AIBinder_Weak* weak = AIBinder_Weak_new(binder);
128   AIBinder* promoted = AIBinder_Weak_promote(weak);
129   EXPECT_EQ(binder, promoted);
130   AIBinder_Weak_delete(weak);
131   AIBinder_decStrong(binder);
132   AIBinder_decStrong(promoted);
133 }
134 
TEST_F(NdkBinderTest_AIBinder,WeakPointerCanNotPromote)135 TEST_F(NdkBinderTest_AIBinder, WeakPointerCanNotPromote) {
136   AIBinder* binder = SampleData::newBinder();
137   AIBinder_Weak* weak = AIBinder_Weak_new(binder);
138   AIBinder_decStrong(binder);
139 
140   AIBinder* promoted = AIBinder_Weak_promote(weak);
141   EXPECT_EQ(nullptr, promoted);
142 
143   AIBinder_Weak_delete(weak);
144 }
145 
TEST_F(NdkBinderTest_AIBinder,WeakPointerClonePromotes)146 TEST_F(NdkBinderTest_AIBinder, WeakPointerClonePromotes) {
147   AIBinder* binder = SampleData::newBinder();
148   AIBinder_Weak* weak = AIBinder_Weak_new(binder);
149   AIBinder_Weak* copy = AIBinder_Weak_clone(weak);
150   AIBinder_Weak_delete(weak);
151 
152   AIBinder* promoted = AIBinder_Weak_promote(copy);
153   EXPECT_EQ(binder, promoted);
154 
155   AIBinder_Weak_delete(copy);
156   AIBinder_decStrong(promoted);
157   AIBinder_decStrong(binder);
158 }
159 
TEST_F(NdkBinderTest_AIBinder,WeakPointerCloneNoPromote)160 TEST_F(NdkBinderTest_AIBinder, WeakPointerCloneNoPromote) {
161   AIBinder* binder = SampleData::newBinder();
162   AIBinder_Weak* weak = AIBinder_Weak_new(binder);
163   AIBinder_Weak* copy = AIBinder_Weak_clone(weak);
164   AIBinder_Weak_delete(weak);
165 
166   AIBinder_decStrong(binder);
167 
168   AIBinder* promoted = AIBinder_Weak_promote(weak);
169   EXPECT_EQ(nullptr, promoted);
170 
171   AIBinder_Weak_delete(copy);
172 }
173 
TEST_F(NdkBinderTest_AIBinder,BinderEqual)174 TEST_F(NdkBinderTest_AIBinder, BinderEqual) {
175   AIBinder* binder = SampleData::newBinder();
176 
177   EXPECT_FALSE(AIBinder_lt(binder, binder));
178 
179   AIBinder_decStrong(binder);
180 }
181 
TEST_F(NdkBinderTest_AIBinder,BinderNotEqual)182 TEST_F(NdkBinderTest_AIBinder, BinderNotEqual) {
183   AIBinder* b1 = SampleData::newBinder();
184   AIBinder* b2 = SampleData::newBinder();
185 
186   EXPECT_NE(AIBinder_lt(b1, b2), AIBinder_lt(b2, b1));
187 
188   AIBinder_decStrong(b2);
189   AIBinder_decStrong(b1);
190 }
191 
TEST_F(NdkBinderTest_AIBinder,WeakPointerEqual)192 TEST_F(NdkBinderTest_AIBinder, WeakPointerEqual) {
193   AIBinder* binder = SampleData::newBinder();
194   AIBinder_Weak* weak1 = AIBinder_Weak_new(binder);
195   AIBinder_Weak* weak2 = AIBinder_Weak_new(binder);
196 
197   // doesn't need to be promotable to remember ordering
198   AIBinder_decStrong(binder);
199 
200   // they are different objects
201   EXPECT_NE(weak1, weak2);
202 
203   // they point to the same binder
204   EXPECT_FALSE(AIBinder_Weak_lt(weak1, weak2));
205   EXPECT_FALSE(AIBinder_Weak_lt(weak2, weak1));
206 
207   AIBinder_Weak_delete(weak1);
208   AIBinder_Weak_delete(weak2);
209 }
210 
TEST_F(NdkBinderTest_AIBinder,WeakPointerNotEqual)211 TEST_F(NdkBinderTest_AIBinder, WeakPointerNotEqual) {
212   AIBinder* b1 = SampleData::newBinder();
213   AIBinder_Weak* w1 = AIBinder_Weak_new(b1);
214   AIBinder* b2 = SampleData::newBinder();
215   AIBinder_Weak* w2 = AIBinder_Weak_new(b2);
216 
217   bool b1ltb2 = AIBinder_lt(b1, b2);
218 
219   // doesn't need to be promotable to remember ordering
220   AIBinder_decStrong(b2);
221   AIBinder_decStrong(b1);
222 
223   EXPECT_EQ(b1ltb2, AIBinder_Weak_lt(w1, w2));
224   EXPECT_EQ(!b1ltb2, AIBinder_Weak_lt(w2, w1));
225 
226   AIBinder_Weak_delete(w1);
227   AIBinder_Weak_delete(w2);
228 }
229 
TEST_F(NdkBinderTest_AIBinder,LocalIsLocal)230 TEST_F(NdkBinderTest_AIBinder, LocalIsLocal) {
231   AIBinder* binder = SampleData::newBinder();
232   EXPECT_FALSE(AIBinder_isRemote(binder));
233   AIBinder_decStrong(binder);
234 }
235 
TEST_F(NdkBinderTest_AIBinder,IsAlive)236 TEST_F(NdkBinderTest_AIBinder, IsAlive) {
237   AIBinder* binder = SampleData::newBinder();
238   EXPECT_TRUE(AIBinder_isAlive(binder));
239   AIBinder_decStrong(binder);
240 }
241 
TEST_F(NdkBinderTest_AIBinder,CanPing)242 TEST_F(NdkBinderTest_AIBinder, CanPing) {
243   AIBinder* binder = SampleData::newBinder();
244   EXPECT_OK(AIBinder_ping(binder));
245   AIBinder_decStrong(binder);
246 }
247 
TEST_F(NdkBinderTest_AIBinder,GetExtensionImmediatelyReturnsNull)248 TEST_F(NdkBinderTest_AIBinder, GetExtensionImmediatelyReturnsNull) {
249   AIBinder* binder = SampleData::newBinder();
250   AIBinder* ext;
251   EXPECT_OK(AIBinder_getExtension(binder, &ext));
252   EXPECT_EQ(ext, nullptr);
253   AIBinder_decStrong(binder);
254 }
255 
TEST_F(NdkBinderTest_AIBinder,GetSetExtensionLocally)256 TEST_F(NdkBinderTest_AIBinder, GetSetExtensionLocally) {
257   AIBinder* binder = SampleData::newBinder();
258   AIBinder* ext = SampleData::newBinder();
259   EXPECT_OK(AIBinder_setExtension(binder, ext));
260 
261   AIBinder* getExt;
262   EXPECT_OK(AIBinder_getExtension(binder, &getExt));
263   ASSERT_EQ(ext, getExt);
264 
265   AIBinder_decStrong(ext);
266   AIBinder_decStrong(getExt);
267   AIBinder_decStrong(binder);
268 }
269 
TEST_F(NdkBinderTest_AIBinder,GetSetExtensionRepeatedly)270 TEST_F(NdkBinderTest_AIBinder, GetSetExtensionRepeatedly) {
271   AIBinder* binder = SampleData::newBinder();
272   AIBinder* ext1 = SampleData::newBinder();
273   AIBinder* ext2 = SampleData::newBinder();
274   EXPECT_OK(AIBinder_setExtension(binder, ext1));
275   EXPECT_OK(AIBinder_setExtension(binder, ext2));
276 
277   AIBinder* getExt;
278   EXPECT_OK(AIBinder_getExtension(binder, &getExt));
279   ASSERT_EQ(ext2, getExt);
280 
281   AIBinder_decStrong(ext1);
282   AIBinder_decStrong(ext2);
283   AIBinder_decStrong(getExt);
284   AIBinder_decStrong(binder);
285 }
286 
TEST_F(NdkBinderTest_AIBinder,TransactionHappens)287 TEST_F(NdkBinderTest_AIBinder, TransactionHappens) {
288   AIBinder* binder = SampleData::newBinder(TransactionsReturn(STATUS_OK),
289                                            ExpectLifetimeTransactions(1));
290   EXPECT_OK(SampleData::transact(binder, kCode));
291   AIBinder_decStrong(binder);
292 }
293 
TEST_F(NdkBinderTest_AIBinder,OnewayTransactionHappens)294 TEST_F(NdkBinderTest_AIBinder, OnewayTransactionHappens) {
295   AIBinder* binder = SampleData::newBinder(TransactionsReturn(STATUS_OK),
296                                            ExpectLifetimeTransactions(1));
297   EXPECT_OK(SampleData::transact(binder, kCode, WriteNothingToParcel,
298                                  ReadNothingFromParcel, FLAG_ONEWAY));
299   AIBinder_decStrong(binder);
300 }
301 
TEST_F(NdkBinderTest_AIBinder,TransactionCodeMaintained)302 TEST_F(NdkBinderTest_AIBinder, TransactionCodeMaintained) {
303   AIBinder* binder = SampleData::newBinder(
304       [&](transaction_code_t code, const AParcel*, AParcel*) {
305         EXPECT_EQ(code, kCode);
306         return STATUS_OK;
307       },
308       ExpectLifetimeTransactions(1));
309   EXPECT_OK(SampleData::transact(binder, kCode));
310   AIBinder_decStrong(binder);
311 }
312 
TEST_F(NdkBinderTest_AIBinder,TransactionCodeRangeRespected)313 TEST_F(NdkBinderTest_AIBinder, TransactionCodeRangeRespected) {
314   AIBinder* binder = SampleData::newBinder(TransactionsReturn(STATUS_OK));
315   EXPECT_OK(SampleData::transact(binder, FIRST_CALL_TRANSACTION));
316   EXPECT_OK(SampleData::transact(binder, FIRST_CALL_TRANSACTION + 1));
317   EXPECT_OK(SampleData::transact(binder, LAST_CALL_TRANSACTION - 1));
318   EXPECT_OK(SampleData::transact(binder, LAST_CALL_TRANSACTION));
319 
320   EXPECT_EQ(STATUS_UNKNOWN_TRANSACTION,
321             SampleData::transact(binder, FIRST_CALL_TRANSACTION - 1));
322   EXPECT_EQ(STATUS_UNKNOWN_TRANSACTION,
323             SampleData::transact(binder, LAST_CALL_TRANSACTION + 1));
324   AIBinder_decStrong(binder);
325 }
326 
TEST_F(NdkBinderTest_AIBinder,UnknownFlagsRejected)327 TEST_F(NdkBinderTest_AIBinder, UnknownFlagsRejected) {
328   AIBinder* binder =
329       SampleData::newBinder(nullptr, ExpectLifetimeTransactions(0));
330   EXPECT_EQ(STATUS_BAD_VALUE,
331             SampleData::transact(binder, kCode, WriteNothingToParcel,
332                                  ReadNothingFromParcel, +1 + 415));
333   EXPECT_EQ(STATUS_BAD_VALUE,
334             SampleData::transact(binder, kCode, WriteNothingToParcel,
335                                  ReadNothingFromParcel, FLAG_ONEWAY + 1));
336   EXPECT_EQ(STATUS_BAD_VALUE,
337             SampleData::transact(binder, kCode, WriteNothingToParcel,
338                                  ReadNothingFromParcel, ~0));
339   AIBinder_decStrong(binder);
340 }
341 
TEST_F(NdkBinderTest_AIBinder,UnassociatedBinderRejected)342 TEST_F(NdkBinderTest_AIBinder, UnassociatedBinderRejected) {
343   AIBinder* binder1 = SampleData::newBinder(nullptr, ExpectLifetimeTransactions(0));
344 
345   AParcel* in;
346   EXPECT_EQ(STATUS_OK, AIBinder_prepareTransaction(binder1, &in));
347 
348   AIBinder* binder2 = SampleData::newBinder(nullptr, ExpectLifetimeTransactions(0));
349 
350   AParcel* out;
351   // transaction on different binder object from prepare fails
352   EXPECT_EQ(STATUS_BAD_VALUE, AIBinder_transact(binder2, kCode, &in, &out, 0));
353 
354   AParcel_delete(out);
355 
356   AIBinder_decStrong(binder2);
357   AIBinder_decStrong(binder1);
358 }
359 
EmptyOnCreate(void * args)360 void* EmptyOnCreate(void* args) { return args; }
EmptyOnDestroy(void *)361 void EmptyOnDestroy(void* /*userData*/) {}
EmptyOnTransact(AIBinder *,transaction_code_t,const AParcel *,AParcel *)362 binder_status_t EmptyOnTransact(AIBinder* /*binder*/,
363                                 transaction_code_t /*code*/,
364                                 const AParcel* /*in*/, AParcel* /*out*/) {
365   return STATUS_OK;
366 }
367 
TEST_F(NdkBinderTest_AIBinder,NullArguments)368 TEST_F(NdkBinderTest_AIBinder, NullArguments) {
369   void* const kVoidStar = reinterpret_cast<void*>(0xDEADBEEF);
370   const char* const kStr = "asdf";
371   AIBinder* binder = SampleData::newBinder();
372   AIBinder_DeathRecipient* recipient =
373       AIBinder_DeathRecipient_new(onBinderDied);
374   EXPECT_NE(nullptr, recipient);
375 
376   EXPECT_EQ(nullptr, AIBinder_Class_define(nullptr, EmptyOnCreate,
377                                            EmptyOnDestroy, EmptyOnTransact));
378   EXPECT_EQ(nullptr, AIBinder_Class_define(kStr, nullptr, EmptyOnDestroy,
379                                            EmptyOnTransact));
380   EXPECT_EQ(nullptr, AIBinder_Class_define(kStr, EmptyOnCreate, nullptr,
381                                            EmptyOnTransact));
382   EXPECT_EQ(nullptr, AIBinder_Class_define(kStr, EmptyOnCreate, EmptyOnDestroy,
383                                            nullptr));
384 
385   EXPECT_EQ(nullptr, AIBinder_new(nullptr /*clazz*/, kVoidStar /*args*/));
386   EXPECT_EQ(false, AIBinder_isRemote(nullptr));
387   EXPECT_EQ(false, AIBinder_isAlive(nullptr));
388   EXPECT_EQ(STATUS_UNEXPECTED_NULL, AIBinder_ping(nullptr));
389 
390   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
391             AIBinder_linkToDeath(nullptr, recipient, kVoidStar /*cookie*/));
392   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
393             AIBinder_linkToDeath(binder, nullptr, kVoidStar /*cookie*/));
394   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
395             AIBinder_unlinkToDeath(nullptr, recipient, kVoidStar /*cookie*/));
396   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
397             AIBinder_unlinkToDeath(binder, nullptr, kVoidStar /*cookie*/));
398 
399   // Does not crash
400   AIBinder_incStrong(nullptr);
401   AIBinder_decStrong(nullptr);
402 
403   EXPECT_EQ(-1, AIBinder_debugGetRefCount(nullptr));
404   EXPECT_EQ(false, AIBinder_associateClass(binder, nullptr));
405   EXPECT_EQ(false, AIBinder_associateClass(nullptr, SampleData::kClass));
406   EXPECT_EQ(nullptr, AIBinder_getClass(nullptr));
407   EXPECT_EQ(nullptr, AIBinder_getUserData(nullptr));
408 
409   AParcel* parcel = nullptr;
410   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
411             AIBinder_prepareTransaction(binder, nullptr));
412   EXPECT_EQ(STATUS_UNEXPECTED_NULL,
413             AIBinder_prepareTransaction(nullptr, &parcel));
414   EXPECT_EQ(nullptr, parcel);  // not modified
415 
416   {
417     auto newParcel = [&] {
418       AParcel* parcel = nullptr;
419       EXPECT_OK(AIBinder_prepareTransaction(binder, &parcel));
420       return parcel;
421     };
422 
423     AParcel* inParcel = nullptr;
424     AParcel* outParcel = nullptr;
425 
426     inParcel = newParcel();
427     EXPECT_NE(nullptr, inParcel);
428     EXPECT_EQ(
429         STATUS_UNEXPECTED_NULL,
430         AIBinder_transact(nullptr, kCode, &inParcel, &outParcel, 0 /*flags*/));
431     EXPECT_EQ(nullptr, inParcel);   // ownership taken
432     EXPECT_EQ(nullptr, outParcel);  // not modified
433 
434     EXPECT_EQ(
435         STATUS_UNEXPECTED_NULL,
436         AIBinder_transact(binder, kCode, nullptr, &outParcel, 0 /*flags*/));
437     EXPECT_EQ(nullptr, outParcel);  // not modified
438 
439     inParcel = newParcel();
440     EXPECT_NE(nullptr, inParcel);
441     EXPECT_EQ(
442         STATUS_UNEXPECTED_NULL,
443         AIBinder_transact(binder, kCode, &inParcel, nullptr, 0 /*flags*/));
444     EXPECT_EQ(nullptr, inParcel);   // ownership taken
445     EXPECT_EQ(nullptr, outParcel);  // not modified
446   }
447 
448   EXPECT_EQ(nullptr, AIBinder_Weak_new(nullptr));
449 
450   // Does not crash
451   AIBinder_Weak_delete(nullptr);
452 
453   EXPECT_EQ(nullptr, AIBinder_Weak_promote(nullptr));
454 
455   EXPECT_EQ(nullptr, AIBinder_DeathRecipient_new(nullptr));
456 
457   EXPECT_EQ(nullptr, AIBinder_Weak_clone(nullptr));
458 
459   AIBinder_Weak* weak = AIBinder_Weak_new(binder);
460   EXPECT_TRUE(AIBinder_Weak_lt(nullptr, weak));
461   EXPECT_FALSE(AIBinder_Weak_lt(weak, nullptr));
462   AIBinder_Weak_delete(weak);
463 
464   // Does not crash
465   AIBinder_DeathRecipient_delete(nullptr);
466 
467   AIBinder_DeathRecipient_delete(recipient);
468   AIBinder_decStrong(binder);
469 
470   EXPECT_EQ(STATUS_UNEXPECTED_NULL, AIBinder_getExtension(nullptr, nullptr));
471   EXPECT_EQ(STATUS_UNEXPECTED_NULL, AIBinder_setExtension(nullptr, nullptr));
472 }
473