mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Mitigate OOM during update
This commit is contained in:
parent
f134517f11
commit
cd8499f742
@ -63,6 +63,7 @@
|
|||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:defaultToDeviceProtectedStorage="true"
|
android:defaultToDeviceProtectedStorage="true"
|
||||||
android:directBootAware="true"
|
android:directBootAware="true"
|
||||||
|
android:largeHeap="true"
|
||||||
android:name=".CrashLoggingApplication">
|
android:name=".CrashLoggingApplication">
|
||||||
|
|
||||||
<!-- Services -->
|
<!-- Services -->
|
||||||
|
@ -92,7 +92,7 @@ object UpdateStatus {
|
|||||||
val isDownloading = mutableStateOf(false)
|
val isDownloading = mutableStateOf(false)
|
||||||
val downloadText = mutableStateOf("")
|
val downloadText = mutableStateOf("")
|
||||||
|
|
||||||
var downloadedUpdate: ByteArray? = null
|
var downloadedUpdate: ByteArrayOutputStream? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun install(scope: CoroutineScope, context: Context, inputStream: InputStream, dataLength: Long, updateStatusText: (String) -> Unit) {
|
private suspend fun install(scope: CoroutineScope, context: Context, inputStream: InputStream, dataLength: Long, updateStatusText: (String) -> Unit) {
|
||||||
@ -109,7 +109,7 @@ private suspend fun install(scope: CoroutineScope, context: Context, inputStream
|
|||||||
session = packageInstaller.openSession(sessionId)
|
session = packageInstaller.openSession(sessionId)
|
||||||
|
|
||||||
if(UpdateStatus.downloadedUpdate == null) {
|
if(UpdateStatus.downloadedUpdate == null) {
|
||||||
ByteArrayOutputStream(dataLength.toInt()).use { outputStream ->
|
UpdateStatus.downloadedUpdate = ByteArrayOutputStream(dataLength.toInt()).use { outputStream ->
|
||||||
inputStream.copyToOutputStream(dataLength, outputStream) { progress ->
|
inputStream.copyToOutputStream(dataLength, outputStream) { progress ->
|
||||||
val progressText = "${(progress * 100.0f).toInt()}%";
|
val progressText = "${(progress * 100.0f).toInt()}%";
|
||||||
if (lastProgressText != progressText) {
|
if (lastProgressText != progressText) {
|
||||||
@ -119,17 +119,16 @@ private suspend fun install(scope: CoroutineScope, context: Context, inputStream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateStatus.downloadedUpdate = outputStream.toByteArray()
|
// Note: .use will close the outputStream, but closing has no effect
|
||||||
|
// on ByteArrayOutputStream
|
||||||
|
outputStream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
session.openWrite("package", 0, dataLength).use { sessionStream ->
|
session.openWrite("package", 0, dataLength).use { sessionStream ->
|
||||||
UpdateStatus.downloadedUpdate!!.inputStream().use { byteStream ->
|
UpdateStatus.downloadedUpdate!!.writeTo(sessionStream)
|
||||||
byteStream.copyToOutputStream(dataLength, sessionStream) { }
|
session.fsync(sessionStream)
|
||||||
}
|
|
||||||
|
|
||||||
session.fsync(sessionStream);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
val intent = Intent(context, InstallReceiver::class.java);
|
val intent = Intent(context, InstallReceiver::class.java);
|
||||||
|
Loading…
Reference in New Issue
Block a user