Skip to content

Commit 87c7951

Browse files
authored
[tizen_rpc_port] Update RpcPort to support TIDL protocol version 2 (#1070)
1 parent 158dc46 commit 87c7951

5 files changed

Lines changed: 220 additions & 1 deletion

File tree

packages/tizen_rpc_port/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.7
2+
3+
* Guard Tizen 10.0+ specific Parcel APIs (`reader`, `dataSize`, and `reserve`) to throw `UnsupportedError` on unsupported versions of Tizen instead of crashing.
4+
* Add integration test cases for the guarded Tizen 10.0+ specific Parcel APIs.
5+
* Update README to mention system requirements for these APIs.
6+
17
## 0.1.6
28

39
* Read byte values as unsigned (0-255) so `Parcel.readByte` is consistent

packages/tizen_rpc_port/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,6 @@ The following privileges may be added to the client app's `tizen-manifest.xml` f
4747
## Supported devices
4848

4949
This plugin is supported on Tizen devices running Tizen 6.5 or above.
50+
51+
> **Note**
52+
> Some `Parcel` APIs (`reader`, `dataSize`, and `reserve`) are supported only on Tizen 10.0 or above. Calling these APIs on unsupported versions of Tizen will throw an `UnsupportedError`.

packages/tizen_rpc_port/example/client/integration_test/tizen_rpc_port_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,39 @@ void main() {
283283
expect(proxy.portName, 'TestPort');
284284
});
285285
});
286+
287+
// ---------------------------------------------------------------------------
288+
// Tizen 10.0+ Parcel APIs (reader, dataSize, reserve) with safety guards
289+
// ---------------------------------------------------------------------------
290+
291+
group('Tizen 10.0+ Parcel APIs', () {
292+
testWidgets('reader getter/setter', (WidgetTester _) async {
293+
final Parcel parcel = Parcel();
294+
try {
295+
parcel.reader = 10;
296+
expect(parcel.reader, 10);
297+
} on UnsupportedError catch (e) {
298+
expect(e.message, contains('not supported on this version of Tizen'));
299+
}
300+
});
301+
302+
testWidgets('dataSize getter/setter', (WidgetTester _) async {
303+
final Parcel parcel = Parcel();
304+
try {
305+
parcel.dataSize = 20;
306+
expect(parcel.dataSize, 20);
307+
} on UnsupportedError catch (e) {
308+
expect(e.message, contains('not supported on this version of Tizen'));
309+
}
310+
});
311+
312+
testWidgets('reserve', (WidgetTester _) async {
313+
final Parcel parcel = Parcel();
314+
try {
315+
parcel.reserve(100);
316+
} on UnsupportedError catch (e) {
317+
expect(e.message, contains('not supported on this version of Tizen'));
318+
}
319+
});
320+
});
286321
}

