Skip to content

Commit

Permalink
Remove foreground service requirements and change debug log behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rken committed Sep 14, 2024
1 parent f30fb13 commit 75f203c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 159 deletions.
19 changes: 3 additions & 16 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission
android:name="android.permission.FOREGROUND_SERVICE"
tools:node="remove" />

<application
android:name="eu.darken.octi.App"
Expand Down Expand Up @@ -60,23 +60,10 @@
android:resource="@xml/battery_widget_info" />
</receiver>

<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />

<!-- Debug stuff-->
<activity
android:name="eu.darken.octi.common.debug.recording.ui.RecorderActivity"
android:theme="@style/AppThemeFloating" />

<service
android:name="eu.darken.octi.common.debug.recording.core.RecorderService"
android:foregroundServiceType="specialUse">
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="This service is part of a bug reporting mechanism. It is explicitly launched by the user to create debug logs and troubleshoot issues within Octi itself. It shows an on-going foreground notification that allows the user to control the debug log functionality while the debug log is being created and the user is reproducing the issue." />
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.logging.logTag
import eu.darken.octi.common.debug.recording.ui.RecorderActivity
import eu.darken.octi.common.flow.DynamicStateFlow
import eu.darken.octi.common.startServiceCompat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
Expand Down Expand Up @@ -57,11 +56,7 @@ class RecorderModule @Inject constructor(
newRecorder.start(createRecordingFilePath())
triggerFile.createNewFile()

context.startServiceCompat(Intent(context, RecorderService::class.java))

copy(
recorder = newRecorder
)
copy(recorder = newRecorder)
} else if (!shouldRecord && isRecording) {
val currentLog = recorder!!.path!!
recorder.stop()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package eu.darken.octi.main.ui.settings.support

sealed interface SupportEvent {
data object DebugLogInfo : SupportEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.annotation.Keep
import androidx.fragment.app.viewModels
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import eu.darken.octi.R
import eu.darken.octi.common.ClipboardHelper
Expand Down Expand Up @@ -35,31 +34,37 @@ class SupportFragment : PreferenceFragment2() {

override fun onPreferencesCreated() {
debugLogPref.setOnPreferenceClickListener {
MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(R.string.support_debuglog_label)
setMessage(R.string.settings_debuglog_explanation)
setPositiveButton(R.string.general_continue) { _, _ -> vm.startDebugLog() }
setNegativeButton(R.string.general_cancel_action) { _, _ -> }
setNeutralButton(R.string.settings_privacy_policy_label) { _, _ -> webpageTool.open(PrivacyPolicy.URL) }
}.show()
vm.toggleDebugLog()
true
}
super.onPreferencesCreated()
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
vm.clipboardEvent.observe2(this) { installId ->
Snackbar.make(requireView(), installId, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.general_copy_action) {
clipboardHelper.copyToClipboard(installId)
vm.isRecording.observe2(this) {
debugLogPref.apply {
if (it != null) {
setIcon(R.drawable.ic_bug_stop_24)
setTitle(R.string.support_debuglog_inprogress_label)
summary = it.path
} else {
setIcon(R.drawable.ic_baseline_bug_report_24)
setTitle(R.string.support_debuglog_label)
setSummary(R.string.support_debuglog_desc)
}
.show()
}
}

vm.emailEvent.observe2(this) { startActivity(it) }

vm.isRecording.observe2(this) {
debugLogPref.isEnabled = !it
vm.events.observe2(this) {
when (it) {
SupportEvent.DebugLogInfo -> MaterialAlertDialogBuilder(requireContext()).apply {
setTitle(R.string.support_debuglog_label)
setMessage(R.string.settings_debuglog_explanation)
setPositiveButton(R.string.general_continue) { _, _ -> vm.toggleDebugLog(consent = true) }
setNegativeButton(R.string.general_cancel_action) { _, _ -> }
setNeutralButton(R.string.settings_privacy_policy_label) { _, _ -> webpageTool.open(PrivacyPolicy.URL) }
}.show()
}
}

super.onViewCreated(view, savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package eu.darken.octi.main.ui.settings.support

import android.content.Intent
import dagger.hilt.android.lifecycle.HiltViewModel
import eu.darken.octi.common.coroutine.DispatcherProvider
import eu.darken.octi.common.debug.logging.log
import eu.darken.octi.common.debug.recording.core.RecorderModule
import eu.darken.octi.common.livedata.SingleLiveEvent
import eu.darken.octi.common.uix.ViewModel3
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import javax.inject.Inject

Expand All @@ -16,13 +16,22 @@ class SupportFragmentVM @Inject constructor(
private val recorderModule: RecorderModule,
) : ViewModel3(dispatcherProvider) {

val emailEvent = SingleLiveEvent<Intent>()
val clipboardEvent = SingleLiveEvent<String>()
val isRecording = recorderModule.state.map { it.currentLogPath }.asLiveData2()

val isRecording = recorderModule.state.map { it.isRecording }.asLiveData2()
val events = SingleLiveEvent<SupportEvent>()

fun startDebugLog() = launch {
log { "startDebugLog()" }
recorderModule.startRecorder()
fun toggleDebugLog(consent: Boolean = false) = launch {
log { "toggleDebugLog()" }
recorderModule.apply {
if (state.first().isRecording) {
stopRecorder()
} else {
if (consent) {
startRecorder()
} else {
events.postValue(SupportEvent.DebugLogInfo)
}
}
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_bug_stop_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19 7H16.19C15.74 6.2 15.12 5.5 14.37 5L16 3.41L14.59 2L12.42 4.17C11.96 4.06 11.5 4 11 4S10.05 4.06 9.59 4.17L7.41 2L6 3.41L7.62 5C6.87 5.5 6.26 6.21 5.81 7H3V9H5.09C5.03 9.33 5 9.66 5 10V11H3V13H5V14C5 14.34 5.03 14.67 5.09 15H3V17H5.81C7.26 19.5 10.28 20.61 13 19.65V19C13 16.46 14.61 14.2 17 13.35V13H19V11H17V10C17 9.66 16.97 9.33 16.91 9H19V7M13 15H9V13H13V15M13 11H9V9H13V11M16 16H22V22H16V16Z" />
</vector>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
<string name="discord_label">Discord</string>
<string name="discord_description">A place to hang out in and ask questions.</string>

<string name="support_debuglog_label">Debug log</string>
<string name="support_debuglog_label">Record debug log</string>
<string name="support_debuglog_inprogress_label">Stop debug log</string>
<string name="support_debuglog_desc">Record everything the app is doing into a text file that you can share.</string>
<string name="settings_support_label">Support</string>
<string name="debug_debuglog_sensitive_information_message">This file contains sensitive information (e.g. your installed applications). Only share it with trusted parties.</string>
Expand Down

0 comments on commit 75f203c

Please sign in to comment.