How to update your Android device using Barracks – Part 2

Today’s part, will be more about classical Android devices with a User Interface than Android Things. Let’s digg into it:

Providing users with a feedback

In our first post for this series, I explained how to silently wake up your updater and download Android updates from Barracks. As we are talking about Android based devices, it may be nice to provide the users with a nice feedback if your devices has a screen, and therefore try to avoid the following experience 😉

your-pc-will-automatically-restart-in-1-minute-600x140

Add your application to the settings

The first thing you’ll want to do is making sure your app is opened when the user will select the System updates menu:

screenshot_20161129-092700

Something you may not be aware of : if you are using any vanilla Android device with Google Play Services installed, the system updates are provided by the Play Services, including the UI. If you are brave enough to decompile the Play Services APK (you hacker !), you’ll find the magic lines :

The interesting part is the intent-filter, this is how the System settings application finds out which activity to launch when the user presses the System updates menu entry. As your application will compete with the Google Play Services for handling this intent, I suggest that you update the android:priority attribute with a high value (999 being the max value):

With this setup, your activity will be started and you will be able to display the appropriate content for updating you device.

Display a notification

As we have already dealt with checking for updates and downloading these updates, it is now time to make sure we notify the user about the availability of an update. In order to do so, you’ll have to add some code in the UpdateCheckCallback.onUpdateAvailable method to display a notification in the status bar. This is an example, which will display a notification, leading to the activity you previously added for handling the system updates intent:

Show download progress

If you reached this section, you’ve achieved the largest part of the UI job !

The last part will be about displaying a progress when downloading the update. Our SDK offers a helper, which gives a very straight forward method for downloading the software update, and you have multiple ways of dealing with the progress. The simplest one being using the onDownloadProgress from the helper:

A more advanced way would be to listen to local broadcasts sent by the Barracks SDK:

Conclusion

In this post, you’ve seen how to handle the visible part of the update process, giving you the opportunity to provide feedback to the user through an adequate UI. You also know how to properly hook your update activity into the system settings.

The last part will be a little bit hairy, as we will discuss permissions, ROM cooking and calling not so documented Android APIs.