Uitron masking 1.0.16 (#84)

This commit is contained in:
Sayed Owais Ali
2023-12-20 12:40:01 +05:30
committed by GitHub
parent f0b7ca051b
commit 55e0b4ca15
4 changed files with 41 additions and 20 deletions

View File

@@ -6,7 +6,7 @@ plugins {
id 'kotlin-parcelize'
}
def VERSION_NAME = "1.0.16"
def VERSION_NAME = "1.0.17"
android {
namespace 'com.navi.alfred'

View File

@@ -6,4 +6,5 @@ import com.navi.alfred.model.MaskingBounds
interface ComposeMaskingRepo {
fun maskSensitiveComposable(id: String, coordinates: MaskingBounds?, currentView: View?)
fun removeSensitiveComposable(id: String)
fun blurSensitiveScreen(isVisible: Boolean)
}

View File

@@ -1,29 +1,41 @@
package com.navi.alfred.repository
import android.view.View
import com.navi.alfred.AlfredManager
import com.navi.alfred.model.MaskingBounds
import java.lang.ref.WeakReference
class ComposeMaskingRepoImpl : ComposeMaskingRepo {
private val sensitiveCoordinates = mutableMapOf<String, MaskingBounds>()
private var rootView = WeakReference<View>(null)
private var blurSensitiveScreen = false
override fun maskSensitiveComposable(
id: String,
coordinates: MaskingBounds?,
rootView: View?
) {
if (rootView != this.rootView.get()) {
removeAllSensitiveComposables()
}
if (coordinates != null) {
this.rootView = WeakReference(rootView)
sensitiveCoordinates[id] = coordinates
if (AlfredManager.isAlfredRecordingEnabled()) {
if (rootView != this.rootView.get()) {
removeAllSensitiveComposables()
}
if (coordinates != null) {
this.rootView = WeakReference(rootView)
sensitiveCoordinates[id] = coordinates
}
}
}
override fun removeSensitiveComposable(id: String) {
if (sensitiveCoordinates.containsKey(id)) {
sensitiveCoordinates.remove(id)
if (AlfredManager.isAlfredRecordingEnabled()) {
if (sensitiveCoordinates.containsKey(id)) {
sensitiveCoordinates.remove(id)
}
}
}
override fun blurSensitiveScreen(isVisible: Boolean) {
if (AlfredManager.isAlfredRecordingEnabled()) {
blurSensitiveScreen = isVisible
}
}
@@ -38,4 +50,8 @@ class ComposeMaskingRepoImpl : ComposeMaskingRepo {
internal fun getRootViewOfComposeScreen(): View? {
return rootView.get()
}
internal fun getBlurSensitiveScreenStatus(): Boolean {
return blurSensitiveScreen
}
}

View File

@@ -200,14 +200,16 @@ internal suspend fun captureScreen(
if (isMaskingEnabled(screenName) || (v.tag == AlfredConstants.SENSITIVE_VIEW_TAG) || (v.tag == AlfredConstants.SENSITIVE_COMPOSE_VIEW_TAG)) {
try {
if (currentScreen.isComposeScreen == true) {
if (sensitiveCoordinates.isNotEmpty() && rootView != null) {
withContext(Dispatchers.Main) {
captureComposeViewWithMasking(canvas, sensitiveCoordinates, rootView)
}
} else {
if (AlfredManager.sensitiveComposeRepository.getBlurSensitiveScreenStatus()) {
withContext(Dispatchers.Main) {
blurScreen(canvas, v)
}
} else {
if (rootView != null) {
withContext(Dispatchers.Main) {
captureComposeViewWithMasking(canvas, sensitiveCoordinates, rootView)
}
}
}
} else {
val maskedViewsList = findViewWithTagRecursive(
@@ -311,12 +313,14 @@ internal fun captureComposeViewWithMasking(
rootView: View
) {
rootView.draw(canvas)
val paint = Paint()
paint.color = Color.BLACK
if (sensitiveCoordinates.isNotEmpty()) {
val paint = Paint()
paint.color = Color.BLACK
sensitiveCoordinates.forEach { bounds ->
if (bounds.bottom > 0 && bounds.top < rootView.height && bounds.height > 0 && bounds.width > 0) {
canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.bottom, paint)
sensitiveCoordinates.forEach { bounds ->
if (bounds.bottom > 0 && bounds.top < rootView.height && bounds.height > 0 && bounds.width > 0) {
canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.bottom, paint)
}
}
}
}
@@ -328,7 +332,7 @@ internal fun blurScreen(
rootView.draw(canvas)
val paint = Paint()
paint.color = Color.GRAY
paint.alpha = 90
paint.alpha = 240
canvas.drawRect(
rootView.left.toFloat(),
rootView.top.toFloat(),