PlayBook applications run in sandboxes, each one with holding files, data base, other data… and also the exit code and the log file for the latest execution of the application, all nicely protected using QNX. Our IDE (formally QNX® Momentics IDE for BlackBerry® Native SDK for Tablet OS) knows how to talk to the PlayBook to get at these resources but you can also use NDK command-line commands, and this post will help you get started using several of them.
For concreteness, I’ll use the AudioControl sample (Samples Page or direct ZIP) – the application queries the PlayBook for audio control settings and shows the result on the log file for the application. This post shows how to access that log, first the slow way… then the fast way.
Note: The instructions assume you have installed a DebugToken into your PlayBook.
Prep Work: Install the Application
Start by downloading the latest NDK 2 (beta 2 as of this writing) so we can use its command tools. The NDK includes a handy script to set important environment variables, on my mac this looks like:
bash-3.2$ source /Developer/SDKs/bbndk-2.0.0-beta2/bbndk-env.sh
Next, unzip that AudioControl sample and open a terminal window on the
AudioControlMakefile subdirectory. You can now compile using
make, and then package and install using
blackberry-nativepackager. As described in the Elena-improved version of NDK2 – Step by Step, you can rely on the local
bar-descriptor.xml to describe all the assets and you only need to define externally the variable
QNX_TARGET. The result is:
bash-3.2$ make bash-3.2$ blackberry-nativepackager -package out.bar \ -devMode -debugToken MYDEBUGTOKEN\ bar-descriptor.xml -list -listManifest\ -D QNX_TARGET=/Developer/SDKs/bbndk-2.0.0-beta2/target/qnx6 bash-3.2$ blackberry-nativepackager -installApp \ -device DEVICEIP -password DEVICEPASSWD\ out.bar
Enable SSH Access
For safety, you cannot just ssh (yes, there is a wikipedia page for ssh) into your PlayBook. You start the SSH daemon using the
blackberry-connect program to physically (well, WiFi works) connect into the PlayBook, which must be in Developer Mode, provide the password to the device, and provide your RSA-4096 public key. The daemon is active only while
blackberry-connect is running, and will only accept connections that authenticate against that key.
Added: On Unix machines the desired key can be generated and can be installed in the default location with the command:
% ssh-keygen -b 4096 -t rsa
Start the blackberry-connect command… and leave it running!
bash-3.2$ blackberry-connect DEVICEIP \ -password DEVICEPASSWD \ -sshPublicKey ~/.ssh/id_rsa.pub Info: Connecting to target 10.0.1.2:4455 Info: Authenticating with target 10.0.1.2:4455 Info: Encryption parameters verified Info: Authenticating with target credentials. Info: Successfully authenticated with target credentials. Info: Sending ssh key to target 10.0.1.2:4455 Info: ssh key successfully transferred. Info: Successfully connected. This application must remain running in order to use debug tools. Exiting the application will terminate this connection.
Now you can ssh into the device. You will need to ssh using the
devuser login, which grants you enough privileges to be a productive developer, but not enough to get you into trouble.
You can safely explore around:
bash-3.2$ ssh email@example.com $ pwd /accounts/devuser $ ls /accounts 1000 devuser $ cd /accounts/1000 $ ls -F appdata/ db/ sys/ certificates/ pimdata/ sysdata/ clipboard/ shared/ $ ls -ldg appdata/com.example.* ls -d appdata/com.example.* appdata/com.example.AudioControlMakefile.testDev_rolMakefilee6ce75a2 .... appdata/com.example.VideoPlaybackMakefile.testDev_ackMakefileaa3c64ef
The Log Output
Finally, back to that log file. Go to the sandbox for AudioControl and it is there:
$ cd com.example.AudioControlMakefile.testDev_rolMakefilee6ce75a2 $ cat logs/log Audio Mixer Status Headphone Volume: 53.360001 Speaker Volume: 53.360001 Input Gain: 100.000000 Headphone Muted: False Speaker Muted: False Input Muted: False Audio Mixer Event Headphone Volume: 53.360001 Speaker Volume: 53.360001 Input Gain: 100.000000 Headphone Mute: False Speaker Mute: False Input Mute: False Available Output Channel: Headphones
BlackBerry-Deploy – a Swiss Army Knife
That was the “slow” – but most informative – way to get at the log file; as promised, there is a faster way, using the
blackberry-deploy command. This command provides a shortcuts for many common operations, including a way to retrieve a file from the sandbox, so, in this particular case, once you know that the name of the log file is logs/log, you can extract it directly using
-getFile as shown below:
bash-3.2$ blackberry-deploy -getFile logs/log /tmp/mylog \ -device MYDEVICEIP -password MYDEVICEPASSWD out.bar Info: Sending request: Get File Info: Action: Get File Info: Package com.example.AudioControlMakefile.testDev_rolMakefilee6ce75a2 Info: Asset Path logs/log Info: Sending File: 353 Info: File saved: /tmp/mylog bash-3.2$ cat /tmp/mylog Audio Mixer Status Headphone Volume: 53.360001 Speaker Volume: 53.360001 Input Gain: 100.000000 Headphone Muted: False Speaker Muted: False Input Muted: False Audio Mixer Event Headphone Volume: 53.360001 Speaker Volume: 53.360001 Input Gain: 100.000000 Headphone Mute: False Speaker Mute: False Input Mute: False Available Output Channel: Headphones bash-3.2$
blackberry-deploy will list you the subcommands they accept if you invoke them without arguments. Check them out!