[QPR1][Security] Fix RequestIgnoreBatteryOptimizations info disclosure

after discussed with kdeus@ we will remove the setResult() from the
dialog action to avoid the caller apps can distinguish the users
interaction behavior, and declared REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
in other applications.

Bug: 195963373
Test: make SettingsRoboTests
Change-Id: Ia2e47c493c206e96b0bc1d9f08735c0f9474c233
Merged-In: Ia2e47c493c206e96b0bc1d9f08735c0f9474c233
(cherry picked from commit 518d6df4f48172a55b9785bfb979b9500f0f66c8)
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);
+    }
 }