Android Debugging, Troubleshooting, and Sharing


Android Versions or “APK Types”

First, there are three versions of the Android app for any given release:

  1. Google Play Production (SMS Disabled)
  2. (Non-Google Play) “Standard” Production (SMS Enabled)
  3. Training (SMS & Debugging Enabled)

Below are some key details of each.

Google Play

  • No Debugging
  • No SMS
  • Screenshot/ screen sharing opt-in via settings

The google play store APK does NOT support any sending of SMS. This is because there has been an ongoing issue with Google not allowing it in the store. Otherwise the in-app functionality is all there.

However, this APK is not available to connect to debugging software since it would open up security issues for tablets that are lost/stolen.

Standard

  • No Debugging
  • SMS Enabled
  • Screenshot/ screen sharing opt-in via settings

The so-called “Standard APK” is the APK that is released via github and can be downloaded and installed a particular device.

This type DOES have the full SMS module installed but does not have debugging capabilities.

Training

  • Increased Security Implications
  • Full SMS Enabled
  • Full Debugging Enabled
  • Screenshots/screen sharing Allowed by Default

The training APK comes with full SMS capabilities, as well as the pre-configured code for accessing network requests and logs via Flipper: https://fbflipper.com/

Like the “Standard APK” the training APK must be downloaded via the android git repository.

Flipper - https://fbflipper.com/

Flipper could probably use its own write up but until there is a greater need this should suffice.

Flipper is a platform for debugging iOS, Android and React Native apps. Visualize, inspect, and control your apps from a simple desktop interface. Use Flipper as is or extend it using the plugin API.

Flipper is “plugin-based” and comes with a few “built-ins” that cover most if not everything that we need as debuggers (as opposed to developers).

  • Device needs to have USB Debugging Enabled (system settings > software info > click “build number” 7 times).
  • Training APK for DHIS2 needs to be used for debugging
  • Android Studio needs to be open and connected to device (device manager - select device, make sure to click “allow” on device when prompted for usb debugging) (see below)

Screen Sharing From Computer - SCRCPY

https://github.com/Genymobile/scrcpy

Pronounced “Screen Copy”

SCRCPY allows you to control your phone or tablet from a computer as well as offering a faster way of input via the keyboard when working in the android app.

UiO’s Jaime Bosque wrote this guide a while ago:

https://community.dhis2.org/t/how-to-clone-your-android-screen-useful-for-presentations-debugging-etc/38077

Emulator Scripts

These scripts help to deploy stand-alone emulators on your computer using Android Studio but without loading the interface which is a “heavy” operation. In order to use you’ll need save this to an executable and update the paths.

##### emulator choose #####

-#!/bin/bash

cd /home//Android/Sdk/emulator
echo "Choose one from the available emulators..."

select emulator in `./emulator -list-avds`; do
./emulator -avd $emulator
exit

done

##### install passed APK from command line uninstalling previous versions ######

#!/bin/bash

# Remove a previous package of DHIS 2 (training or release) and install the passed one
# Get file information
APK=$1
extension="${APK##*.}"

if [ $extension != "apk" ]; then
    echo "Provided file is not an APK"
    echo "Exiting"
    exit 1
else
    echo "Provided file is an APK"
    `file $APK | grep -q "release"`
    if [ $? -eq 0 ]; then
        echo "Release APK was passed as an argument"
        adb shell pm list packages | grep -q 'com.dhis2$'
        if [ $? -eq 0 ]; then
            echo "  Release package is already installed... deleting"
            adb uninstall com.dhis2
        else
            echo "  No previous release package detected"
        fi
        echo "Installing release package"
        adb install $APK
    else
        echo "Training APK was passed as an argument"
        adb shell pm list packages | grep -q 'com.dhis2.debug$'
        if [ $? -eq 0 ]; then
            echo "  Training package is already installed... deleting"
            adb uninstall com.dhis2.debug
        else
            echo "  No previous training package detected"
        fi
        echo "Installing training package"
        adb install $APK
    fi  
fi