From 0850401dc43b1940242c1405daf5a71577551ede Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Mon, 13 May 2019 15:56:27 +0200 Subject: [PATCH] Fixed crash where new application asks for root access --- .../main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt | 2 +- .../com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt b/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt index e8ef9ddf2..16ce52afb 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/database/PolicyDao.kt @@ -44,7 +44,7 @@ class PolicyDao( condition { equals("uid", uid) } - }.map { it.first().toPolicy(context.packageManager) } + }.map { it.firstOrNull()?.toPolicy(context.packageManager) } .doOnError { if (it is PackageManager.NameNotFoundException) { delete(uid).subscribe() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt index b5abb974a..e452db355 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/surequest/SuRequestViewModel.kt @@ -110,7 +110,8 @@ class SuRequestViewModel( val bundle = connector.readSocketInput() val uid = bundle.getString("uid")?.toIntOrNull() ?: return false appRepo.deleteOutdated().blockingGet() // wrong! - policy = appRepo.fetch(uid).blockingGet() ?: uid.toPolicy(packageManager) + policy = runCatching { appRepo.fetch(uid).blockingGet() } + .getOrDefault(uid.toPolicy(packageManager)) } catch (e: IOException) { e.printStackTrace() return false