Skip to content

fix: 改为先备份再定向删除,降低误删风险#2

Open
BobYue-01 wants to merge 1 commit intoepcdiy:mainfrom
BobYue-01:main
Open

fix: 改为先备份再定向删除,降低误删风险#2
BobYue-01 wants to merge 1 commit intoepcdiy:mainfrom
BobYue-01:main

Conversation

@BobYue-01
Copy link
Copy Markdown

@BobYue-01 BobYue-01 commented Mar 29, 2026

背景

该仓库用于复现和验证安卓低版本 SDK 的权限缺陷:在授予相关权限后,应用可直接删除相册内容。
这类测试具备明显破坏性,导致用户难以在主力机上参与 OEM 机型验证,也带来误删风险。

问题确认

已确认 app_low 的原有测试逻辑存在以下行为:

  1. 会执行真实删除(调用文件删除接口),不是仅打印日志。
  2. 会递归扫描 DCIM 目录及子目录,命中条件后持续删除。
  3. 删除范围接近“全量媒体文件”(并非仅测试样本),风险较高。

修改内容

为降低破坏性并保留问题验证能力,本 PR 将 app_low 测试流程调整如下:

  • 删除策略从“直接删除”改为“先备份,后删除”。
  • 备份
    • 备份目录固定为 Pictures/FileDeleterBackup
    • 备份文件名冲突时自动重命名,避免覆盖。
    • 备份失败时跳过删除,避免数据不可恢复。
  • 删除
    • 删除范围收敛为仅限文件名前缀为 fdtest_ 的照片文件。
    • 文件类型限制为 jpg/jpeg/png,不再处理其他媒体。
  • 界面
    • 新增醒目提示文案,明确“仅处理特定命名文件 + 先备份再删除”的规则。
    • 按钮文案同步调整。

fixed: #3

Limit deletion scope to test photos only and require backup first.

  - Replace recursive direct delete flow with backup-then-delete
    processing in `MainActivity`.

  - Only process files with prefix `fdtest_` and image extensions
    `jpg/jpeg/png`; skip all other media.

  - Add backup directory creation with fallback path and duplicate
    filename handling to avoid overwrite.

  - Update UI text to clearly warn users that only prefixed test photos
    are affected and backups are saved to `Pictures/FileDeleterBackup`.
Copilot AI review requested due to automatic review settings March 29, 2026 15:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 针对 fileDeleter/app_low 中具备破坏性的“真实删除相册内容”测试流程进行降风险改造:将删除前置为“先备份再删除”,并把处理范围收敛到特定命名规则的图片文件,以降低误删风险且保留漏洞复现能力。

Changes:

  • 删除策略改为:命中目标文件后先复制备份到固定备份目录,再执行删除;备份失败则跳过删除
  • 删除范围收敛:仅处理文件名前缀 fdtest_ 且后缀为 jpg/jpeg/png 的照片
  • UI 增加醒目提示文案并调整按钮文案,明确规则与备份目录

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
fileDeleter/app_low/src/main/res/layout/activity_main.xml 更新按钮文案并新增提示 TextView,告知“仅处理 fdtest_ 前缀图片 + 先备份再删除”的规则
fileDeleter/app_low/src/main/java/com/epcdiy/filedeleter/MainActivity.java 增加备份逻辑(唯一命名、复制流、备份目录准备)并将递归删除改为“备份后删除 + 仅命中特定照片”

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 16 to 20
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;


import java.io.File;
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app_low 模块的依赖仍是 com.android.support:appcompat-v7:28.0.0,但这里使用的是 androidx.appcompat.app.AppCompatActivity。在启用 AndroidX 的情况下这通常会导致编译期找不到 AppCompatActivity(除非显式依赖 androidx.appcompat:appcompat)或产生 Support/AndroidX 混用问题;建议将 app_low/build.gradle 切换到 AndroidX 的 appcompat 依赖,或改回 android.support.v7.app.AppCompatActivity 并统一全模块依赖。

Copilot uses AI. Check for mistakes.
}
});
updateUI("警告!使用前务必备份照片!");
updateUI("提示:仅处理文件名前缀为 " + TARGET_PREFIX + " 的照片(jpg/jpeg/png),且先备份后删除。备份目录:Pictures/" + BACKUP_FOLDER_NAME);
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里提示文案固定写死备份目录为 Pictures/FileDeleterBackup,但 prepareBackupDir() 在创建公共 Pictures 目录失败时会回退到 getExternalFilesDir(...)(app 私有目录)。建议在拿到 backupDir 后用实际路径(或明确“可能回退到应用私有目录”)更新 UI 文案,避免误导用户去错误位置找备份。

Suggested change
updateUI("提示:仅处理文件名前缀为 " + TARGET_PREFIX + " 的照片(jpg/jpeg/png),且先备份后删除。备份目录:Pictures/" + BACKUP_FOLDER_NAME);
updateUI("提示:仅处理文件名前缀为 " + TARGET_PREFIX
+ " 的照片(jpg/jpeg/png),且先备份后删除。优先备份到公共目录:Pictures/"
+ BACKUP_FOLDER_NAME + ",如创建失败则可能回退到应用私有目录中。");

Copilot uses AI. Check for mistakes.
android:layout_marginTop="8dp"
android:background="#fff3cd"
android:padding="8dp"
android:text="仅处理文件名前缀为 fdtest_ 的照片(jpg/jpeg/png),并先备份到 Pictures/FileDeleterBackup 后再删除。"
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该提示文案写死“备份到 Pictures/FileDeleterBackup”,但代码里 prepareBackupDir() 可能会回退到应用私有外部目录(getExternalFilesDir(...))。建议让界面显示实际备份路径,或至少说明备份目录可能回退,否则用户可能找不到备份文件。

Suggested change
android:text="仅处理文件名前缀为 fdtest_ 的照片(jpg/jpeg/png),并先备份到 Pictures/FileDeleterBackup 后再删除。"
android:text="仅处理文件名前缀为 fdtest_ 的照片(jpg/jpeg/png),并先备份到名为 FileDeleterBackup 的文件夹(通常位于公共图片目录,无法创建时可能回退到应用私有外部目录)后再删除。"

Copilot uses AI. Check for mistakes.
Comment on lines +139 to 147
private boolean backupFile(File source, File backupDir) {
File outFile = buildUniqueBackupFile(backupDir, source.getName());
try (InputStream inputStream = new FileInputStream(source);
OutputStream outputStream = new FileOutputStream(outFile)) {
copyStream(inputStream, outputStream);
return true;
} catch (Exception e) {
return false;
}
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backupFile() 捕获了所有 Exception 直接返回 false,但没有把失败原因输出到日志或界面,排查“备份失败”会比较困难。建议至少 Log.e(...) 记录异常信息/堆栈,或把 e.getMessage() 附加到 UI 的失败提示中(注意不要泄露敏感路径可按需截断)。

Copilot uses AI. Check for mistakes.
@BobYue-01
Copy link
Copy Markdown
Author

作为简易 POC 测试的一个简易修补 PR,Copilot 的建议徒增复杂性。

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.

[Improve] 避免相册破坏性全量删除:改为针对「特定命名的测试文件」进行备份 + 定向删除

2 participants