Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? # to your account

[PM-19108] Enhance Privileged Apps List View #4898

Draft
wants to merge 1 commit into
base: innovation-sprint/privileged-apps/settings-mgmt
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<!-- Protect access to AuthenticatorBridgeService using this custom permission.

Note that each build type uses a different value for knownCerts.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.x8bit.bitwarden.data.platform.manager

/**
* Abstraction for interacting with Android package manager.
*/
interface BitwardenPackageManager {

/**
* Checks if the package is installed.
*/
fun isPackageInstalled(packageName: String): Boolean

/**
* Gets the app name from the package name or null if the package name is not found.
*/
fun getAppNameFromPackageNameOrNull(packageName: String): String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.x8bit.bitwarden.data.platform.manager

import android.content.Context
import android.content.pm.PackageManager

/**
* Primary implementation of [BitwardenPackageManager].
*/
class BitwardenPackageManagerImpl(
context: Context,
) : BitwardenPackageManager {

private val nativePackageManager = context.packageManager

override fun isPackageInstalled(packageName: String): Boolean {
return try {
nativePackageManager.getApplicationInfo(packageName, 0)
true
} catch (_: PackageManager.NameNotFoundException) {
false
}
}

override fun getAppNameFromPackageNameOrNull(packageName: String): String? {
return try {
val appInfo = nativePackageManager.getApplicationInfo(packageName, 0)
nativePackageManager
.getApplicationLabel(appInfo)
.toString()
} catch (_: PackageManager.NameNotFoundException) {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import com.x8bit.bitwarden.data.platform.manager.AssetManager
import com.x8bit.bitwarden.data.platform.manager.AssetManagerImpl
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManager
import com.x8bit.bitwarden.data.platform.manager.BiometricsEncryptionManagerImpl
import com.x8bit.bitwarden.data.platform.manager.BitwardenPackageManager
import com.x8bit.bitwarden.data.platform.manager.BitwardenPackageManagerImpl
import com.x8bit.bitwarden.data.platform.manager.DatabaseSchemeManager
import com.x8bit.bitwarden.data.platform.manager.DatabaseSchemeManagerImpl
import com.x8bit.bitwarden.data.platform.manager.DebugMenuFeatureFlagManagerImpl
Expand Down Expand Up @@ -366,4 +368,10 @@ object PlatformManagerModule {
clock = clock,
)
}

@Provides
@Singleton
fun provideBitwardenPackageManager(
@ApplicationContext context: Context,
): BitwardenPackageManager = BitwardenPackageManagerImpl(context = context)
}
Loading
Loading