Merge "[QPR1][Security] Fix RequestIgnoreBatteryOptimizations info disclosure" into sc-qpr1-dev am: 71327943dc

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15596897

Change-Id: I3d91b11afeb397e7bddea0b82d0cfe4d2faafece
diff --git a/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java b/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java
index f75fccc..7caad60 100644
--- a/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java
+++ b/src/com/android/settings/fuelgauge/RequestIgnoreBatteryOptimizations.java
@@ -32,10 +32,11 @@
 
 public class RequestIgnoreBatteryOptimizations extends AlertActivity implements
         DialogInterface.OnClickListener {
-    static final String TAG = "RequestIgnoreBatteryOptimizations";
+    private static final String TAG = "RequestIgnoreBatteryOptimizations";
+    private static final boolean DEBUG = false;
 
     private PowerWhitelistManager mPowerWhitelistManager;
-    String mPackageName;
+    private String mPackageName;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -45,14 +46,14 @@
 
         Uri data = getIntent().getData();
         if (data == null) {
-            Log.w(TAG, "No data supplied for IGNORE_BATTERY_OPTIMIZATION_SETTINGS in: "
+            debugLog("No data supplied for IGNORE_BATTERY_OPTIMIZATION_SETTINGS in: "
                     + getIntent());
             finish();
             return;
         }
         mPackageName = data.getSchemeSpecificPart();
         if (mPackageName == null) {
-            Log.w(TAG, "No data supplied for IGNORE_BATTERY_OPTIMIZATION_SETTINGS in: "
+            debugLog("No data supplied for IGNORE_BATTERY_OPTIMIZATION_SETTINGS in: "
                     + getIntent());
             finish();
             return;
@@ -60,7 +61,7 @@
 
         PowerManager power = getSystemService(PowerManager.class);
         if (power.isIgnoringBatteryOptimizations(mPackageName)) {
-            Log.i(TAG, "Not should prompt, already ignoring optimizations: " + mPackageName);
+            debugLog("Not should prompt, already ignoring optimizations: " + mPackageName);
             finish();
             return;
         }
@@ -69,7 +70,7 @@
         try {
             ai = getPackageManager().getApplicationInfo(mPackageName, 0);
         } catch (PackageManager.NameNotFoundException e) {
-            Log.w(TAG, "Requested package doesn't exist: " + mPackageName);
+            debugLog("Requested package doesn't exist: " + mPackageName);
             finish();
             return;
         }
@@ -77,7 +78,7 @@
         if (getPackageManager().checkPermission(
                 Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, mPackageName)
                 != PackageManager.PERMISSION_GRANTED) {
-            Log.w(TAG, "Requested package " + mPackageName + " does not hold permission "
+            debugLog("Requested package " + mPackageName + " does not hold permission "
                     + Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
             finish();
             return;
@@ -105,10 +106,13 @@
         switch (which) {
             case BUTTON_POSITIVE:
                 mPowerWhitelistManager.addToWhitelist(mPackageName);
-                setResult(RESULT_OK);
                 break;
             case BUTTON_NEGATIVE:
                 break;
         }
     }
+
+    private static void debugLog(String debugContent) {
+        if (DEBUG) Log.w(TAG, debugContent);
+    }
 }