Where is that Log? DevUser and Account 1000 on PlayBook

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.

Explore

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 devuser@10.0.1.2
$ 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$

Both blackberry-nativepackager and blackberry-deploy will list you the subcommands they accept if you invoke them without arguments. Check them out!

Posted in PlayBook | Tagged , | 5 Comments

Hello NDK beta 2 – Step by Step

The second beta of the Native SDK is now available at native/beta microsite – the corresponding runtime is 2.0.0.6149 – and this post shows how to compile, package, and install the first Hello Graphics Sample using just the command-line.

Download NDK and Prep Your PlayBook

Point your browser to the download page, and download the SDK.  The bundle includes the full, Eclipse-based, Momentics IDE and is 400MB; in this post I will only use a few command-line commands, but there is no smaller bundle.  Yesterday I encountered some download failures when using Chrome (on MacOS), but Safari worked fine.

The post assumes you have a PlayBook (you can buy one here) so you will not need to download the simulator.

You will need to install the latest 2.0 OS beta on your device as described in Unbox your PlayBook with a 2.0 Twist.  You will also need a debug token an you can follow the instructions in Installing a Debug Token on your PlayBook; the NDK has its own copy of the commands used there: blackberry-debugtokenrequest and blackberry-deploy.

bash-3.2$ blackberry-debugtokenrequest -storepass MYSTOREPASS \
-devicepin MYDEVICEPIN MYDEBUGTOKEN.bar 

bash-3.2$ blackberry-deploy -installDebugToken MYDEBUGTOKEN.bar \
-device MYDEVICEPIN -password MYDEVICEPASS

Note to create a Debug Token you will need RIM to mail you Signed Keys and that currently can take a couple of hours.

Install the NDK

Install the NDK as usual.  I used the default location; in my Mac this was /Developer/SDKs/bbndk-2.0.0-beta2. The NDK includes a bbndk-env.sh file that defines needed shell variables including Makefile flags, PATH, targets, etc. You need to source this file so makes and commands work as desired

source /Developer/SDKs/bbndk-2.0.0-beta2/bbndk-env.sh

Download and Compile the Sample

Next, download the sample you want to use from the NDK Sample Apps.  In this case we will use the first Graphics samples.

Expand the ZIP file into some new directory, navigate to the subdirectory that is pre-arranged to be compiled via a Makefile, and compile the sources via a single make command.

bash-3.2$ unzip HelloNativeSDK.zip
bash-3.2$ cd HelloNativeSDKMakefile
bash-3.2$ make

I’ll skip the verbose output but the result is to compile and load the program. The result is in the x86/ and the arm/ directories.

Package

Next we will take the arm/o.le-v7 objects and we will package that into a bar (the format used for PlayBook applications) using the bar-descriptor.xml. We will also request the bar to be packaged in devMode, and we will sign it using the debugToken we have created previously. The sample also includes an icon for the application that will be used in the home screen.

The complete command is as follows:

blackberry-nativepackager -package out.bar -devMode \
-debugToken MYDEBUGTOKEN.bar \
bar-descriptor.xml -list -listManifest \
-e arm/o.le-v7/HelloNativeSDKMakefile HelloNativeSDKMakefile \
icon.png

I added a -list and a -listManifest flags to the command so you can see what’s created, but that is not necessary. The resulting bar is out.bar.

Added – Elena pointed out than rather than indicate any of the assets to include in the bar, use the BAR descriptor using the -D flag:

blackberry-nativepackager -package out.bar -devMode \
-debugToken MYDEBUGTOKEN.bar \
bar-descriptor.xml -list -listManifest \
-D QNX_TARGET=$QNX_TARGET

Note that if you list any assets in the command line that has precedence over the information in the descriptor, so don’t list any.

Install

Before installing into the PlayBook, remember to put it in Developer Mode, to note its device address, to assign – and remember – a device password, and to upload the same debugToken we used above onto it. All this is described in  Installing a Debug Token on your PlayBook.

And now you are ready, just need to:

blackberry-nativepackager -installApp \
-device MYDEVICEIP -password MYDEVICEPASS \
out.bar

Note that you do not need to connect the device via a USB cable; plain WiFi will work.

And that’s it. You should see something like:

Info: Sending request: Install
Info: Action: Install
Info: File size: 21620
Info: Installing ...
Info: Processing 21620 bytes
actual_dname::com.example.HelloNativeSDKMakefile.testDev_SDKMakefile15be26ac
actual_id::testDev_SDKMakefile15be26ac
actual_version::1.0.0.1
result::success

