This example shows you how to use RpcDefault
and RpcOptional
which is built into Mobly snippet lib to annotate RPC's parameters.
These annotations can be used to specify the default and optional parameters for RPC methods, which allows developers to create more flexible and reusable RPC methods.
Here are some additional benefits of using RpcDefault
and RpcOptional
:
See the source code ExampleDefaultAndOptionalRpcSnippet.java for details.
This folder contains a fully working example of a standalone snippet apk.
Compile the example
./gradlew examples:ex7_default_and_optional_rpc:assembleDebug
Install the apk on your phone
adb install -r ./examples/ex7_default_and_optional_rpc/build/outputs/apk/debug/ex7_default_and_optional_rpc-debug.apk
Use snippet_shell
from mobly to trigger makeToast()
:
snippet_shell.py com.google.android.mobly.snippet.example7 >>> s.makeToast('Hello') Wait for `Hello, bool:true` message to show up on the screen. Here we didn't provide a Boolean to the RPC, so a default value, true, is used. >>> s.makeToast('Hello', False) Wait for `Hello, bool:false` message to show up on the screen. Here we provide a Boolean to the RPC, so the value is used instead of using default value. >>> s.makeToast('Hello', False, 1) Wait for `Hello, bool:false, number: 1` message to show up on the screen. The number is an optional parameter, it only shows up when we pass a value to the RPC.