Skip to content
Open
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
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />

<!--Mic audio recording and ?-->
Expand Down Expand Up @@ -62,7 +63,6 @@
android:supportsRtl="true"
android:theme="@style/Theme.App.Starting"
android:hardwareAccelerated="true"
android:clearTaskOnLaunch="true"
android:enableOnBackInvokedCallback="true"
tools:targetApi="33">
<activity
Expand All @@ -75,9 +75,9 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</activity>

Expand Down Expand Up @@ -123,4 +123,4 @@
android:resource="@xml/file_paths" />
</provider>
</application>
</manifest>
</manifest>
596 changes: 562 additions & 34 deletions app/src/main/java/com/msp1974/vacompanion/MainActivity.kt

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions app/src/main/java/com/msp1974/vacompanion/VACAApplication.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
package com.msp1974.vacompanion

import android.app.Application
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import com.msp1974.vacompanion.utils.ActivityManager
import timber.log.Timber
import timber.log.Timber.DebugTree

class VACAApplication: Application() {
companion object {
const val FOREGROUND_CHANNEL_ID = "VACAForegroundServiceChannelId"
const val RECOVERY_CHANNEL_ID = "VACAForegroundRecoveryChannelId"
lateinit var activityManager: ActivityManager
}

override fun onCreate() {
super.onCreate()

activityManager = ActivityManager(this)

Timber.plant(DebugTree())

// Create the notification channel (required for Android 8.0 and above)
val channel = NotificationChannel(
"VACAForegroundServiceChannelId",
val serviceChannel = NotificationChannel(
FOREGROUND_CHANNEL_ID,
"VACA Foreground Service Channel",
NotificationManager.IMPORTANCE_LOW
)
// service provided by Android Operating system to show notification outside of our app
val recoveryChannel = NotificationChannel(
RECOVERY_CHANNEL_ID,
"VACA Foreground Recovery Channel",
NotificationManager.IMPORTANCE_HIGH
).apply {
description = "Brings View Assist Companion back to the foreground after an OS restart"
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
setSound(null, null)
enableVibration(false)
}

val notificationManager =
getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}

companion object {
lateinit var activityManager: ActivityManager
notificationManager.createNotificationChannel(serviceChannel)
notificationManager.createNotificationChannel(recoveryChannel)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,33 @@ import timber.log.Timber

class BootUpReceiver : BroadcastReceiver() {

companion object {
const val EXTRA_BOOT_RECOVERY = "com.msp1974.vacompanion.extra.BOOT_RECOVERY"
}

override fun onReceive(context: Context, intent: Intent) {
if (Intent.ACTION_BOOT_COMPLETED == intent.action && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Timber.d("Received boot completed intent")
if (
intent.action in setOf(
Intent.ACTION_BOOT_COMPLETED,
Intent.ACTION_LOCKED_BOOT_COMPLETED,
"android.intent.action.QUICKBOOT_POWERON",
) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
) {
Timber.d("Received boot intent: ${intent.action}")
val sharedPreferences =
PreferenceManager.getDefaultSharedPreferences(context.applicationContext)
val startOnBoot = sharedPreferences.getBoolean("startOnBoot", false)
if (startOnBoot) {
Timber.d("Starting app")
val activityIntent = Intent(context, MainActivity::class.java)
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activityIntent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_SINGLE_TOP
)
activityIntent.putExtra(EXTRA_BOOT_RECOVERY, true)
context.startActivity(activityIntent)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BroadcastSender {
internal const val SATELLITE_STOPPED = "SATELLITE_STOPPED"
internal const val TOAST_MESSAGE = "TOAST_MESSAGE"
internal const val WEBVIEW_CRASH = "WEBVIEW_CRASH"
internal const val WEBVIEW_SESSION_UNHEALTHY = "WEBVIEW_SESSION_UNHEALTHY"
internal const val VERSION_MISMATCH = "VERSION_MISMATCH"
internal const val REQUEST_MISSING_PERMISSIONS = "REQUEST_MISSING_PERMISSIONS"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ internal class BackgroundTaskController (private val context: Context): EventLis
}
)
}
"uiIdle" -> {
val state = event.newValue as Boolean
server.sendStatus(
buildJsonObject {
putJsonObject("sensors", {
put("ui_idle", state)
})
}
)
}
"motionDetectionSensitivity" -> {
motionTask.setSensitivity(event.newValue as Int)
}
Expand Down Expand Up @@ -364,6 +374,7 @@ internal class BackgroundTaskController (private val context: Context): EventLis
}

is WakeWordEngineProvider.AudioResult.AudioLevel -> {
sendVoiceIndicatorLevel(it.level)
if (config.diagnosticsEnabled) {
sendDiagnostics(it.level, lastWakeWordDetectionScore)
}
Expand All @@ -386,6 +397,7 @@ internal class BackgroundTaskController (private val context: Context): EventLis
engine = null
engineStarted = false
sendDiagnostics(0f, 0f)
sendVoiceIndicatorLevel(0f)
Timber.d("Wake word detection terminated")
}

Expand Down Expand Up @@ -493,6 +505,12 @@ internal class BackgroundTaskController (private val context: Context): EventLis
}
}

fun sendVoiceIndicatorLevel(audioLevel: Float) {
config.eventBroadcaster.notifyEvent(
Event("voiceIndicatorLevel", "", audioLevel.coerceIn(0f, 1f))
)
}


fun shutdown() {
Timber.i("Shutting down")
Expand Down
Loading