chore: Some more NPE prevention

This commit is contained in:
Ahmad Ansori Palembani 2024-06-05 19:16:19 +07:00
parent ac4a6d59e9
commit ae3dd32076
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -31,13 +31,13 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
override fun doWork(): Result { override fun doWork(): Result {
val storageManager: StorageManager by injectLazy() val storageManager: StorageManager by injectLazy()
val notifier = BackupNotifier(context.localeContext) val notifier = BackupNotifier(context.localeContext)
val uri = inputData.getString(LOCATION_URI_KEY)?.toUri() ?: storageManager.getAutomaticBackupsDirectory()?.uri!! val uri = inputData.getString(LOCATION_URI_KEY)?.toUri() ?: storageManager.getAutomaticBackupsDirectory()?.uri
val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupConst.BACKUP_ALL) val flags = inputData.getInt(BACKUP_FLAGS_KEY, BackupConst.BACKUP_ALL)
val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true) val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true)
notifier.showBackupProgress() notifier.showBackupProgress()
return try { return try {
val location = BackupCreator(context).createBackup(uri, flags, isAutoBackup) val location = BackupCreator(context).createBackup(uri!!, flags, isAutoBackup)
if (!isAutoBackup) notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())!!) if (!isAutoBackup) notifier.showBackupComplete(UniFile.fromUri(context, location.toUri())!!)
Result.success() Result.success()
} catch (e: Exception) { } catch (e: Exception) {