Test

After this your PlayBook should have the application. Launch it and you will see…

Posted in Native | Tagged , | 11 Comments

News Summary – Dec 12th, 2011

Highlights from recent activity in Open Source projects:

Posted in Weekly | Tagged , , , , , , , | Leave a comment

Announcing Java Sample Repositories

Today we are pleased to announce two new repositories of Open Source code for BlackBerry. We have a repository of Java sample code which includes our BlackBerry JDE Samples from the 7.0 SDK, and a repository of samples previously released through our Knowledge Base. Now these popular code samples are available through the Apache Software License 2.0, which allows developers full access to use them in their applications and extend the samples further.

JDE-Samples

If you aren’t familiar with the samples included in the BlackBerry tools, I’d recommend taking a look sometime if there is an API you are curious about. There are 100+ samples included which cover each major API. Our JDE-Samples repository will include these samples for each version of the SDK.

This repository uses Git’s very good support of branches (e.g. see Pro Git’s Chapter 3), to keep the samples for all the JDE releases in the same directory.  For example, the in-device samples for JDE 4.6.1 are here.  There are currently 8 branches, plus the master branch.  There are also 8 tags; one per each of these branches.

Samples-for-Java

Our Samples-for-Java repository includes five sample applications today and we will continue to add more in the future. The massively popular Advanced UI sample, with it’s many containers and components is included. The KB article for this sample shows some example screenshots so you can see what it can do. We’ve also included the Simple Location API, the Titlebar API, and sample apps for Analytics and a YouTube client. Read on for more details on these samples.

Advanced UI: If you have ever wanted to take your UI designs further this is the first place to look. There are several button extensions included, allowing you to use Bitmaps for buttons, or to do Embossed buttons, create hyperlinks and button lists. There are also toggle switches, sliders, ratings, and pill buttons ready to use in your applications. Advanced managers allow you to quickly do new layouts, like justified horizontal and vertical layouts, or 2 column screens. Finally, progress animations and bitmap gauge fields add polish to your UI.

Addional details and more screenshots like the one to the right, in “Implement advanced buttons, fields, and managers“.

Simple Location API: Using GPS is not always the easiest task. This code aims to change that for when you just want location information. It automatically handles carrier and device hardware support differences and battery usage concerns.

More details in the KB article: “Simple Location API“.

Titlebar API: Many different applications have a need for consistent system displays in their application. Basics like network coverage, the time, or the name of an application are desirable standards for an application to display at the top of the screen. In the 6.0 SDK the Titlebar API was created for this, but there are still plenty of 5.0 devices out there, and some of us need to support some of the 4.x code lines as well. This library attempts to port that 6.0 Titlebar API back as far as the 4.2.1 SDK. A preprocessor based wrapper allows you to code with one Titlebar class and build with any version of the SDK from 4.2.1 through 7.1.

The full KB article including images is “How To Implement a TitleBar with Signal Strength, Battery Level, Icon, Unread mail and Clock

Analytics Sample: This sample implements each of the BlackBerry Analytics SDK methods so you have a handy reference. If you sign up for the service this sample is included in the SDK download, but with it open sourced we can continue to expand on it.

YouTube Client: Originally published to both our blog and YouTube’s blog, this sample shows you to work with the YouTube Data API using the very convenient BlackBerry Communication API from the 6.0 SDK. It’s a great starting point for either API or if you are doing a quick proof of concept with YouTube interaction. Further details in the KB: “How to – Create a YouTube viewer with the BlackBerry 6 Communication API

Check them out and see where the code takes you!

Posted in Java | Tagged , | 1 Comment

NFC Support in WebWorks

Support for Near Field Communications (NFC – Wikipedia, NFC Forum) was added this week to the WebWorks-Community-APIs repository.  The work comes from Martin Woolley and John Murray, in the DevRel team.

Martin and John are also authors for a series of three articles on the topic:

A number of recent RIM announcements have addressed the importance of NFC support in BlackBerry smartphones.  See for instance, this press release from October 26th, 2011.

I hope to find time next week to post a more detailed piece expanding on the new functionality.

Posted in HTML5 | Tagged , , | 2 Comments

Contributions to Apache

