Lock and own-files rules: Pause needs the unlock, the composer opens picked files as a share does
- A scheduled task's Pause in its notification acted on the account from a locked phone (where the lock screen shows notifications in full); it now asks for the unlock, as Allow once, Deny, Run again and Mark read do. - The composer's attachments were the one upload still opened with contentResolver.openInputStream: a picker's answer is any app's word, and one that named a copy held by this app's own provider, or a file: path, was read with the app's own rights. Picked files are now opened through SharedSource, like a share's and the file manager's; only the photo the camera wrote for the composer (camera/ under the app's own provider) is read directly. - A photo taken for the composer whose upload failed stayed in the cache for good: the camera folder is cleared at sign-out and on a switch of instance, and swept by age at start. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
3 files changed
+40
-8
No files matched your search
@@ -146,7 +146,8 @@ object Notifications {
|
||||
* server cut them (BigTextStyle opens them). On the lock screen only the public version: the
|
||||
* app's name and "A scheduled task has a result." (or failed) -- nothing from the account, so
|
||||
* the server's `public` (which names the task) is not used. A tap and Open go to the run;
|
||||
* Run again starts it again, once the phone is unlocked; Pause is there when offered.
|
||||
* Run again starts it again and Pause (there when offered) pauses the task, each only once
|
||||
* the phone is unlocked.
|
||||
*/
|
||||
private fun scheduled(context: Context, instance: String, payload: PushPayload) {
|
||||
val notice = ScheduledNotice.from(payload) ?: return
|
||||
@@ -179,7 +180,8 @@ object Notifications {
|
||||
}
|
||||
if (notice.pause) {
|
||||
val pause = scheduleAction(context, instance, notice.scheduleId, notice.id, ScheduleActionReceiver.PAUSE)
|
||||
builder.addAction(0, notice.label("pause", context.getString(R.string.schedule_pause)), pause)
|
||||
// It acts on the account, as Run again does: only once the phone is unlocked.
|
||||
builder.addAction(unlocked(notice.label("pause", context.getString(R.string.schedule_pause)), pause))
|
||||
}
|
||||
NotificationManagerCompat.from(context).notify(notice.id, builder.build())
|
||||
}
|
||||
|
||||
@@ -44,7 +44,10 @@ import eu.llembas.android.api.serving
|
||||
import eu.llembas.android.api.whereabouts
|
||||
import eu.llembas.android.auth.Instance
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.share.SharedRefused
|
||||
import eu.llembas.android.share.SharedSource
|
||||
import eu.llembas.android.ui.explain
|
||||
import eu.llembas.android.ui.files.FileCache
|
||||
import eu.llembas.android.ui.files.noSuchRoute
|
||||
import eu.llembas.android.whileOpen
|
||||
import kotlinx.coroutines.CancellationException
|
||||
@@ -136,6 +139,14 @@ data class Draft(
|
||||
val image: Boolean = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* Whether an address to attach is the photo the camera wrote for the composer: one of this
|
||||
* app's own provider ([own], its authority), in the camera's folder ([segments]: the address's
|
||||
* path). Only that is read with the app's own rights; a copy of one of the account's files
|
||||
* that the same provider holds for another app is not a photo, whoever names it.
|
||||
*/
|
||||
fun composerPhoto(authority: String?, segments: List<String>, own: String): Boolean = authority == own && segments.size == 2 && segments[0] == FileCache.CAMERA
|
||||
|
||||
/** The one tool a message may force (the server's `FORCEABLE_TOOLS`): make a picture. */
|
||||
const val IMAGE_TOOL = "image_generate"
|
||||
|
||||
@@ -1144,20 +1155,28 @@ class ChatViewModel(app: Application) :
|
||||
viewModelScope.launch {
|
||||
uploadBegins()
|
||||
try {
|
||||
val resolver = getApplication<Application>().contentResolver
|
||||
val app = getApplication<Application>()
|
||||
val resolver = app.contentResolver
|
||||
for (uri in uris) {
|
||||
// The one address of this app's own that is taken: the photo the camera wrote for
|
||||
// the composer. Every other is a picker's word -- which may be any app's -- and is
|
||||
// opened as a share's is (SharedSource): never a file of this app's own.
|
||||
val photo = composerPhoto(uri.authority, uri.pathSegments, photoAuthority)
|
||||
val (name, bytes) = withContext(Dispatchers.IO) {
|
||||
val name = resolver.query(uri, arrayOf(OpenableColumns.DISPLAY_NAME), null, null, null)?.use { c ->
|
||||
if (c.moveToFirst()) c.getString(0) else null
|
||||
} ?: "file"
|
||||
name to (resolver.openInputStream(uri)?.use { it.readBytes() } ?: ByteArray(0))
|
||||
val stream = if (photo) resolver.openInputStream(uri) else SharedSource.open(app, uri)
|
||||
name to (stream?.use { it.readBytes() } ?: ByteArray(0))
|
||||
}
|
||||
val mime = resolver.getType(uri) ?: "application/octet-stream"
|
||||
val stored = api().upload(name, mime, bytes, _state.value.chat?.id)
|
||||
_state.update { it.copy(pending = it.pending + stored) }
|
||||
// A photo the camera took for this message is the server's now.
|
||||
if (uri.authority == photoAuthority) runCatching { resolver.delete(uri, null, null) }
|
||||
if (photo) runCatching { resolver.delete(uri, null, null) }
|
||||
}
|
||||
} catch (_: SharedRefused) {
|
||||
_state.update { it.copy(error = getApplication<Application>().getString(R.string.share_refused)) }
|
||||
} catch (e: Exception) {
|
||||
fail(e)
|
||||
}
|
||||
@@ -1223,7 +1242,7 @@ class ChatViewModel(app: Application) :
|
||||
*/
|
||||
override fun photoTarget(): Uri {
|
||||
val app = getApplication<Application>()
|
||||
val dir = File(app.cacheDir, "camera").apply { mkdirs() }
|
||||
val dir = File(app.cacheDir, FileCache.CAMERA).apply { mkdirs() }
|
||||
val file = File(dir, "photo-${System.currentTimeMillis()}.jpg")
|
||||
return FileProvider.getUriForFile(app, photoAuthority, file)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ import java.util.UUID
|
||||
* handed over, nor when the screen that made it closes or the app starts again: the other app
|
||||
* may still be reading it (a mail being written). So it goes by its age alone, [SHARED_KEPT_MS]
|
||||
* after it was written -- looked at when the app starts, when a screen with transfers closes and
|
||||
* before a new copy is made -- and all of them go at sign-out and on a switch of instance. No
|
||||
* before a new copy is made -- and all of them go at sign-out and on a switch of instance, with
|
||||
* the photos taken for the composer ([CAMERA]). No
|
||||
* storage permission is involved: what the person keeps, they save through the system's own
|
||||
* "Save to" page.
|
||||
*/
|
||||
@@ -45,6 +46,14 @@ object FileCache {
|
||||
private const val VIEWING = "viewing"
|
||||
private const val SHARED = "shared"
|
||||
|
||||
/**
|
||||
* The folder a photo for the composer is taken into (`res/xml/file_paths.xml`). A photo is
|
||||
* deleted once it is uploaded; one whose upload failed, or that was never attached, would
|
||||
* otherwise stay for good -- so these go with the rest at sign-out and on a switch of
|
||||
* instance, and by their age when the app starts.
|
||||
*/
|
||||
const val CAMERA = "camera"
|
||||
|
||||
/** How long a copy another app was handed is kept: an hour. */
|
||||
const val SHARED_KEPT_MS = 60 * 60 * 1000L
|
||||
|
||||
@@ -59,13 +68,15 @@ object FileCache {
|
||||
|
||||
/** Every copy, gone: at sign-out and on a switch of instance. */
|
||||
fun clear(context: Context) {
|
||||
for (name in listOf(VIEWING, SHARED)) runCatching { File(context.cacheDir, name).deleteRecursively() }
|
||||
for (name in listOf(VIEWING, SHARED, CAMERA)) runCatching { File(context.cacheDir, name).deleteRecursively() }
|
||||
}
|
||||
|
||||
/** When the process starts: no viewer is open, so their copies go; the shared ones by their age. */
|
||||
fun atStart(context: Context) {
|
||||
runCatching { File(context.cacheDir, VIEWING).deleteRecursively() }
|
||||
sweepShared(context)
|
||||
// A photo being taken right now is younger than this; one left from a failed upload is not.
|
||||
sweep(File(context.cacheDir, CAMERA), System.currentTimeMillis(), SHARED_KEPT_MS)
|
||||
}
|
||||
|
||||
/** The shared copies older than [olderThanMs], and no other. */
|
||||
|
||||
Reference in new issue
Block a user