Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ android/key.properties
# build outputs / release artifacts
dist/
*.apk
/apk

# Local-only dependency overrides (sibling path linking); never commit.
pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BootReceiver : BroadcastReceiver() {
action != "android.intent.action.QUICKBOOT_POWERON") return

if (!hasPairedDevice(context)) return
markPendingHeadlessBoot(context)

val svcIntent = Intent(context, EdgeTrackingService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Expand All @@ -47,4 +48,12 @@ class BootReceiver : BroadcastReceiver() {
val id = prefs.getString("flutter.paired_remote_id", null)
return !id.isNullOrEmpty()
}

private fun markPendingHeadlessBoot(context: Context) {
val prefs: SharedPreferences = context.getSharedPreferences(
"openstrap_runtime",
Context.MODE_PRIVATE
)
prefs.edit().putBoolean("pending_headless_boot", true).apply()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package wtf.openstrap.openstrap_edge

import android.content.Context
import android.os.Bundle
import io.flutter.embedding.android.FlutterFragmentActivity

/**
Expand All @@ -17,6 +19,38 @@ import io.flutter.embedding.android.FlutterFragmentActivity
* FragmentActivity host. The cached-engine overrides work the same on either base.
*/
class MainActivity : FlutterFragmentActivity() {
companion object {
@Volatile
var activityAttached: Boolean = false
}

override fun getCachedEngineId(): String = EdgeApplication.ENGINE_ID
override fun shouldDestroyEngineWithHost(): Boolean = false

override fun onCreate(savedInstanceState: Bundle?) {
activityAttached = true
clearPendingHeadlessBoot()
super.onCreate(savedInstanceState)
}

override fun onStart() {
super.onStart()
activityAttached = true
clearPendingHeadlessBoot()
}

override fun onStop() {
activityAttached = false
super.onStop()
}

private fun clearPendingHeadlessBoot() {
val prefs = applicationContext.getSharedPreferences(
"openstrap_runtime",
Context.MODE_PRIVATE
)
if (prefs.getBoolean("pending_headless_boot", false)) {
prefs.edit().putBoolean("pending_headless_boot", false).apply()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ object NativeChannels {
app.stopService(Intent(app, EdgeTrackingService::class.java))
result.success(null)
}
"consumeHeadlessBootPending" -> {
val prefs = app.getSharedPreferences(
"openstrap_runtime",
Context.MODE_PRIVATE
)
val pending = prefs.getBoolean("pending_headless_boot", false)
val eligible = pending && !MainActivity.activityAttached
if (eligible) {
prefs.edit().putBoolean("pending_headless_boot", false).apply()
}
result.success(eligible)
}
else -> result.notImplemented()
}
}
Expand Down
Loading