Skip to content

Commit

Permalink
proxy-app map: set alpha based on internet permission
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainmohd-a committed Sep 9, 2024
1 parent d715e76 commit 8b49215
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ class FirewallAppListAdapter(
} else {
b.firewallAppLabelTv.setTextColor(userAppColor)
} */
b.firewallAppToggleOther.text = getFirewallText(appStatus, connStatus)
displayIcon(
getIcon(context, appInfo.packageName, appInfo.appName), b.firewallAppIconIv)
// set the alpha based on internet permission
if (appInfo.hasInternetPermission(packageManager)) {
b.firewallAppLabelTv.alpha = 1f
b.firewallAppIconIv.alpha = 1f
} else {
b.firewallAppLabelTv.alpha = 0.4f
b.firewallAppIconIv.alpha = 0.4f
}
b.firewallAppToggleOther.text = getFirewallText(appStatus, connStatus)
displayIcon(
getIcon(context, appInfo.packageName, appInfo.appName), b.firewallAppIconIv)
if (appInfo.packageName == context.packageName) {
b.firewallAppToggleWifi.visibility = View.GONE
b.firewallAppToggleMobileData.visibility = View.GONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Logger
import Logger.LOG_TAG_PROXY
import android.content.Context
import android.content.DialogInterface
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -54,6 +55,7 @@ class WgIncludeAppsAdapter(
PagingDataAdapter<ProxyApplicationMapping, WgIncludeAppsAdapter.IncludedAppInfoViewHolder>(
DIFF_CALLBACK
) {
private val packageManager: PackageManager = context.packageManager

companion object {

Expand Down Expand Up @@ -138,6 +140,14 @@ class WgIncludeAppsAdapter(

val isIncluded = mapping.proxyId == proxyId && mapping.proxyId != ""
ui { displayIcon(getIcon(context, mapping.packageName, mapping.appName)) }
// set the alpha based on internet permission
if (mapping.hasInternetPermission(packageManager)) {
b.wgIncludeAppListApkLabelTv.alpha = 1f
b.wgIncludeAppListApkIconIv.alpha = 1f
} else {
b.wgIncludeAppListApkLabelTv.alpha = 0.4f
b.wgIncludeAppListApkIconIv.alpha = 0.4f
}
setupClickListeners(mapping, isIncluded)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.celzero.bravedns.database

import android.Manifest
import android.content.pm.PackageManager
import androidx.room.Entity

@Entity(tableName = "ProxyApplicationMapping", primaryKeys = ["uid", "packageName", "proxyId"])
Expand Down Expand Up @@ -55,4 +57,14 @@ class ProxyApplicationMapping {
this.isActive = isActive
this.proxyId = proxyId
}

fun hasInternetPermission(packageManager: PackageManager): Boolean {
if (packageName.startsWith("no_package_")) return true

// INTERNET permission if defined, can not be denied so this is safe to use
return packageManager.checkPermission(
Manifest.permission.INTERNET,
packageName
) == PackageManager.PERMISSION_GRANTED
}
}

0 comments on commit 8b49215

Please sign in to comment.