Skip to content

Commit

Permalink
fix: optimize querying download uri (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedUmbrellaX authored Mar 9, 2024
1 parent 64df08f commit 7504bb9
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions app/src/google/java/ani/dantotsu/others/AppUpdater.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,8 @@ object AppUpdater {
DownloadManager.EXTRA_DOWNLOAD_ID, id
) ?: id

val query = DownloadManager.Query()
query.setFilterById(downloadId)
val c = downloadManager.query(query)

if (c.moveToFirst()) {
val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS)
if (DownloadManager.STATUS_SUCCESSFUL == c
.getInt(columnIndex)
) {
c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI)
val uri = Uri.parse(
c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
)
openApk(this@downloadUpdate, uri)
}
downloadManager.getUriForDownloadedFile(downloadId)?.let {
openApk(this@downloadUpdate, it)
}
} catch (e: Exception) {
logError(e)
Expand All @@ -190,16 +177,11 @@ object AppUpdater {
private fun openApk(context: Context, uri: Uri) {
try {
uri.path?.let {
val contentUri = FileProvider.getUriForFile(
context,
BuildConfig.APPLICATION_ID + ".provider",
File(it)
)
val installIntent = Intent(Intent.ACTION_VIEW).apply {
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
data = contentUri
data = uri
}
context.startActivity(installIntent)
}
Expand Down

0 comments on commit 7504bb9

Please sign in to comment.