-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(installer): Store install metadata in APK
- Loading branch information
1 parent
c5eded4
commit e4eddf7
Showing
25 changed files
with
160 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/kotlin/com/aliucord/manager/installer/InstallMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.aliucord.manager.installer | ||
|
||
import com.aliucord.manager.ui.screens.installopts.InstallOptions | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* Data stored inside patched APKs as "aliucord.json" in order to preserve install-time information about Aliucord and the Manager. | ||
*/ | ||
@Serializable | ||
data class InstallMetadata( | ||
/** | ||
* The user-selected options for this installation. | ||
*/ | ||
val options: InstallOptions, | ||
|
||
/** | ||
* The semver version of this manager that performed the installation. | ||
*/ | ||
val managerVersionName: String, | ||
|
||
/** | ||
* Whether the manager is a real release or built from source. | ||
*/ | ||
val customManager: Boolean, | ||
|
||
/** | ||
* Aliuhook release version injected into the APK. | ||
*/ | ||
val aliuhookVersion: String, | ||
|
||
/** | ||
* Short commit hash of the commit the injector was built from. | ||
*/ | ||
val injectorCommitHash: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ord/manager/installer/steps/StepRunner.kt → .../aliucord/manager/installer/StepRunner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/kotlin/com/aliucord/manager/installer/steps/patch/SaveMetadataStep.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.aliucord.manager.installer.steps.patch | ||
|
||
import com.aliucord.manager.BuildConfig | ||
import com.aliucord.manager.R | ||
import com.aliucord.manager.installer.InstallMetadata | ||
import com.aliucord.manager.installer.StepRunner | ||
import com.aliucord.manager.installer.steps.StepGroup | ||
import com.aliucord.manager.installer.steps.base.Step | ||
import com.aliucord.manager.installer.steps.download.* | ||
import com.aliucord.manager.ui.screens.installopts.InstallOptions | ||
import com.aliucord.manager.util.IS_CUSTOM_BUILD | ||
import com.github.diamondminer88.zip.ZipWriter | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
/** | ||
* Store the install options and additional data inside the APK for future use, | ||
* for example checking what library versions were used, or performing "updates" while | ||
* maintaining the same install options as what was used upon first install. | ||
*/ | ||
class SaveMetadataStep(private val options: InstallOptions) : Step() { | ||
override val group = StepGroup.Patch | ||
override val localizedName = R.string.install_step_save_metadata | ||
|
||
private val json = Json { | ||
prettyPrint = true | ||
} | ||
|
||
override suspend fun execute(container: StepRunner) { | ||
val apk = container.getStep<CopyDependenciesStep>().patchedApk | ||
val aliuhook = container.getStep<DownloadAliuhookStep>() | ||
val injector = container.getStep<DownloadInjectorStep>() | ||
|
||
val metadata = InstallMetadata( | ||
options = options, | ||
managerVersionName = BuildConfig.VERSION_NAME, | ||
customManager = IS_CUSTOM_BUILD, | ||
aliuhookVersion = aliuhook.targetVersion, | ||
injectorCommitHash = injector.aliucordHash, | ||
) | ||
|
||
ZipWriter(apk, /* append = */ true).use { | ||
it.writeEntry("aliucord.json", json.encodeToString<InstallMetadata>(metadata)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/kotlin/com/aliucord/manager/util/ColorSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.aliucord.manager.util | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.toArgb | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.* | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
/** | ||
* (De)serialize compose's [Color] into/from an ARGB hex string. | ||
*/ | ||
object ColorSerializer : KSerializer<Color> { | ||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("Color", PrimitiveKind.STRING) | ||
|
||
override fun serialize(encoder: Encoder, value: Color) { | ||
val string = value | ||
.toArgb().toUInt() | ||
.toString(16) | ||
.padStart(8, '0') | ||
encoder.encodeString(string) | ||
} | ||
|
||
override fun deserialize(decoder: Decoder): Color { | ||
val string = decoder.decodeString() | ||
return Color(string.toInt(16)) | ||
} | ||
} |
Oops, something went wrong.