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

Commit

Permalink
fix: Button not detecting correct info about accessibility
Browse files Browse the repository at this point in the history
Closes #25

Notifications about microphone and camera usage is turned ON by default

feat: Edge to edge

removal: Camera and microphone history due to the fact that Android as a system doesn't provide an option to detect the current app using the package
  • Loading branch information
CraZyLegenD committed Nov 17, 2020
1 parent 5e36aa9 commit 67b0972
Show file tree
Hide file tree
Showing 41 changed files with 60 additions and 476 deletions.
4 changes: 2 additions & 2 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 30
versionCode 1
versionName "1.0.2"
versionCode 2
versionName "1.0.3"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.crazylegend.vigilante.activities
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.navigation.NavController
Expand Down Expand Up @@ -46,19 +45,13 @@ class MainActivity : AppCompatActivity() {

private val showBackButtonList
get() = listOf(
R.id.settingsFragment, R.id.crashFragment, R.id.cameraAccessFragment,
R.id.microphoneAccessFragment, R.id.appsUsageFragment, R.id.screenAccessFragment,
R.id.settingsFragment, R.id.crashFragment,
R.id.appsUsageFragment, R.id.screenAccessFragment,
R.id.listFilterBottomSheet, R.id.notificationsFragment, R.id.headsetFragment,
R.id.permissionRequestFragment, R.id.permissionDetailsBottomSheet, R.id.notificationDetailsFragment,
R.id.powerFragment, R.id.powerDetailsDialog
)

override fun onPostCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onPostCreate(savedInstanceState, persistentState)
EdgeToEdge.setUpRoot(binding.root)

}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (isIgnoringBatteryOptimization != true) {
Expand All @@ -69,6 +62,8 @@ class MainActivity : AppCompatActivity() {

override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
EdgeToEdge.setUpRoot(binding.root)

navController.addOnDestinationChangedListener { _, destination, _ ->
binding.backButton.root.isVisible = destination.id in showBackButtonList
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@ package com.crazylegend.vigilante.camera
import android.content.Context
import android.hardware.camera2.CameraManager
import androidx.lifecycle.ServiceLifecycleDispatcher
import com.crazylegend.database.coroutines.makeDBCall
import com.crazylegend.kotlinextensions.context.cameraManager
import com.crazylegend.kotlinextensions.context.notificationManager
import com.crazylegend.kotlinextensions.currentTimeMillis
import com.crazylegend.kotlinextensions.ifTrue
import com.crazylegend.vigilante.R
import com.crazylegend.vigilante.camera.db.CameraModel
import com.crazylegend.vigilante.camera.db.CameraRepository
import com.crazylegend.vigilante.contracts.service.ServiceManagersCoroutines
import com.crazylegend.vigilante.di.providers.PrefsProvider
import com.crazylegend.vigilante.di.providers.UserNotificationsProvider
import com.crazylegend.vigilante.di.qualifiers.ServiceContext
import com.crazylegend.vigilante.service.VigilanteService
import com.crazylegend.vigilante.service.VigilanteService.Companion.currentPackageString
import dagger.hilt.android.scopes.ServiceScoped
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject

/**
Expand All @@ -31,17 +22,13 @@ import javax.inject.Inject
class CameraProcessor @Inject constructor(
@ServiceContext private val context: Context,
private val userNotificationsProvider: UserNotificationsProvider,
private val prefsProvider: PrefsProvider,
private val cameraRepository: CameraRepository) : ServiceManagersCoroutines {
private val prefsProvider: PrefsProvider) : ServiceManagersCoroutines {

//lifecycle
override val serviceLifecycleDispatcher = ServiceLifecycleDispatcher(this)

//camera
private lateinit var cameraCallback: CameraManager.AvailabilityCallback
private val packageUsingCamera: AtomicReference<String?> = AtomicReference(currentPackageString)
private var wasCameraBeingUsed: AtomicBoolean = AtomicBoolean(false)
private val cameraStartedUsageTime: AtomicLong = AtomicLong(-1)
private val cameraNotificationID = 69

override fun initVars() {
Expand All @@ -61,7 +48,7 @@ class CameraProcessor @Inject constructor(
object : CameraManager.AvailabilityCallback() {
override fun onCameraAvailable(cameraId: String) {
super.onCameraAvailable(cameraId)
setCameraNotUsed(cameraId)
setCameraNotUsed()
stopNotificationIfUserEnabled()
}

Expand All @@ -77,8 +64,6 @@ class CameraProcessor @Inject constructor(
}

private fun setCameraUsed() {
wasCameraBeingUsed.set(true)
packageUsingCamera.set(currentPackageString)
sendNotificationIfUserEnabled()
VigilanteService.serviceLayoutListener?.showCamera()
}
Expand All @@ -90,30 +75,14 @@ class CameraProcessor @Inject constructor(
}


private fun setCameraNotUsed(cameraId: String) {
if (wasCameraBeingUsed.get()) {
val cameraStoppedBeingUsedAt = currentTimeMillis
val cameraModel = CameraModel(Date(cameraStartedUsageTime.getAndSet(-1)),
packageUsingCamera.getAndSet(null), cameraId, Date(cameraStoppedBeingUsedAt))
scope.makeDBCall {
cameraRepository.insertCameraRecord(cameraModel)
}
wasCameraBeingUsed.set(false)
VigilanteService.serviceLayoutListener?.hideCamera()
}
private fun setCameraNotUsed() {
VigilanteService.serviceLayoutListener?.hideCamera()
}
//endregion


//region public
override fun eventActionByPackageName(eventPackageName: CharSequence) {
if (!wasCameraBeingUsed.get()) {
packageUsingCamera.set(eventPackageName.toString())
} else {
if (cameraStartedUsageTime.get() == -1L)
cameraStartedUsageTime.set(currentTimeMillis)
}
}

//endregion


Expand Down
24 changes: 0 additions & 24 deletions app/src/main/java/com/crazylegend/vigilante/camera/db/CameraDao.kt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ interface LifecycleManagersContract {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
fun disposeResources()

fun eventActionByPackageName(eventPackageName: CharSequence)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ object DatabaseModule {
@Singleton
fun headsetDao(database: VigilanteDatabase) = database.headsetDao()

@Provides
@Singleton
fun cameraDao(database: VigilanteDatabase) = database.cameraDao()

@Provides
@Singleton
fun notificationsDao(database: VigilanteDatabase) = database.notificationsDAO()

@Provides
@Singleton
fun microphoneDao(database: VigilanteDatabase) = database.microphoneDAO()

@Provides
@Singleton
fun screenDao(database: VigilanteDatabase) = database.screenDAO()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.crazylegend.vigilante.database


import android.content.Context
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.crazylegend.kotlinextensions.singleton.ParameterizedSingleton
import com.crazylegend.vigilante.camera.db.CameraDao
import com.crazylegend.vigilante.camera.db.CameraModel
import com.crazylegend.vigilante.headset.database.HeadsetDAO
import com.crazylegend.vigilante.headset.database.HeadsetModel
import com.crazylegend.vigilante.microphone.db.MicrophoneDAO
import com.crazylegend.vigilante.microphone.db.MicrophoneModel
import com.crazylegend.vigilante.notifications.db.NotificationsDAO
import com.crazylegend.vigilante.notifications.db.NotificationsModel
import com.crazylegend.vigilante.permissions.db.PermissionRequestModel
Expand All @@ -28,20 +25,16 @@ import com.crazylegend.vigilante.utils.instantiateDatabase
*/
@Database(entities = [
HeadsetModel::class,
CameraModel::class,
NotificationsModel::class,
MicrophoneModel::class,
ScreenModel::class,
PermissionRequestModel::class,
PowerModel::class
], version = 1, exportSchema = true)
], version = 2, exportSchema = true)
@TypeConverters(DateTypeConverter::class)
abstract class VigilanteDatabase : RoomDatabase() {

abstract fun headsetDao(): HeadsetDAO
abstract fun cameraDao(): CameraDao
abstract fun notificationsDAO(): NotificationsDAO
abstract fun microphoneDAO(): MicrophoneDAO
abstract fun screenDAO(): ScreenDAO
abstract fun permissionRequestsDAO(): PermissionRequestsDAO
abstract fun powerDAO(): PowerDAO
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.crazylegend.vigilante.database.migrations

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

/**
* Created by crazy on 11/17/20 to long live and prosper !
*/
class CameraAndMicRemovalMigration : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("drop table if exists cameraAccesses")
database.execSQL("drop table if exists microphoneAccesses")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class BroadcastProvider @Inject constructor(private val service: Service) : Serv
receivers.asSequence().forEach { service.unregisterReceiver(it) }
}

override fun eventActionByPackageName(eventPackageName: CharSequence) {}

private fun registerPowerReceiver() {
val filter = IntentFilter(Intent.ACTION_POWER_CONNECTED)
filter.addAction(Intent.ACTION_POWER_DISCONNECTED)
Expand Down
Loading

0 comments on commit 67b0972

Please sign in to comment.