The Apache Software Foundation uses Contribution Agreements to “clearly define the terms under which intellectual property has been contributed to the ASF”.  There are two variants of the CLA, the ICLA for individuals, and the CCLA for corporations.

RIM recently signed the CCLA and this will enable us to contribute to projects like Apache Cordova (aka Callback, aka PhoneGap).  We also have a few other (smaller) contributions in the pipeline related to improved BBX support for several Apache projects.

As with other Open Source activities, we will post updates in this forum.

Posted in Uncategorized | Tagged | Leave a comment

Update on Apache Cordova (aka Callback, aka PhoneGap)

Back in March, myself and three other intrepid BlackBerry employees made the trek to Vancouver to work with the folks at Nitobi to bring BlackBerry PlayBook support to the PhoneGap project.  Much code was written, some food and beverage was consumed, and at the end of the three days, a large portion of the code was created to support PlayBook.  The code required a bit of cleanup, and some automated tests still needed to be put into place.  With a busy summer, this took a tad longer than expected, but Nitobi and the PhoneGap project as a whole also had a busy summer and fall.

As some will be aware, PhoneGap was contributed to the Apache foundation as the Callback incubator project.  Further, Nitobi was acquired by Adobe.  Yet the good folks at the company-previously-known-as-Nitobi have continued to push forward, and BlackBerry remains firmly committed to being involved in this important community.

With a newly minted and signed Apache CLA in hand, Gord Tanner (@gordtanner) and myself returned to Vancouver with a few goals in mind.  With the help of Michael Brooks (@mwbrooks), the support for PlayBook is now merged in to the main Callback repository and is ready for the next official release!  Perhaps as interesting was the prototype code Gord brought for a proposed architecture that would enable a common phonegap.js file for all platforms that Callback supports.  This work was well received, and it was pulled into an official Callback repo where this exploratory work will be pushed forward.  We encourage everyone to check out the work in GitHub, and even see how you can also get involved.

Posted in HTML5 | Tagged , , , , , | 2 Comments

Announcing a new Qt codedrop for the BlackBerry PlayBook

I’m pleased to announce a new code drop today in our public github repository for the BlackBerry PlayBook port of the Qt toolkit. This new drop features many fixes, features and improvements over the initial one that was released at DevCon in October.

The first main improvement is general stability; lots of crashes have been fixed and the new code should work properly on the PlayBook simulator as well as on the actual device.

Secondly, an experimental fully OpenGLES2-backed rendering architecture has been implemented and can be enabled at runtime. This can be done by setting the environment variable QBB_USE_OPENGL to 1 before launching your app. Please note that this is very immature right now.

Finally, the XmlPatterns module, conspicuously not present in the previous drop, is now built by default.

We have also taken the opportunity to rebase our branch on top of the upstream 4.8 branch maintained by Nokia, and this is why we had to create a new branch for this new drop, as history has been rewritten.

And last but not least, many thanks to all the community members who have been working with us and submitting bug reports and patches – your feedback is what makes open source so great, and we look forward to hearing any suggestions you have in the future!

Posted in Native | Tagged , | 23 Comments

NDK 2.0 Beta Now Available

The first beta of the Native SDK for the BlackBerry ® PlayBook™ is now available.

Check out:

Note the last link: you have to re-register your PlayBook even if you did it previously.  The upgrade window is only for 24 hours after registering so you can downgrade later to a 1.0* release if you want to.  Also note that as of this writing, the NDK samples at GitHub are still for PlayBook 1, not PlayBook 2.

This release has many new features including the Scoreloop SDK 1.0 beta 1 release.  Check out the Release Notes for full details.

Posted in Native | Tagged , | Leave a comment

Community Project on Python on the PlayBook

QNX’s support of POSIX is proving to be really helpful in porting functionality to the PlayBook (and later BBX).  One area in point is Python (wikipediahome site) .

PlayBook 2.0 already includes the Python 3.2 runtime but Peter Hansen has started an exploratory project to make it possible to create PlayBook Applications using Python.

Peter has been documenting the effort so far in his blog, and also created a project site for the code:

The latest additions to bbx-python include some demos (WAV playback, GPS logging).  Overall, very good progress in very short time.  I’ll provide more updates as they occur.

And, if you are interested in contributing to the topic, drop a note to Peter (@peter9477); Rob Paskowitz already has expressed some interest and the more the merrier.

Posted in Uncategorized | Tagged | 5 Comments