Skip to content

Commit 6eb99fb

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
fix: use generated proxy for BT GATT, eliminating manual parcel writes
1 parent 66a1178 commit 6eb99fb

2 files changed

Lines changed: 8 additions & 51 deletions

File tree

examples/ble_sensor_collector/main.go

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/AndroidGoLab/binder/binder"
2727
"github.com/AndroidGoLab/binder/binder/versionaware"
2828
"github.com/AndroidGoLab/binder/kernelbinder"
29-
"github.com/AndroidGoLab/binder/parcel"
3029
"github.com/AndroidGoLab/binder/servicemanager"
3130
)
3231

@@ -178,37 +177,16 @@ func main() {
178177

179178
spy := &gattSpy{registeredCh: make(chan int32, 1)}
180179
gattCallback := genBluetooth.NewBluetoothGattCallbackStub(spy)
180+
gattProxy := genBluetooth.NewBluetoothGattProxy(gattBinder)
181181

182-
// registerClient via raw transaction (the generated proxy may not
183-
// handle all the complex parameters correctly).
184-
code, err := gattBinder.ResolveCode(ctx, genBluetooth.DescriptorIBluetoothGatt, "registerClient")
185-
if err != nil {
186-
fmt.Fprintf(os.Stderr, "resolve registerClient: %v\n", err)
187-
os.Exit(1)
188-
}
182+
// ParcelUuid for the app identifier (placeholder; the actual UUID
183+
// value is not significant for GATT client registration).
184+
appID := genOs.ParcelUuid{}
189185

190-
data := parcel.New()
191-
data.WriteInterfaceToken(genBluetooth.DescriptorIBluetoothGatt)
192-
data.WriteInt32(1) // non-null ParcelUuid
193-
data.WriteInt64(0x0000180000001000)
194-
data.WriteInt64(-9223371485494954757)
195-
binder.WriteBinderToParcel(ctx, data, gattCallback.AsBinder(), transport)
196-
data.WriteBool(false)
197-
data.WriteInt32(0)
198-
attr := shellAttribution()
199-
data.WriteInt32(1)
200-
attr.MarshalParcel(data)
201-
202-
reply, err := gattBinder.Transact(ctx, code, 0, data)
203-
if err != nil {
186+
if err := gattProxy.RegisterClient(ctx, appID, gattCallback, false, 0, shellAttribution()); err != nil {
204187
fmt.Fprintf(os.Stderr, "registerClient: %v\n", err)
205188
os.Exit(1)
206189
}
207-
if statusErr := binder.ReadStatus(reply); statusErr != nil {
208-
fmt.Fprintf(os.Stderr, "registerClient status: %v\n", statusErr)
209-
fmt.Fprintf(os.Stderr, "Hint: AIDL version mismatch — the BT stack may not expect AttributionSource.\n")
210-
return
211-
}
212190

213191
select {
214192
case status := <-spy.registeredCh:

tests/e2e/bluetooth_gatt_test.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/AndroidGoLab/binder/android/content"
1818
genOs "github.com/AndroidGoLab/binder/android/os"
1919
"github.com/AndroidGoLab/binder/binder"
20-
"github.com/AndroidGoLab/binder/parcel"
2120
)
2221

2322
// ---------------------------------------------------------------------------
@@ -192,34 +191,14 @@ func TestBluetoothGATT_FullPipeline(t *testing.T) {
192191
require.NotNil(t, gattBinder, "GetBluetoothGatt returned nil")
193192
t.Logf("IBluetoothGatt handle: %d", gattBinder.Handle())
194193

195-
code := resolveCode(ctx, t, gattBinder,
196-
genBluetooth.DescriptorIBluetoothGatt, "registerClient")
194+
gattProxy := genBluetooth.NewBluetoothGattProxy(gattBinder)
197195

198196
spy := &gattCallbackSpy{registeredCh: make(chan int32, 1)}
199197
gattCallback := genBluetooth.NewBluetoothGattCallbackStub(spy)
200198

201-
data := parcel.New()
202-
defer data.Recycle()
203-
data.WriteInterfaceToken(genBluetooth.DescriptorIBluetoothGatt)
204-
data.WriteInt32(1) // non-null ParcelUuid
205-
data.WriteInt64(0x0000180000001000)
206-
data.WriteInt64(-9223371485494954757)
207-
binder.WriteBinderToParcel(ctx, data, gattCallback.AsBinder(), transport)
208-
data.WriteBool(false)
209-
data.WriteInt32(0)
210-
attr := shellAttribution()
211-
data.WriteInt32(1)
212-
attr.MarshalParcel(data)
213-
214-
regReply, err := gattBinder.Transact(ctx, code, 0, data)
199+
appID := genOs.ParcelUuid{}
200+
err = gattProxy.RegisterClient(ctx, appID, gattCallback, false, 0, shellAttribution())
215201
requireOrSkip(t, err)
216-
if statusErr := binder.ReadStatus(regReply); statusErr != nil {
217-
// AIDL version mismatch: the server may not expect
218-
// AttributionSource (e.g., older BT stack). Skip
219-
// rather than fail — the proxy call is correct per
220-
// the AIDL spec, but the device's version differs.
221-
requireOrSkip(t, statusErr)
222-
}
223202

224203
select {
225204
case status := <-spy.registeredCh:

0 commit comments

Comments
 (0)