Updater: Allow starting activities from background

-----

05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: FATAL EXCEPTION: main
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: Process: com.shiftos.updater, PID: 19707
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.shiftos.updater/org.lineageos.updater.controller.UpdaterService }: app is in background uid UidRecord{1463ce2 u0a63 TPSL bg:+47m50s26ms idle change:idle procs:1 seq(0,0,0)}
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1616)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.ContextImpl.startService(ContextImpl.java:1571)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.content.ContextWrapper.startService(ContextWrapper.java:669)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at org.lineageos.updater.UpdatesActivity.onStart(UpdatesActivity.java:181)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1433)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.Activity.performStart(Activity.java:7847)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3295)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:107)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:214)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7397)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
05-06 17:21:58.988 10063 19707 19707 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)

-----

Change-Id: Ibc2d471b028c1d4e824b3ede4bbc336d76801f88
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
2 files changed
tree: f24a7353b31ddf5f41df9d980fe40f1c5c1cb081
  1. res/
  2. src/
  3. .gitignore
  4. Android.bp
  5. AndroidManifest.xml
  6. build.gradle
  7. gen-keystore.sh
  8. gradle.properties
  9. keystore.properties.sample
  10. privapp_whitelist_org.lineageos.updater.xml
  11. proguard.flags
  12. push-update.sh
  13. README.md
README.md

Updater

Simple application to download and apply OTA packages.

Server requirements

The app sends GET requests to the URL defined by the updater_server_url resource (or the lineage.updater.uri system property) and expects as response a JSON with the following structure:

{
  "response": [
    {
      "datetime": 1230764400,
      "filename": "ota-package.zip",
      "id": "5eb63bbbe01eeed093cb22bb8f5acdc3",
      "romtype": "nightly",
      "size": 314572800,
      "url": "https://example.com/ota-package.zip",
      "version": "15.1"
    }
  ]
}

The datetime attribute is the build date expressed as UNIX timestamp.
The filename attribute is the name of the file to be downloaded.
The id attribute is a string that uniquely identifies the update.
The romtype attribute is the string to be compared with the ro.lineage.releasetype property.
The size attribute is the size of the update expressed in bytes.
The url attribute is the URL of the file to be downloaded.
The version attribute is the string to be compared with the ro.lineage.build.version property.

Additional attributes are ignored.

Build with Android Studio

Updater needs access to the system API, therefore it can't be built only using the public SDK. You first need to generate the libraries with all the needed classes. The application also needs elevated privileges, so you need to sign it with the right key to update the one in the system partition. To do this:

  • Place this directory anywhere in the Android source tree
  • Generate a keystore and keystore.properties using gen-keystore.sh
  • Build the dependencies running make UpdaterStudio from the root of the Android source tree. This command will add the needed libraries in system_libraries/.

You need to do the above once, unless Android Studio can't find some symbol. In this case, rebuild the system libraries with make UpdaterStudio.