Skip to content

Commit

Permalink
Fixed nullability issues
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
  • Loading branch information
ArnyminerZ authored and rfc2822 committed Sep 6, 2024
1 parent 0582587 commit ed7a47d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import android.content.pm.PackageManager
import at.bitfire.davdroid.db.AppDatabase
import at.bitfire.davdroid.db.SyncStats
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import java.text.Collator
import java.util.logging.Logger
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class DavSyncStatsRepository @Inject constructor(
@ApplicationContext val context: Context,
Expand Down Expand Up @@ -61,11 +61,14 @@ class DavSyncStatsRepository @Inject constructor(
val packageManager = context.packageManager
val packageName = packageManager.resolveContentProvider(authority, 0)?.packageName ?: authority
return try {
val appInfo = packageManager.getPackageInfo(packageName, 0).applicationInfo
val appInfo = packageManager.getPackageInfo(packageName, 0).applicationInfo!!
packageManager.getApplicationLabel(appInfo).toString()
} catch (e: PackageManager.NameNotFoundException) {
logger.warning("Application name not found for authority: $authority")
authority
} catch (_: NullPointerException) {
logger.warning("Package name ($packageName) not found for authority: $authority")
authority
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import at.bitfire.ical4android.TaskProvider
import at.bitfire.ical4android.TaskProvider.ProviderName
import dagger.Lazy
import dagger.hilt.android.qualifiers.ApplicationContext
import java.util.logging.Logger
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import java.util.logging.Logger
import javax.inject.Inject

/**
* Responsible for setting/getting the currently used tasks app, and for communicating with it.
Expand Down Expand Up @@ -168,7 +168,7 @@ class TasksAppManager @Inject constructor(

val pm = context.packageManager
val tasksAppInfo = pm.getPackageInfo(e.provider.packageName, 0)
val tasksAppLabel = tasksAppInfo.applicationInfo.loadLabel(pm)
val tasksAppLabel = tasksAppInfo.applicationInfo?.loadLabel(pm)

val notify = NotificationCompat.Builder(context, registry.CHANNEL_SYNC_ERRORS)
.setSmallIcon(R.drawable.ic_sync_problem_notify)
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/kotlin/at/bitfire/davdroid/ui/DebugInfoModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.dmfs.tasks.contract.TaskContract
import java.io.File
import java.io.IOException
import java.io.Writer
Expand All @@ -67,6 +64,9 @@ import java.util.logging.Level
import java.util.logging.Logger
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.dmfs.tasks.contract.TaskContract
import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter as asCalendarSyncAdapter
import at.bitfire.vcard4android.Utils.asSyncAdapter as asContactsSyncAdapter
import at.techbee.jtx.JtxContract.asSyncAdapter as asJtxSyncAdapter
Expand Down Expand Up @@ -239,9 +239,9 @@ class DebugInfoModel @AssistedInject constructor(
val info = pm.getPackageInfo(packageName, 0)
val appInfo = info.applicationInfo
val notes = mutableListOf<String>()
if (!appInfo.enabled)
if (appInfo?.enabled == false)
notes += "disabled"
if (appInfo.flags.and(ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0)
if (appInfo?.flags?.and(ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0)
notes += "<em>on external storage</em>"
table.addLine(
info.packageName, info.versionName, PackageInfoCompat.getLongVersionCode(info),
Expand Down Expand Up @@ -366,7 +366,7 @@ class DebugInfoModel @AssistedInject constructor(
// permissions
writer.append("Permissions:\n")
val ownPkgInfo = context.packageManager.getPackageInfo(BuildConfig.APPLICATION_ID, PackageManager.GET_PERMISSIONS)
for (permission in ownPkgInfo.requestedPermissions) {
for (permission in ownPkgInfo.requestedPermissions ?: emptyArray()) {
val shortPermission = permission.removePrefix("android.permission.")
writer.append(" - $shortPermission: ")
.append(
Expand Down

0 comments on commit ed7a47d

Please sign in to comment.