mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
feat: reopen the app after it updates itself from the Updates page
This commit is contained in:
1 parent
f13c885fec
commit
02f0699b9c
3 files changed
+38
-5
No files matched your search
@@ -135,6 +135,14 @@
|
||||
<service
|
||||
android:name=".core.WirelessAdbPairingService"
|
||||
android:exported="false" />
|
||||
<!-- Takes PackageInstaller's answer to an in-app update and opens the new build. -->
|
||||
<activity
|
||||
android:name=".update.InstallStatusActivity"
|
||||
android:exported="false"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:taskAffinity="${applicationId}.update"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
||||
<!-- Hands a zipped session folder to the share sheet; nothing else is exposed. -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.droiddeck.launcher.update
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageInstaller
|
||||
import android.os.Bundle
|
||||
import com.droiddeck.launcher.MainActivity
|
||||
|
||||
/**
|
||||
* Where PackageInstaller answers an update, invisibly. Android ends the app to replace it and a
|
||||
* receiver can't open it again from the background, but an activity started by the installer's
|
||||
* own answer may: on success this opens the new build. Every answer also goes on to the Updates
|
||||
* page as an [SelfInstaller.ACTION_STATUS] broadcast, for the confirm prompt and the errors.
|
||||
*/
|
||||
class InstallStatusActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)
|
||||
sendBroadcast(Intent(intent).setAction(SelfInstaller.ACTION_STATUS).setComponent(null).setPackage(packageName))
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
startActivity(Intent(this, MainActivity::class.java).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK))
|
||||
}
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,10 @@ import java.net.URL
|
||||
/**
|
||||
* Installs one of DroidDeck's own builds over itself: download into the cache, check the file
|
||||
* against GitHub's sha256, then hand it to PackageInstaller. Android shows its own "Update this
|
||||
* app?" prompt, and the app is restarted on the new build.
|
||||
* app?" prompt, and [InstallStatusActivity] opens the new build once it is in.
|
||||
*/
|
||||
object SelfInstaller {
|
||||
/** The broadcast PackageInstaller answers on; the launcher registers for it while it is open. */
|
||||
/** The broadcast [InstallStatusActivity] passes PackageInstaller's answers on as; the launcher registers for it while it is open. */
|
||||
const val ACTION_STATUS = "com.droiddeck.launcher.update.INSTALL_STATUS"
|
||||
|
||||
/** Android lets an app install packages only once the user allows it in "Install unknown apps". */
|
||||
@@ -72,7 +72,7 @@ object SelfInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
/** Writes [apk] into an install session and commits it; the answer comes as an [ACTION_STATUS] broadcast. */
|
||||
/** Writes [apk] into an install session and commits it; the answer comes to [InstallStatusActivity]. */
|
||||
fun install(context: Context, apk: File) {
|
||||
val installer = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL).apply {
|
||||
@@ -89,9 +89,9 @@ object SelfInstaller {
|
||||
session.fsync(out)
|
||||
}
|
||||
}
|
||||
val status = Intent(ACTION_STATUS).setPackage(context.packageName)
|
||||
val status = Intent(context, InstallStatusActivity::class.java)
|
||||
val flags = PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 0)
|
||||
session.commit(PendingIntent.getBroadcast(context, id, status, flags).intentSender)
|
||||
session.commit(PendingIntent.getActivity(context, id, status, flags).intentSender)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user