From 42d5979f6981a7e6b3e1b191e465f94faeda2d0f Mon Sep 17 00:00:00 2001 From: ykhung Date: Wed, 13 Apr 2022 11:18:18 +0800 Subject: [PATCH] [Security] Verify the permission first before querying installed apps Verify the target app "REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" permission first before querying installed apps information to avoid the exposed the installed apps information and improve the performance by applying the early return flow. Bug: 227753723 Test: make RunSettingsRoboTests Change-Id: Ib5826b8082f4bf14f93d5ff4d2d332dc395bf9a8 --- .../RequestIgnoreBatteryOptimizations.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java b/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java index ee4609001bb..9ef8c8ce747 100644 --- a/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java +++ b/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java @@ -69,15 +69,6 @@ public class RequestIgnoreBatteryOptimizations extends AlertActivity implements return; } - ApplicationInfo ai; - try { - ai = getPackageManager().getApplicationInfo(mPackageName, 0); - } catch (PackageManager.NameNotFoundException e) { - debugLog("Requested package doesn't exist: " + mPackageName); - finish(); - return; - } - if (getPackageManager().checkPermission( Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, mPackageName) != PackageManager.PERMISSION_GRANTED) { @@ -87,6 +78,15 @@ public class RequestIgnoreBatteryOptimizations extends AlertActivity implements return; } + ApplicationInfo ai; + try { + ai = getPackageManager().getApplicationInfo(mPackageName, 0); + } catch (PackageManager.NameNotFoundException e) { + debugLog("Requested package doesn't exist: " + mPackageName); + finish(); + return; + } + final AlertController.AlertParams p = mAlertParams; final CharSequence appLabel = ai.loadSafeLabel(getPackageManager(), PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, PackageItemInfo.SAFE_LABEL_FLAG_TRIM