packages/tizen_rpc_port/lib/src/parcel.dart

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,179 @@ class Parcel {
484484
return ParcelHeader._fromHandle(pHeader.value);
485485
});
486486
}
487+
488+
/// Gets the reader position of this parcel.
489+
int get reader {
490+
_ensureFunctionsLoaded();
491+
final int Function(rpc_port_parcel_h, Pointer<Uint32>)? func =
492+
_rpcPortParcelGetReader;
493+
if (func == null) {
494+
throw UnsupportedError(
495+
'The reader property is not supported on this version of Tizen.',
496+
);
497+
}
498+
return using((Arena arena) {
499+
final Pointer<Uint32> pValue = arena();
500+
final int ret = func(_handle, pValue);
501+
if (ret != 0) {
502+
throw PlatformException(
503+
code: ret.toString(),
504+
message: tizen.get_error_message(ret).toDartString(),
505+
);
506+
}
507+
return pValue.value;
508+
});
509+
}
510+
511+
/// Sets the reader position of this parcel.
512+
set reader(int value) {
513+
RangeError.checkNotNegative(value, 'value');
514+
_ensureFunctionsLoaded();
515+
final int Function(rpc_port_parcel_h, int)? func = _rpcPortParcelSetReader;
516+
if (func == null) {
517+
throw UnsupportedError(
518+
'The reader property is not supported on this version of Tizen.',
519+
);
520+
}
521+
final int ret = func(_handle, value);
522+
if (ret != 0) {
523+
throw PlatformException(
524+
code: ret.toString(),
525+
message: tizen.get_error_message(ret).toDartString(),
526+
);
527+
}
528+
}
529+
530+
/// Gets the data size of this parcel.
531+
int get dataSize {
532+
_ensureFunctionsLoaded();
533+
final int Function(rpc_port_parcel_h, Pointer<Uint32>)? func =
534+
_rpcPortParcelGetDataSize;
535+
if (func == null) {
536+
throw UnsupportedError(
537+
'The dataSize property is not supported on this version of Tizen.',
538+
);
539+
}
540+
return using((Arena arena) {
541+
final Pointer<Uint32> pValue = arena();
542+
final int ret = func(_handle, pValue);
543+
if (ret != 0) {
544+
throw PlatformException(
545+
code: ret.toString(),
546+
message: tizen.get_error_message(ret).toDartString(),
547+
);
548+
}
549+
return pValue.value;
550+
});
551+
}
552+
553+
/// Sets the data size of this parcel.
554+
set dataSize(int value) {
555+
RangeError.checkNotNegative(value, 'value');
556+
_ensureFunctionsLoaded();
557+
final int Function(rpc_port_parcel_h, int)? func =
558+
_rpcPortParcelSetDataSize;
559+
if (func == null) {
560+
throw UnsupportedError(
561+
'The dataSize property is not supported on this version of Tizen.',
562+
);
563+
}
564+
final int ret = func(_handle, value);
565+
if (ret != 0) {
566+
throw PlatformException(
567+
code: ret.toString(),
568+
message: tizen.get_error_message(ret).toDartString(),
569+
);
570+
}
571+
}
572+
573+
/// Reserves the capacity of this parcel.
574+
void reserve(int size) {
575+
RangeError.checkNotNegative(size, 'size');
576+
_ensureFunctionsLoaded();
577+
final int Function(rpc_port_parcel_h, int)? func = _rpcPortParcelReserve;
578+
if (func == null) {
579+
throw UnsupportedError(
580+
'The reserve method is not supported on this version of Tizen.',
581+
);
582+
}
583+
final int ret = func(_handle, size);
584+
if (ret != 0) {
585+
throw PlatformException(
586+
code: ret.toString(),
587+
message: tizen.get_error_message(ret).toDartString(),
588+
);
589+
}
590+
}
591+
}
592+
593+
DynamicLibrary? _libRpcPort;
594+
bool _libRpcPortLoaded = false;
595+
596+
DynamicLibrary? _getLibRpcPort() {
597+
if (!_libRpcPortLoaded) {
598+
try {
599+
_libRpcPort = DynamicLibrary.open('librpc-port.so.1');
600+
} catch (_) {
601+
_libRpcPort = null;
602+
}
603+
_libRpcPortLoaded = true;
604+
}
605+
return _libRpcPort;
606+
}
607+
608+
int Function(rpc_port_parcel_h, Pointer<Uint32>)? _rpcPortParcelGetReader;
609+
int Function(rpc_port_parcel_h, int)? _rpcPortParcelSetReader;
610+
int Function(rpc_port_parcel_h, Pointer<Uint32>)? _rpcPortParcelGetDataSize;
611+
int Function(rpc_port_parcel_h, int)? _rpcPortParcelSetDataSize;
612+
int Function(rpc_port_parcel_h, int)? _rpcPortParcelReserve;
613+
614+
bool _functionsLoaded = false;
615+
616+
void _ensureFunctionsLoaded() {
617+
if (_functionsLoaded) {
618+
return;
619+
}
620+
_functionsLoaded = true;
621+
final DynamicLibrary? lib = _getLibRpcPort();
622+
if (lib == null) {
623+
return;
624+
}
625+
try {
626+
_rpcPortParcelGetReader = lib
627+
.lookup<
628+
NativeFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>)>>(
629+
'rpc_port_parcel_get_reader',
630+
)
631+
.asFunction();
632+
} catch (_) {}
633+
try {
634+
_rpcPortParcelSetReader = lib
635+
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
636+
'rpc_port_parcel_set_reader',
637+
)
638+
.asFunction();
639+
} catch (_) {}
640+
try {
641+
_rpcPortParcelGetDataSize = lib
642+
.lookup<
643+
NativeFunction<Int32 Function(rpc_port_parcel_h, Pointer<Uint32>)>>(
644+
'rpc_port_parcel_get_data_size',
645+
)
646+
.asFunction();
647+
} catch (_) {}
648+
try {
649+
_rpcPortParcelSetDataSize = lib
650+
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
651+
'rpc_port_parcel_set_data_size',
652+
)
653+
.asFunction();
654+
} catch (_) {}
655+
try {
656+
_rpcPortParcelReserve = lib
657+
.lookup<NativeFunction<Int32 Function(rpc_port_parcel_h, Uint32)>>(
658+
'rpc_port_parcel_reserve',
659+
)
660+
.asFunction();
661+
} catch (_) {}
487662
}

packages/tizen_rpc_port/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: tizen_rpc_port
22
description: Tizen RPC Port APIs. Used to make remote procedure calls between Tizen apps.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/tizen_rpc_port
5-
version: 0.1.6
5+
version: 0.1.7
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

0 commit comments

Comments
 (0)