Skip to content

Commit

Permalink
[Feature] Add badge for encrypted files.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Sep 18, 2023
1 parent 892229c commit 1c156ff
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import me.zhanghai.android.files.file.formatShort
import me.zhanghai.android.files.file.iconRes
import me.zhanghai.android.files.file.isApk
import me.zhanghai.android.files.provider.archive.isArchivePath
import me.zhanghai.android.files.provider.common.isEncrypted
import me.zhanghai.android.files.settings.Settings
import me.zhanghai.android.files.ui.AnimatedListAdapter
import me.zhanghai.android.files.ui.CheckableForegroundLinearLayout
Expand Down Expand Up @@ -301,6 +302,8 @@ class FileListAdapter(
} else {
R.drawable.symbolic_link_badge_icon_18dp
}
} else if (file.attributesNoFollowLinks.isEncrypted()) {
R.drawable.encrypted_badge_icon_18dp
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.parcelize.WriteWith
import me.zhanghai.android.files.provider.archive.archiver.ReadArchive
import me.zhanghai.android.files.provider.common.AbstractPosixFileAttributes
import me.zhanghai.android.files.provider.common.ByteString
import me.zhanghai.android.files.provider.common.EncryptedFileAttributes
import me.zhanghai.android.files.provider.common.FileTimeParceler
import me.zhanghai.android.files.provider.common.PosixFileModeBit
import me.zhanghai.android.files.provider.common.PosixFileType
Expand All @@ -31,8 +32,11 @@ internal class ArchiveFileAttributes(
override val group: PosixGroup?,
override val mode: Set<PosixFileModeBit>?,
override val seLinuxContext: ByteString?,
private val isEncrypted: Boolean,
private val entryName: String
) : AbstractPosixFileAttributes() {
) : AbstractPosixFileAttributes(), EncryptedFileAttributes {
override fun isEncrypted(): Boolean = isEncrypted

fun entryName(): String = entryName

companion object {
Expand All @@ -47,10 +51,11 @@ internal class ArchiveFileAttributes(
val group = entry.group
val mode = entry.mode
val seLinuxContext = null
val isEncrypted = entry.isEncrypted
val entryName = entry.name
return ArchiveFileAttributes(
lastModifiedTime, lastAccessTime, creationTime, type, size, fileKey, owner, group,
mode, seLinuxContext, entryName
mode, seLinuxContext, isEncrypted, entryName
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ object ArchiveReader {
private fun createDirectoryEntry(name: String): ReadArchive.Entry {
require(!name.endsWith("/")) { "name $name should not end with a slash" }
return ReadArchive.Entry(
name, null, null, null, PosixFileType.DIRECTORY, 0, null, null,
name, false, null, null, null, PosixFileType.DIRECTORY, 0, null, null,
PosixFileMode.DIRECTORY_DEFAULT, null
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class ReadArchive : Closeable {
?: throw ArchiveException(
Archive.ERRNO_FATAL, "pathname == null && pathnameUtf8 == null"
)
val isEncrypted = ArchiveEntry.isEncrypted(entry)
val stat = ArchiveEntry.stat(entry)
val lastModifiedTime = if (ArchiveEntry.mtimeIsSet(entry)) {
FileTime.from(
Expand Down Expand Up @@ -177,8 +178,8 @@ class ReadArchive : Closeable {
val symbolicLinkTarget =
getEntryString(ArchiveEntry.symlinkUtf8(entry), ArchiveEntry.symlink(entry), charset)
return Entry(
name, lastModifiedTime, lastAccessTime, creationTime, type, size, owner, group, mode,
symbolicLinkTarget
name, isEncrypted, lastModifiedTime, lastAccessTime, creationTime, type, size, owner,
group, mode, symbolicLinkTarget
)
}

Expand Down Expand Up @@ -209,6 +210,7 @@ class ReadArchive : Closeable {

class Entry(
val name: String,
val isEncrypted: Boolean,
val lastModifiedTime: FileTime?,
val lastAccessTime: FileTime?,
val creationTime: FileTime?,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com>
* All Rights Reserved.
*/

package me.zhanghai.android.files.provider.common

import java8.nio.file.attribute.BasicFileAttributes

interface EncryptedFileAttributes {
fun isEncrypted(): Boolean
}

fun BasicFileAttributes.isEncrypted(): Boolean =
if (this is EncryptedFileAttributes) isEncrypted() else false
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/encrypted_badge_icon_18dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
~ Copyright (c) 2023 Hai Zhang <dreaming.in.code.zh@gmail.com>
~ All Rights Reserved.
-->

<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="18dp"
android:height="18dp"
android:viewportWidth="18"
android:viewportHeight="18">

<path
android:fillColor="@color/file_icon_grey"
android:pathData="M9,0a9,9 0 0,0 0,18 9,9 0 0,0 0,-18zm0,2a7,7 0 0,1 0,14 7,7 0 0,1 0,-14zM12,7h-0.5v-1a2.5,2.5 0 0,0 -5,0v1h-0.5a1,1 0 0,0 -1,1v4.5a1,1 0 0,0 1,1h6a1,1 0 0,0 1,-1v-4.5a1,1 0 0,0 -1,-1zm-2,0h-2v-1a1,1 0 0,1 2,0zm-1,4.25a1,1 0 0,1 0,-2 1,1 0 0,1 0,2z" />
</vector>

0 comments on commit 1c156ff

Please sign in to comment.