Skip to content

Commit

Permalink
fix: Null stats for package
Browse files Browse the repository at this point in the history
Fatal Exception: java.lang.NullPointerException: getService().queryStatsF…ackage(packageInfo, user) must not be null
       at com.xayah.librootservice.service.RemoteRootService.queryStatsForPackage(RemoteRootService.java:80)
       at com.xayah.librootservice.service.RemoteRootService$queryStatsForPackage$1.invokeSuspend(RemoteRootService.java:12)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:8)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:105)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:3)
       at kotlinx.coroutines.scheduling.TaskImpl.run(TaskImpl.java:2)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:95)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:95)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:95)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:95)

Change-Id: Ib75123aeafd3bc1adac72407d15b15b992912eb5
  • Loading branch information
XayahSuSuSu committed Sep 28, 2023
1 parent 94aee1d commit 9db10e0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,23 @@ fun PackageBackupList() {
EnvUtil.saveIcon(context, packageInfo.packageName, icon)
}
val storageStats = StorageStats()
remoteRootService.queryStatsForPackage(packageInfo, remoteRootService.getUserHandle(userId)).also { stats ->
storageStats.appBytes = stats.appBytes
storageStats.cacheBytes = stats.cacheBytes
storageStats.dataBytes = stats.dataBytes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) storageStats.externalCacheBytes = stats.externalCacheBytes
tryService(onFailed = { msg ->
scope.launch {
state = state.setState(ListState.Error)
snackbarHostState.showSnackbar(
message = "$msg\n${context.getString(R.string.remote_service_err_info)}",
duration = SnackbarDuration.Indefinite
)
}
}) {
remoteRootService.queryStatsForPackage(packageInfo, remoteRootService.getUserHandle(userId)).also { stats ->
if (stats != null) {
storageStats.appBytes = stats.appBytes
storageStats.cacheBytes = stats.cacheBytes
storageStats.dataBytes = stats.dataBytes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) storageStats.externalCacheBytes = stats.externalCacheBytes
}
}
}

newPackages.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal class RemoteRootServiceImpl : IRemoteRootService.Stub() {
UserHandleHidden.of(userId)
}

override fun queryStatsForPackage(packageInfo: PackageInfo, user: UserHandle): StorageStats = synchronized(lock) {
override fun queryStatsForPackage(packageInfo: PackageInfo, user: UserHandle): StorageStats? = synchronized(lock) {
storageStatsManager.queryStatsForPackage(packageInfo.applicationInfo.storageUuid, packageInfo.packageName, user)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class RemoteRootService(private val context: Context) {

suspend fun getUserHandle(userId: Int): UserHandle = getService().getUserHandle(userId)

suspend fun queryStatsForPackage(packageInfo: PackageInfo, user: UserHandle): StorageStats = getService().queryStatsForPackage(packageInfo, user)
suspend fun queryStatsForPackage(packageInfo: PackageInfo, user: UserHandle): StorageStats? = getService().queryStatsForPackage(packageInfo, user)

suspend fun getUsers(): List<UserInfo> = getService().users
}

0 comments on commit 9db10e0

Please sign in to comment.