-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_binder.go
More file actions
37 lines (32 loc) · 880 Bytes
/
write_binder.go
File metadata and controls
37 lines (32 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package binder
import (
"context"
"github.com/AndroidGoLab/binder/parcel"
)
// WriteBinderToParcel writes an IBinder to a parcel, choosing the correct
// wire format based on whether the binder is a local stub or a remote proxy.
//
// For remote proxies (ProxyBinder), it writes BINDER_TYPE_HANDLE with the handle.
// For local stubs (StubBinder), it auto-registers the stub with the transport
// (if not already registered) and writes BINDER_TYPE_BINDER with the cookie.
func WriteBinderToParcel(
ctx context.Context,
p *parcel.Parcel,
b IBinder,
transport Transport,
) {
if b == nil {
p.WriteNullStrongBinder()
return
}
stub, isStub := b.(*StubBinder)
if !isStub {
p.WriteStrongBinder(b.Handle())
return
}
cookie := stub.Cookie()
if cookie == 0 {
cookie = stub.RegisterWithTransport(ctx, transport)
}
p.WriteLocalBinder(stub.BinderPtr(), cookie)
}