Merge "When restrict, use uid inside AppInfo" into pi-dev
diff --git a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
index 3675a83..69b5e9e 100644
--- a/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceController.java
@@ -129,6 +129,7 @@
     @VisibleForTesting
     void showDialog(boolean restricted) {
         final AppInfo appInfo = new AppInfo.Builder()
+                .setUid(mUid)
                 .setPackageName(mTargetPackage)
                 .build();
         BatteryTip tip = restricted
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
index 0009451..5941183 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppAction.java
@@ -59,7 +59,7 @@
             final AppInfo appInfo = appInfos.get(i);
             final String packageName = appInfo.packageName;
             // Force app standby, then app can't run in the background
-            mBatteryUtils.setForceAppStandby(mBatteryUtils.getPackageUid(packageName), packageName,
+            mBatteryUtils.setForceAppStandby(appInfo.uid, packageName,
                     AppOpsManager.MODE_IGNORED);
             if (CollectionUtils.isEmpty(appInfo.anomalyTypes)) {
                 // Only log context if there is no anomaly type
diff --git a/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java b/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
index fab7b01..9f0da63 100644
--- a/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
+++ b/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppAction.java
@@ -23,6 +23,7 @@
 
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batterytip.AppInfo;
 import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
 
 /**
@@ -44,12 +45,12 @@
      */
     @Override
     public void handlePositiveAction(int metricsKey) {
-        final String packageName = mUnRestrictAppTip.getPackageName();
+        final AppInfo appInfo = mUnRestrictAppTip.getUnrestrictAppInfo();
         // Clear force app standby, then app can run in the background
-        mBatteryUtils.setForceAppStandby(mBatteryUtils.getPackageUid(packageName), packageName,
+        mBatteryUtils.setForceAppStandby(appInfo.uid, appInfo.packageName,
                 AppOpsManager.MODE_ALLOWED);
         mMetricsFeatureProvider.action(mContext,
-                MetricsProto.MetricsEvent.ACTION_TIP_UNRESTRICT_APP, packageName, Pair.create(
-                        MetricsProto.MetricsEvent.FIELD_CONTEXT, metricsKey));
+                MetricsProto.MetricsEvent.ACTION_TIP_UNRESTRICT_APP, appInfo.packageName,
+                Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, metricsKey));
     }
 }
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppActionTest.java
index 0e06765..836f458 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/RestrictAppActionTest.java
@@ -46,6 +46,8 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 public class RestrictAppActionTest {
 
+    private static final int UID_1 = 12345;
+    private static final int UID_2 = 23456;
     private static final String PACKAGE_NAME_1 = "com.android.app1";
     private static final String PACKAGE_NAME_2 = "com.android.app2";
     private static final int ANOMALY_WAKEUP = 0;
@@ -63,9 +65,11 @@
 
         final List<AppInfo> mAppInfos = new ArrayList<>();
         mAppInfos.add(new AppInfo.Builder()
+                .setUid(UID_1)
                 .setPackageName(PACKAGE_NAME_1)
                 .build());
         mAppInfos.add(new AppInfo.Builder()
+                .setUid(UID_2)
                 .setPackageName(PACKAGE_NAME_2)
                 .addAnomalyType(ANOMALY_BT)
                 .addAnomalyType(ANOMALY_WAKEUP)
@@ -87,9 +91,9 @@
         mRestrictAppAction.handlePositiveAction(METRICS_KEY);
 
         verify(mBatteryUtils)
-                .setForceAppStandby(anyInt(), eq(PACKAGE_NAME_1), eq(AppOpsManager.MODE_IGNORED));
+                .setForceAppStandby(UID_1, PACKAGE_NAME_1, AppOpsManager.MODE_IGNORED);
         verify(mBatteryUtils)
-                .setForceAppStandby(anyInt(), eq(PACKAGE_NAME_2), eq(AppOpsManager.MODE_IGNORED));
+                .setForceAppStandby(UID_2, PACKAGE_NAME_2, AppOpsManager.MODE_IGNORED);
         verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
                 MetricsProto.MetricsEvent.ACTION_TIP_RESTRICT_APP, PACKAGE_NAME_1, Pair.create(
                         MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY));
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppActionTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppActionTest.java
index f176324..7fdf46a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppActionTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/actions/UnrestrictAppActionTest.java
@@ -42,6 +42,7 @@
 @RunWith(SettingsRobolectricTestRunner.class)
 public class UnrestrictAppActionTest {
 
+    private static final int UID_1 = 12345;
     private static final String PACKAGE_NAME_1 = "com.android.app1";
     private static final int METRICS_KEY = 1;
 
@@ -54,7 +55,10 @@
     public void setUp() {
         MockitoAnnotations.initMocks(this);
 
-        final AppInfo appInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME_1).build();
+        final AppInfo appInfo = new AppInfo.Builder()
+                .setUid(UID_1)
+                .setPackageName(PACKAGE_NAME_1)
+                .build();
         mFeatureFactory = FakeFeatureFactory.setupForTest();
 
         mUnrestrictAppAction = new UnrestrictAppAction(RuntimeEnvironment.application,
@@ -72,7 +76,7 @@
         mUnrestrictAppAction.handlePositiveAction(METRICS_KEY);
 
         verify(mBatteryUtils)
-                .setForceAppStandby(anyInt(), eq(PACKAGE_NAME_1), eq(AppOpsManager.MODE_ALLOWED));
+                .setForceAppStandby(UID_1, PACKAGE_NAME_1, AppOpsManager.MODE_ALLOWED);
         verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
                 MetricsProto.MetricsEvent.ACTION_TIP_UNRESTRICT_APP, PACKAGE_NAME_1, Pair.create(
                         MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY));