Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
Closes #432
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed May 3, 2022
1 parent f06db17 commit a9c6a9a
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 67 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.crazylegend.vigilante"
minSdkVersion 24
targetSdkVersion 32
versionCode 17
versionName "1.2.4"
versionCode 18
versionName "1.2.5"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -74,7 +74,7 @@ dependencies {
//core
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.fragment:fragment-ktx:1.5.0-beta01'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation "androidx.startup:startup-runtime:1.1.1"

Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/com/crazylegend/vigilante/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.crazylegend.kotlinextensions.misc.requestBatteryOptimizations
import com.crazylegend.kotlinextensions.power.isIgnoringBatteryOptimization
Expand All @@ -20,10 +19,7 @@ import dagger.hilt.android.AndroidEntryPoint
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
applyOverrideConfiguration(Configuration())
}
override fun attachBaseContext(newBase: Context?) { super.attachBaseContext(newBase?.let { LocaleHelper.onAttach(it) })}

override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
super.applyOverrideConfiguration(overrideConfiguration?.let {
Expand All @@ -35,7 +31,7 @@ class MainActivity : AppCompatActivity() {

private val navController: NavController
get() =
binding.navHostContainer.getFragment<NavHostFragment>().navController
binding.navHostContainer.getFragment<NavHostFragment>().navController

override fun onSupportNavigateUp() = navController.navigateUp()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.coroutines.CoroutineContext
interface ServiceLifecycle : LifecycleOwner, LifecycleEventObserver {

val coroutineContext: CoroutineContext
get() = Dispatchers.Main
get() = Dispatchers.Main.immediate

val scope: CoroutineScope
get() = CoroutineScope(coroutineContext + SupervisorJob())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class CrashFragment : AbstractFragment<LayoutRecyclerBinding>(R.layout.layout_re
uiAction { shareCrash(item) }
}
}
crashesAdapter.onLongClickListener = {position, _, _ ->
onUnableToCopyCrash(position)
}
}

private fun onUnableToCopyCrash(position: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.crazylegend.vigilante.di.modules.coroutines.appScope

import com.crazylegend.vigilante.di.modules.coroutines.dispatchers.DefaultDispatcher
import com.crazylegend.vigilante.di.modules.coroutines.dispatchers.MainImmediateDispatcher
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand All @@ -21,7 +22,7 @@ object CoroutinesScopesModule {
@Singleton
@Provides
@ApplicationScope
fun providesCoroutineScope(@DefaultDispatcher defaultDispatcher: CoroutineDispatcher): CoroutineScope =
fun providesCoroutineScope(@MainImmediateDispatcher defaultDispatcher: CoroutineDispatcher): CoroutineScope =
CoroutineScope(SupervisorJob() + defaultDispatcher)

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import android.content.Intent
import android.content.IntentFilter
import androidx.lifecycle.ServiceLifecycleDispatcher
import com.crazylegend.common.ifTrue
import com.crazylegend.context.registerReceiverSafe
import com.crazylegend.context.unRegisterReceiverSafe
import com.crazylegend.vigilante.contracts.service.ServiceLifecycle
import com.crazylegend.vigilante.di.providers.prefs.logging.LoggingPrefs
import com.crazylegend.vigilante.headset.HeadsetReceiver
Expand All @@ -20,11 +22,12 @@ import javax.inject.Inject

@ServiceScoped
class BroadcastProvider @Inject constructor(
private val screenReceiver: ScreenReceiver,
private val headsetPlugReceiver: HeadsetReceiver,
private val powerReceiver: PowerReceiver,
private val service: Service,
private val loggingPrefs: LoggingPrefs) : ServiceLifecycle {
private val screenReceiver: ScreenReceiver,
private val headsetPlugReceiver: HeadsetReceiver,
private val powerReceiver: PowerReceiver,
private val service: Service,
private val loggingPrefs: LoggingPrefs
) : ServiceLifecycle {

override val serviceLifecycleDispatcher = ServiceLifecycleDispatcher(this)

Expand All @@ -37,9 +40,9 @@ class BroadcastProvider @Inject constructor(
}

override fun disposeResources() {
loggingPrefs.isHeadsetLoggingEnabled.ifTrue { service.unregisterReceiver(headsetPlugReceiver) }
loggingPrefs.isLockScreenLoggingEnabled.ifTrue { service.unregisterReceiver(screenReceiver) }
loggingPrefs.isPowerLoggingEnabled.ifTrue { service.unregisterReceiver(powerReceiver) }
service.unRegisterReceiverSafe(headsetPlugReceiver)
service.unRegisterReceiverSafe(screenReceiver)
service.unRegisterReceiverSafe(powerReceiver)
}

private fun registerPowerReceiver() {
Expand All @@ -58,9 +61,13 @@ class BroadcastProvider @Inject constructor(
}
}

private inline fun registerReceiver(initialAction: String, broadcastReceiver: BroadcastReceiver, filterConfig: IntentFilter.() -> Unit = {}) {
private inline fun registerReceiver(
initialAction: String,
broadcastReceiver: BroadcastReceiver,
filterConfig: IntentFilter.() -> Unit = {}
) {
val filter = IntentFilter(initialAction)
filter.filterConfig()
service.registerReceiver(broadcastReceiver, filter)
service.registerReceiverSafe(broadcastReceiver, filter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ import javax.inject.Singleton
class LoggingPrefs @Inject constructor(@EncryptedPrefs private val defaultPrefs: SharedPreferences) : LoggingPreferences {

override val isPermissionLoggingEnabled: Boolean
get() = getBooleanState(LOG_PERMISSIONS_KEY)
get() = getBooleanState(LOG_PERMISSIONS_KEY, true)

override fun setPermissionLoggingState(isEnabled: Boolean) = putBooleanState(LOG_NOTIFICATIONS_KEY, isEnabled)

override val isPowerLoggingEnabled: Boolean
get() = getBooleanState(LOG_POWER_KEY)
get() = getBooleanState(LOG_POWER_KEY, true)

override fun setPowerLoggingState(isEnabled: Boolean) = putBooleanState(LOG_POWER_KEY, isEnabled)

override val isHeadsetLoggingEnabled: Boolean
get() = getBooleanState(LOG_HEADSET_KEY)
get() = getBooleanState(LOG_HEADSET_KEY, true)

override fun setHeadsetLoggingState(isEnabled: Boolean) = putBooleanState(LOG_HEADSET_KEY, isEnabled)

override val isNotificationsLoggingEnabled: Boolean
get() = getBooleanState(LOG_NOTIFICATIONS_KEY)
get() = getBooleanState(LOG_NOTIFICATIONS_KEY, true)

override val isEmptyNotificationsLoggingEnabled: Boolean
get() = getBooleanState(LOG_EMPTY_PERMISSIONS_KEY)
get() = getBooleanState(LOG_EMPTY_PERMISSIONS_KEY, true)

override fun setNotificationsLoggingState(isEnabled: Boolean) = putBooleanState(LOG_NOTIFICATIONS_KEY, isEnabled)

override val isLockScreenLoggingEnabled: Boolean
get() = getBooleanState(LOG_LOCKSCREEN_KEY)
get() = getBooleanState(LOG_LOCKSCREEN_KEY, true)

override fun setLockScreenLoggingState(isEnabled: Boolean) = putBooleanState(LOG_LOCKSCREEN_KEY, isEnabled)

private fun putBooleanState(key: String, state: Boolean) = defaultPrefs.putBoolean(key, state)
private fun getBooleanState(key: String) = defaultPrefs.getBoolean(key, false)
private fun getBooleanState(key: String, default: Boolean = false) = defaultPrefs.getBoolean(key, default)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class LocationProcessor @Inject constructor(
locationStatusReceiver = initLocationStatusReceiver()

scope.launch {
locationStatus.collectLatest {
if (it) {
locationStatus.collectLatest { isGPSEnabled ->
if (isGPSEnabled) {
setLocationIsUsed()
VigilanteService.serviceLayoutListener?.showLocation()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import android.view.accessibility.AccessibilityEvent
import androidx.lifecycle.ServiceLifecycleDispatcher
import com.crazylegend.common.currentTimeMillis
import com.crazylegend.common.tryOrElse
import com.crazylegend.coroutines.ioDispatcher
import com.crazylegend.vigilante.BuildConfig
import com.crazylegend.vigilante.contracts.service.ServiceLifecycle
import com.crazylegend.vigilante.di.modules.coroutines.dispatchers.IoDispatcher
import com.crazylegend.vigilante.di.providers.prefs.defaultPrefs.DefaultPreferencessProvider
import com.crazylegend.vigilante.di.providers.prefs.logging.LoggingPrefs
import com.crazylegend.vigilante.notifications.db.NotificationsDAO
import com.crazylegend.vigilante.notifications.db.NotificationsModel
import com.crazylegend.vigilante.notifications.db.NotificationsRepo
import dagger.hilt.android.scopes.ServiceScoped
import kotlinx.coroutines.launch
import java.util.*
import java.util.Date
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch

/**
* Created by crazy on 10/20/20 to long live and prosper !
Expand All @@ -26,7 +27,8 @@ import javax.inject.Inject
class NotificationsProvider @Inject constructor(
private val prefsProvider: DefaultPreferencessProvider,
private val loggingPrefs: LoggingPrefs,
private val notificationsRepo: NotificationsRepo
private val notificationsRepo: NotificationsDAO,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
) : ServiceLifecycle {

fun processEvent(event: AccessibilityEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.crazylegend.vigilante.notifications.details
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.crazylegend.database.coroutines.dbCallStateFlow
import com.crazylegend.vigilante.notifications.db.NotificationsRepo
import com.crazylegend.vigilante.notifications.db.NotificationsDAO
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
Expand All @@ -12,8 +12,8 @@ import dagger.assisted.AssistedInject
* Created by crazy on 11/7/20 to long live and prosper !
*/
class NotificationDetailsViewModel @AssistedInject constructor(
private val notificationsRepo: NotificationsRepo,
@Assisted private val notificationID: Int) : ViewModel() {
private val notificationsRepo: NotificationsDAO,
@Assisted private val notificationID: Int) : ViewModel() {

@AssistedFactory
interface NotificationDetailsVMFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.crazylegend.vigilante.notifications.ui

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.crazylegend.vigilante.notifications.db.NotificationsRepo
import com.crazylegend.vigilante.notifications.db.NotificationsDAO
import com.crazylegend.vigilante.paging.PagingProvider
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
Expand All @@ -12,7 +12,7 @@ import javax.inject.Inject
*/
@HiltViewModel
class NotificationsViewModel @Inject constructor(
private val repo: NotificationsRepo,
private val repo: NotificationsDAO,
pagingProvider: PagingProvider
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.ServiceLifecycleDispatcher
import com.crazylegend.coroutines.makeIOCall
import com.crazylegend.string.isNotNullOrEmpty
import com.crazylegend.vigilante.contracts.service.ServiceLifecycle
import com.crazylegend.vigilante.di.modules.coroutines.dispatchers.IoDispatcher
import com.crazylegend.vigilante.permissions.db.PermissionRequestModel
import com.crazylegend.vigilante.permissions.db.PermissionRequestsDAO
import dagger.hilt.android.scopes.ServiceScoped
Expand All @@ -14,14 +15,16 @@ import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher

/**
* Created by crazy on 10/21/20 to long live and prosper !
*/
@ServiceScoped
@SuppressLint("DefaultLocale")
class PermissionsProcessor @Inject constructor(
private val permissionRequestsRepository: PermissionRequestsDAO
private val permissionRequestsRepository: PermissionRequestsDAO,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
) : ServiceLifecycle {

override val serviceLifecycleDispatcher: ServiceLifecycleDispatcher = ServiceLifecycleDispatcher(this)
Expand All @@ -44,7 +47,7 @@ class PermissionsProcessor @Inject constructor(
val settingsTitle = settingsPermissionTitle.getAndSet(null)
val permissionRequestModel = PermissionRequestModel(newPermissionMessage, currentPackageRef, settingsAppName = settingsTitle)
settingsPermissionTitle.set(null)
scope.makeIOCall {
scope.launch(ioDispatcher) {
permissionRequestsRepository.insertPermissionRequest(permissionRequestModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import com.crazylegend.vigilante.di.modules.coroutines.appScope.ApplicationScope
import com.crazylegend.vigilante.screen.db.ScreenModel
import com.crazylegend.vigilante.screen.db.ScreenRepository
import dagger.hilt.android.scopes.ServiceScoped
import kotlinx.coroutines.*
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
* Created by crazy on 10/30/20 to long live and prosper !
Expand All @@ -28,7 +31,7 @@ class ScreenReceiver @Inject constructor(
else -> null
}
screenModel?.apply {
appScope.launch() {
appScope.launch {
withContext(NonCancellable) {
screenRepository.insertScreenAction(this@apply)
}
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/com/crazylegend/vigilante/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import com.crazylegend.intent.newIntent
import com.crazylegend.lifecycle.viewCoroutineScope
import com.crazylegend.receivers.isServiceRunning
import com.crazylegend.receivers.startForegroundService
import com.crazylegend.security.encryptedSharedPreferences
import com.crazylegend.view.dimen
import com.crazylegend.vigilante.R
import com.crazylegend.vigilante.database.migrations.CameraAndMicRemovalMigration
import com.crazylegend.vigilante.service.VigilanteService
import com.crazylegend.vigilante.settings.THEME_PREF_KEY
import net.sqlcipher.database.SQLiteDatabase
import net.sqlcipher.database.SupportFactory

Expand All @@ -37,10 +39,10 @@ const val MY_OTHER_APPS_URL = "https://funkymuse.dev/apps/"
const val NEW_ISSUE_URL = "${GITHUB_URL}issues/new"
const val DEFAULT_ANIM_TIME = 1000L
val dismissPackages = setOf(
"com.google.android.permissioncontroller",
"com.android.systemui",
"com.google.android.packageinstaller",
"com.android.packageinstaller",
"com.google.android.permissioncontroller",
"com.android.systemui",
"com.google.android.packageinstaller",
"com.android.packageinstaller",
)

fun Context.startVigilante() {
Expand All @@ -58,18 +60,18 @@ inline fun <reified T : RoomDatabase> Context.instantiateDatabase(cameraDbName:
val passphrase = SQLiteDatabase.getBytes(packageName.toCharArray())
val factory = SupportFactory(passphrase)
return Room.databaseBuilder(this, T::class.java, cameraDbName)
.addMigrations(CameraAndMicRemovalMigration())
.openHelperFactory(factory)
.build()
.addMigrations(CameraAndMicRemovalMigration())
.openHelperFactory(factory)
.build()
}

@Suppress("UNCHECKED_CAST")
inline fun <reified T : ViewModel> Fragment.assistedViewModel(
crossinline viewModelProducer: (SavedStateHandle) -> T
crossinline viewModelProducer: (SavedStateHandle) -> T
) = viewModels<T> {
object : AbstractSavedStateViewModelFactory(this, arguments) {
override fun <T : ViewModel> create(key: String, modelClass: Class<T>, handle: SavedStateHandle) =
viewModelProducer(handle) as T
viewModelProducer(handle) as T
}
}

Expand All @@ -86,4 +88,6 @@ fun PreferenceFragmentCompat.addSpacingForPreferenceBackButton() {
clipToPadding = false
updatePadding(bottom = dimen(R.dimen.padding_bottom_scroll).toInt())
}
}
}

fun Context.darkMode() = encryptedSharedPreferences().getBoolean(THEME_PREF_KEY, false)
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_one_time_password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/generatePassword"
app:backgroundTint="@color/primary"
android:textColor="@android:color/white"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
Expand Down
Loading

0 comments on commit a9c6a9a

Please sign in to comment.