Skip to content

Commit

Permalink
Merge pull request #100 from solrudev/develop
Browse files Browse the repository at this point in the history
0.9.4
  • Loading branch information
solrudev authored Jan 4, 2025
2 parents 096c7bc + 8d2a197 commit 35c18c4
Show file tree
Hide file tree
Showing 119 changed files with 369 additions and 211 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Ackpine depends on Jetpack libraries, so it's necessary to declare the `google()

```kotlin
dependencies {
val ackpineVersion = "0.9.3"
val ackpineVersion = "0.9.4"
implementation("ru.solrudev.ackpine:ackpine-core:$ackpineVersion")

// optional - Kotlin extensions and Coroutines support
Expand All @@ -49,7 +49,7 @@ dependencies {
License
-------

Copyright (C) 2023-2024 Ilya Fomichev
Copyright (C) 2023-2025 Ilya Fomichev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion ackpine-assets/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,4 +27,8 @@ ackpine {
artifact {
name = "Ackpine Assets"
}
}

dependencies {
implementation(projects.ackpineRuntime)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import android.os.CancellationSignal
import android.os.ParcelFileDescriptor
import android.provider.OpenableColumns
import android.webkit.MimeTypeMap
import ru.solrudev.ackpine.helpers.use
import java.io.FileNotFoundException

/**
Expand Down Expand Up @@ -135,12 +136,8 @@ public class AssetFileProvider : ContentProvider() {
val row = arrayOfNulls<Any>(columnNames.size)
row.setColumn(OpenableColumns.DISPLAY_NAME, uri.lastPathSegment)
if (OpenableColumns.SIZE in columnNames) {
var assetFileDescriptor: AssetFileDescriptor? = null
try {
assetFileDescriptor = openAssetFile(uri, "r", signal)
openAssetFile(uri, "r", signal).use { assetFileDescriptor ->
row.setColumn(OpenableColumns.SIZE, assetFileDescriptor?.declaredLength ?: -1L)
} finally {
assetFileDescriptor?.close()
}
}
cursor.addRow(row)
Expand Down
2 changes: 1 addition & 1 deletion ackpine-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

@file:Suppress("ConstPropertyName")
@file:Suppress("ConstPropertyName", "Unused")

package ru.solrudev.ackpine.helpers.concurrent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -194,7 +194,7 @@ internal abstract class SessionCommitActivity<F : Failure> protected constructor

internal companion object {

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_ACKPINE_SESSION_ID = "ACKPINE_SESSION_ID"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,7 @@
* limitations under the License.
*/

@file:Suppress("ConstPropertyName")
@file:Suppress("ConstPropertyName", "Unused")

package ru.solrudev.ackpine.impl.installer

Expand Down Expand Up @@ -67,7 +67,7 @@ internal interface InstallSessionFactory {
@WorkerThread
fun create(
session: SessionEntity.InstallSession,
needToCompleteIfSucceeded: Boolean = false
completeIfSucceeded: Boolean = false
): ProgressSession<InstallFailure>

fun resolveNotificationData(notificationData: NotificationData, name: String): NotificationData
Expand Down Expand Up @@ -131,10 +131,10 @@ internal class InstallSessionFactoryImpl internal constructor(

override fun create(
session: SessionEntity.InstallSession,
needToCompleteIfSucceeded: Boolean
completeIfSucceeded: Boolean
): ProgressSession<InstallFailure> = when (session.installerType) {
InstallerType.INTENT_BASED -> createIntentBasedInstallSession(session, needToCompleteIfSucceeded)
InstallerType.SESSION_BASED -> createSessionBasedInstallSession(session, needToCompleteIfSucceeded)
InstallerType.INTENT_BASED -> createIntentBasedInstallSession(session, completeIfSucceeded)
InstallerType.SESSION_BASED -> createSessionBasedInstallSession(session, completeIfSucceeded)
}

override fun resolveNotificationData(notificationData: NotificationData, name: String) = notificationData.run {
Expand All @@ -158,7 +158,7 @@ internal class InstallSessionFactoryImpl internal constructor(

private fun createIntentBasedInstallSession(
installSession: SessionEntity.InstallSession,
needToCompleteIfSucceeded: Boolean
completeIfSucceeded: Boolean
): IntentBasedInstallSession {
val id = UUID.fromString(installSession.session.id)
val initialState = installSession.getState(installSessionDao)
Expand All @@ -173,7 +173,7 @@ internal class InstallSessionFactoryImpl internal constructor(
sessionProgressDao, executor, handler, installSession.notificationId!!,
BinarySemaphore()
)
if (!needToCompleteIfSucceeded || initialState.isTerminal) {
if (!completeIfSucceeded || initialState.isTerminal) {
return session
}
// Though it somewhat helps with self-update sessions, it's still faulty:
Expand All @@ -188,19 +188,16 @@ internal class InstallSessionFactoryImpl internal constructor(
val lastUpdateTimestamp = installSession.lastUpdateTimestamp ?: Long.MAX_VALUE
val isSelfUpdate = initialState is Committed && applicationContext.packageName == packageName
val isLastUpdateTimestampUpdated = getLastSelfUpdateTimestamp() > lastUpdateTimestamp
val isSuccessfulSelfUpdate = isSelfUpdate && isLastUpdateTimestampUpdated
if (isSuccessfulSelfUpdate) {
if (isSelfUpdate && isLastUpdateTimestampUpdated) {
session.complete(Succeeded)
}
if (isSuccessfulSelfUpdate) {
lastUpdateTimestampDao.setLastUpdateTimestamp(id.toString(), getLastSelfUpdateTimestamp())
}
return session
}

private fun createSessionBasedInstallSession(
installSession: SessionEntity.InstallSession,
needToCompleteIfSucceeded: Boolean
completeIfSucceeded: Boolean
): SessionBasedInstallSession {
val initialState = installSession.getState(installSessionDao)
val initialProgress = installSession.getProgress(sessionProgressDao)
Expand All @@ -213,17 +210,17 @@ internal class InstallSessionFactoryImpl internal constructor(
installSession.session.confirmation, installSession.getNotificationData(),
installSession.session.requireUserAction, installSession.getInstallMode(),
installSession.getPreapproval(), installSession.getConstraints(),
requestUpdateOwnership = installSession.requestUpdateOwnership ?: false,
requestUpdateOwnership = installSession.requestUpdateOwnership == true,
packageSource = installSession.packageSource ?: PackageSource.Unspecified,
sessionDao,
sessionFailureDao = installSessionDao,
sessionProgressDao, nativeSessionIdDao, installPreapprovalDao, installConstraintsDao,
executor, handler, nativeSessionId, installSession.notificationId!!,
commitAttemptsCount = installSession.constraints?.commitAttemptsCount ?: 0,
isPreapproved = installSession.preapproval?.isPreapproved ?: false,
isPreapproved = installSession.preapproval?.isPreapproved == true,
dbWriteSemaphore = BinarySemaphore()
)
if (!needToCompleteIfSucceeded || initialState.isTerminal) {
if (!completeIfSucceeded || initialState.isTerminal) {
return session
}
val progressThreshold = (applicationContext.getSessionBasedSessionCommitProgressValue() * PROGRESS_MAX).toInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,7 +127,7 @@ internal class PackageInstallerImpl internal constructor(
.aggregate { type, _: Unit?, session, first ->
val installSession = installSessionFactory.create(
session,
needToCompleteIfSucceeded = type == SESSION_BASED || first && type == INTENT_BASED
completeIfSucceeded = type == SESSION_BASED || first && type == INTENT_BASED
)
sessions[installSession.id] = installSession
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,7 +70,7 @@ internal class IntentBasedInstallActivity : InstallActivity(TAG, startsActivity

internal companion object {

@get:JvmSynthetic
@JvmSynthetic
internal const val APK_URI_KEY = "ACKPINE_INSTALLER_APK_URI"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -220,22 +220,22 @@ internal class PackageInstallerStatusReceiver : BroadcastReceiver() {
@JvmSynthetic
internal fun getAction(context: Context) = "${context.packageName}.PACKAGE_INSTALLER_STATUS"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_NOTIFICATION_BUNDLE = "ru.solrudev.ackpine.extra.NOTIFICATION_BUNDLE"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_NOTIFICATION_ID = "ru.solrudev.ackpine.extra.NOTIFICATION_ID"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_NOTIFICATION_TITLE = "ru.solrudev.ackpine.extra.NOTIFICATION_TITLE"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_NOTIFICATION_MESSAGE = "ru.solrudev.ackpine.extra.NOTIFICATION_MESSAGE"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_NOTIFICATION_ICON = "ru.solrudev.ackpine.extra.NOTIFICATION_ICON"

@get:JvmSynthetic
@JvmSynthetic
internal const val EXTRA_CONFIRMATION = "ru.solrudev.ackpine.extra.CONFIRMATION"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Ilya Fomichev
* Copyright (C) 2023 Ilya Fomichev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 35c18c4

Please sign in to comment.