README.md
1# Default and Optional RPCs Example
2
3This example shows you how to use `RpcDefault` and `RpcOptional` which is built
4into Mobly snippet lib to annotate RPC's parameters.
5
6## Why this is needed?
7
8These annotations can be used to specify the default and optional parameters for
9RPC methods, which allows developers to create more flexible and reusable RPC
10methods.
11
12Here are some additional benefits of using `RpcDefault` and `RpcOptional`:
13
14 - Improve the readability and maintainability of RPC methods.
15 - Prevent errors caused by missing or invalid parameters.
16 - Make it easier to test RPC methods.
17
18See the source code ExampleDefaultAndOptionalRpcSnippet.java for details.
19
20## Running the example code
21
22This folder contains a fully working example of a standalone snippet apk.
23
241. Compile the example
25
26 ./gradlew examples:ex7_default_and_optional_rpc:assembleDebug
27
281. Install the apk on your phone
29
30 adb install -r ./examples/ex7_default_and_optional_rpc/build/outputs/apk/debug/ex7_default_and_optional_rpc-debug.apk
31
321. Use `snippet_shell` from mobly to trigger `makeToast()`:
33
34 snippet_shell.py com.google.android.mobly.snippet.example7
35
36 >>> s.makeToast('Hello')
37
38 Wait for `Hello, bool:true` message to show up on the screen. Here we
39 didn't provide a Boolean to the RPC, so a default value, true, is used.
40
41 >>> s.makeToast('Hello', False)
42
43 Wait for `Hello, bool:false` message to show up on the screen. Here we
44 provide a Boolean to the RPC, so the value is used instead of using
45 default value.
46
47 >>> s.makeToast('Hello', False, 1)
48
49 Wait for `Hello, bool:false, number: 1` message to show up on the
50 screen. The number is an optional parameter, it only shows up when we
51 pass a value to the RPC.
52