Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

移除「外部儲存空間的權限和存取權」 #1394

Draft
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

goofyz
Copy link
Collaborator

@goofyz goofyz commented Jun 5, 2024

Pull request

Issue tracker

Fixes will automatically close the related issues

Fixes #1186
Fixes #1096
Refs #997

Feature

如我在 #1186 描述的方法。「手動部署」(主頁面中按「部署」)時,Trime 會將 /sdcard/rime 的資料複製到內置目錄 /sdcard/Android/data/com.osfans.trime 中使用。之後所有的運作會在 /sdcard/Android/data/com.osfans.trime 中進行。而為了方便測試主題,每次切換「主題」時也會將相關的主題文件覆寫一次到內置目錄。

關於效能方面,「手動部置」和「同步」所需的時間一定有所增加。我的 rime文件夾 約 50MB,需時多了約 20 秒 (取決於你的配置文件大小和手機效能)。平常的文字輸入或切換輸入法等效能不變。

而為了改善效能,以下檔案不會覆製

  • 內部檔案跟外部檔案大小一樣 (若文件只修改一個 character 的話,因為大小一樣便不會複製。這條件有待商榷。)
  • build 資料夾
  • userdb 資料夾

另外, Trime 也會覆寫以下檔案回到 /sdcard/rime

  • default.custom.yaml (選擇方案後)
  • user.yaml (啟用不同方案後)
  • /sync (同步後)

最後,在「工具箱」中新增「內部資料夾」選項,可透過 Android 內置的 DocumentsUI 瀏覽內置目錄。

Code of conduct

Code style

Build pass

  • make debug

Manually test

  • Done

Code Review

  1. No wildcards import
  2. Manual build and test pass
  3. GitHub Action CI pass
  4. At least one contributor review and approve
  5. Merged clean without conflicts
  6. PR will be merged by rebase upstream base

Daily build

Login and download artifact at https://github.com/osfans/trime/actions

Additional Info

goofyz added 30 commits June 5, 2024 12:31
When manual deploy, the app will

1. copy files from external directory to app specific directory using
   `DocumentFile`.
2. delete any files that exists in app specific directory but not in external
   directory.

If files exists in both directories, the app will skip copying when both
file's sizes are the same.
…nged

The following files will be exported:

- `default.custom.yaml`
- `user.yaml`
On some devices, external storage may not be immediately mounted when `TrimeInputMethodService` is started
after device booted.  When external storage is not mounted, `RimeSession` is created but `Rime` will not be
started.

A `BroadcastReceiver` is added to listen for the storage mounted broadcast.  When the broadcast is recevied,
`RimeSession` will be re-created to start the `Rime` properly.
@shitlime
Copy link
Contributor

shitlime commented Jun 5, 2024

目前我在我的机器上测试,发现:
主题文件复制 BUG?

  1. 安装后部署
  2. 在主题选择器中选择默认以外的主题
  3. 在「工具箱」中「內部資料夾」,可以看到刚刚选择的主题文件被复制到「內部資料夾」的根目录

其他:

  1. 同文占用空间非常大(同文占用588MB;而整个 /sdcard/rime 文件夹大小是544MB,其中 build 占用186MB)
  2. 初次部署大概需要十分钟

拷贝整个 rime 文件夹似乎不是很好的选择,如果可能,希望减少拷贝一些不必要的文件?如:

  • backgrounds 背景图片文件夹
  • fonts 字体文件夹
  • sound 键盘音效文件夹

感觉这部分可以考虑限定文件名后缀为 *.trime.yaml *.schema.yaml *.custom.yaml *.lua 等这些文件,来减少不必要的文件复制……

@goofyz
Copy link
Collaborator Author

goofyz commented Jun 5, 2024

  • 主題複製是 bug,遲點修正。
  • 500mb 有點超乎想像,從未想過會這麼大。普遍用家都是這麼大的嗎?
  • 因為不知道那些檔案在什麼地方會被使用,外部資料夾的檔案不能直接使用,所以只能全都 copy。這個有點難解決。

@shitlime
Copy link
Contributor

shitlime commented Jun 5, 2024

* 500mb 有點超乎想像,從未想過會這麼大。普遍用家都是這麼大的嗎?

形码词库不会大,但是音码词库一般都很大,主要取决于方案,我个人安装的方案比较多所以有500MB。
听说最大的拼音方案词库也有几百MB,我认为一般用户应该普遍在100 ~ 300MB之间,方案比较多的用户普遍500MB ~ 1GB+

* 因為不知道那些檔案在什麼地方會被使用,外部資料夾的檔案不能直接使用,所以只能全都 copy。這個有點難解決。

感觉可以先排除一部分librime不会用到的文件夹,让trime直接使用 /sdcard/rime 中的这些文件夹:

  • backgrounds 背景图片文件夹
  • fonts 字体文件夹
  • sound 键盘音效文件夹

这个或许可以放在以后完善……


EDIT: 补充,我的fonts文件夹有120MB,这是我认为需要排除一些文件夹的原因

@Bambooin
Copy link
Collaborator

Bambooin commented Jun 5, 2024

Tested in Android 13, it's working.

Thanks for your hard working!

List and show themes with user/share directory.  Sort themes with default theme at the top and "share" themes
at the bottom.  Copy themes to the correct directory after selected.
@WhiredPlanck
Copy link
Collaborator

目前我对纯粹复制这个方案是不乐观的,虽然它最容易实作,但从性能方面考虑,最理想 的情况是所需时间多了 1 倍(因为相当于同样的东西写进了磁盘两次),而且还要考虑用户目录可能会有很多东西。如果要延续这个方案,我想到的解决办法之一就是差异复制/增量复制,但是说实话要实现起来也挺麻烦的,我个人不是很想弄。

最好的方式我认为还是找到一种稳妥的方法,可以让 librime 无痛地直接读取 SAF 限制下的外部存储空间。或者还有一计:那就是给用户自主选择是用外部还是内部存储,但这无法彻底解决权限问题。

@goofyz
Copy link
Collaborator Author

goofyz commented Jun 9, 2024

老實說,若 rime 大過100 mb 的話,我也覺得此方法不合適。

讓用戶選擇內置還是外置也是一可行選項,至少可以上 google play store 。

@WhiredPlanck
Copy link
Collaborator

@goofyz 我最近在看 rcx 的代码,发现它把 SAF 存储模拟成了 WebDAV 服务器,然后就能让 rclone 从 SAF 中同步了,我感觉很妙。规避了传统方法的限制,或许还提高了性能。

@WhiredPlanck
Copy link
Collaborator

  • 因為不知道那些檔案在什麼地方會被使用

重要的只有方案文件和主题文件,这两个需要依靠 librime 进行部署。其他字体、背景图片等不需要同步进去,可以改为直接通过 SAF 拿。

@goofyz goofyz marked this pull request as draft July 16, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

移除「外部儲存空間的權限和存取權」 文件访问权限似乎会被自动清理
4 participants