Skip to content

Commit b8183d0

Browse files
author
Fastace
committed
Fix:修复目前会扫描恢复路径下所有包名,预期应该恢复本次APP的BUG
1 parent 4475b46 commit b8183d0

12 files changed

Lines changed: 74 additions & 5 deletions

File tree

source/core/service/src/main/kotlin/com/xayah/core/service/AbstractProcessingServiceProxy.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ abstract class AbstractProcessingServiceProxy {
8989
}
9090
}
9191

92+
abstract fun startRestore(packageName: String = "")
93+
9294
suspend fun initialize() = getService().initialize()
9395

9496
suspend fun preprocessing() = getService().preprocessing()

source/core/service/src/main/kotlin/com/xayah/core/service/medium/backup/ProcessingServiceProxyCloudImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyCloudImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, BackupServiceCloudImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/medium/backup/ProcessingServiceProxyLocalImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyLocalImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, BackupServiceLocalImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/medium/restore/ProcessingServiceProxyCloudImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyCloudImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, RestoreServiceCloudImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/medium/restore/ProcessingServiceProxyLocalImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyLocalImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, RestoreServiceLocalImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/packages/backup/ProcessingServiceProxyCloudImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyCloudImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, BackupServiceCloudImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/packages/backup/ProcessingServiceProxyLocalImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyLocalImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, BackupServiceLocalImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/packages/restore/ProcessingServiceProxyCloudImpl.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@ class ProcessingServiceProxyCloudImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, RestoreServiceCloudImpl::class.java) }
15+
// 在所有其他 ProcessingServiceProxy 实现中添加
16+
override fun startRestore(packageName: String) {
17+
// 暂时不支持,抛出异常或记录日志
18+
throw UnsupportedOperationException("startRestore with package name not supported")
19+
}
1520
}

source/core/service/src/main/kotlin/com/xayah/core/service/packages/restore/ProcessingServiceProxyLocalImpl.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@ class ProcessingServiceProxyLocalImpl @Inject constructor() : AbstractProcessing
1212
override lateinit var context: Context
1313

1414
override val intent by lazy { Intent(context, RestoreServiceLocalImpl::class.java) }
15-
}
15+
16+
// 实现支持包名参数的启动方法
17+
override fun startRestore(packageName: String) {
18+
val intent = Intent(context, RestoreServiceLocalImpl::class.java)
19+
if (packageName.isNotEmpty()) {
20+
intent.putExtra("TARGET_PACKAGE_NAME", packageName)
21+
}
22+
context.startForegroundService(intent)
23+
}
24+
}

source/core/service/src/main/kotlin/com/xayah/core/service/packages/restore/RestoreServiceLocalImpl.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xayah.core.service.packages.restore
22

33
import android.util.Log
4+
import android.content.Intent
45
import com.xayah.core.data.repository.PackageRepository
56
import com.xayah.core.data.repository.TaskRepository
67
import com.xayah.core.database.dao.PackageDao
@@ -24,6 +25,8 @@ import java.io.File
2425
internal class RestoreServiceLocalImpl @Inject constructor() : AbstractRestoreService() {
2526
override val mTAG: String = "RestoreServiceLocalImpl"
2627

28+
private var mTargetPackageName: String = ""
29+
2730
@Inject
2831
override lateinit var mRootService: RemoteRootService
2932

@@ -51,6 +54,16 @@ internal class RestoreServiceLocalImpl @Inject constructor() : AbstractRestoreSe
5154
)
5255
}
5356

57+
override fun onCreate() {
58+
super.onCreate()
59+
}
60+
61+
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
62+
mTargetPackageName = intent?.getStringExtra("TARGET_PACKAGE_NAME") ?: ""
63+
Log.d(mTAG, "接收到目标包名: $mTargetPackageName")
64+
return super.onStartCommand(intent, flags, startId)
65+
}
66+
5467
override suspend fun getPackages(): List<PackageEntity> {
5568
// 检查是否为 Restic 恢复场景
5669
val restoreDir = File("${mRootDir}/restore")
@@ -63,9 +76,16 @@ internal class RestoreServiceLocalImpl @Inject constructor() : AbstractRestoreSe
6376
}
6477

6578
Log.d(mTAG, "查询参数: cloud=, backupDir=$backupDir")
66-
val packages = mPackageRepo.queryActivated(OpType.RESTORE, "", backupDir)
67-
Log.d(mTAG, "查询到 ${packages.size} 个激活的应用")
79+
val allPackages = mPackageRepo.queryActivated(OpType.RESTORE, "", backupDir)
80+
81+
// 使用传递的包名进行筛选
82+
val packages = if (mTargetPackageName.isNotEmpty()) {
83+
allPackages.filter { it.packageName == mTargetPackageName }
84+
} else {
85+
allPackages
86+
}
6887

88+
Log.d(mTAG, "筛选后查询到 ${packages.size} 个应用")
6989
return packages
7090
}
7191

0 commit comments

Comments
 (0)