A TV application that plays live TV content is required for Android TV devices. A reference TV application (Live TV) is provided alongside the Android platform, which can be used as-is, customized, extended, or replaced. The source code is available in the Android Open Source Project.

This article summarizes how to build and customize a system TV App based on Live TV for your Android television device. (You may extend your TV application to implement device manufacturer or country-specific features, however this is not in the scope of the reference TV App.)

Dependencies

The TV application is a component of the TV Input Framework (TIF) and cannot be used independently of the other components. This means that only devices with TIF will be able to run the Live TV application.

The Live TV application depends on Android APIs. Different branches have different dependencies on API levels:

Table 1. Live TV branches.

Branch Target API level Minimum API level
master 24 (Android 7.0) 23
android-live-tv 23 (Android 6.0) 21
android-live-tv-l-mr1 22 (Android 5.1) 21

Get the source

To get started, select which version of Live TV you’d like from Git. The instructions below are for the current version of Live TV, but you can easily select an earlier version by changing the branch from master to a different one listed in the table above.

mkdir live-tv && cd live-tv
repo init -u https://android.googlesource.com/platform/manifest -b master
repo sync -j8 -c

Build

To build the Live TV code, run:

. build/envsetup.sh
tapas LiveTv x86
make LiveTv

Push

To push Live TV to your test device:

adb install -r -d $OUT/system/priv-app/LiveTv/LiveTv.apk

If the developer wants the LIVE TV app to have system permissions, the first time it is installed it needs to be pushed to /system/priv-app with:

adb push $OUT/system/priv-app/LiveTv/LiveTv.apk  /system/priv-app/LiveTv/

Test

Once Live TV is on your device, you should test that it is properly integrated. In addition to running the Compatibility test suite and the CTS Verifier tests for the TV app, you can use these tests below:

Unit tests

There are unit and functional tests for the Live TV app. You must have a device (or emulator) connected to run the tests.

adb shell logcat -c
m LiveTv TVTestInput TVUnitTests -j20 &&\
adb install -r -d $OUT/system/priv-app/LiveTv/LiveTv.apk &&\
adb install -r -d $OUT/system/app/TVTestInput/TVTestInput.apk && \
adb install -r -d $OUT/data/app/TVUnitTests/TVUnitTests.apk && \
adb shell pm clear com.android.providers.tv && \
adb shell pm clear com.google.android.tv && \
adb shell am instrument \
  -e testSetupMode unit \
  -w com.android.tv.testinput/.instrument.TestSetupInstrumentation &&\
adb shell input keyevent KEYCODE_HOME &&\
adb shell am instrument \
  -w 'com.android.tv.tests/android.support.test.runner.AndroidJUnitRunner'

Functional Tests

adb shell logcat -c
m LiveTv TVTestInput TVFuncTests -j20 &&\
adb install -r -d $OUT/system/priv-app/LiveTv/LiveTv.apk &&\
adb install -r -d $OUT/system/app/TVTestInput/TVTestInput.apk && \
adb install -r -d $OUT/data/app/TVFuncTests/TVFuncTests.apk && \
adb shell pm clear com.android.providers.tv && \
adb shell pm clear com.google.android.tv && \
adb shell am instrument \
  -e testSetupMode func \
  -w com.android.tv.testinput/.instrument.TestSetupInstrumentation &&\
adb shell input keyevent KEYCODE_HOME &&\
adb shell am instrument \
  -w 'com.android.tv.tests.ui/android.support.test.runner.AndroidJUnitRunner'

Jank Tests

The Jank tests look for dropped frames and delays in rendering.

adb shell logcat -c
m LiveTv TVTestInput TVJankTests -j20 &&\
adb install -r -d $OUT/system/priv-app/LiveTv/LiveTv.apk &&\
adb install -r -d $OUT/system/app/TVTestInput/TVTestInput.apk &&\
adb install -r -d $OUT/data/app/TVJankTests/TVJankTests.apk &&\
adb shell pm clear com.android.providers.tv &&\
adb shell pm clear com.google.android.tv &&\
echo "Creating a lot of channels and EPG data, this may take a while" &&\
adb shell am instrument \
  -e testSetupMode jank \
  -w com.android.tv.testinput/.instrument.TestSetupInstrumentation &&\
adb shell input keyevent KEYCODE_HOME &&\
adb shell am instrument \
  -w 'com.android.tv.tests.jank/android.support.test.runner.AndroidJUnitRunner'