Properly set isInstantApp for power usage page

Previously the app header was not properly configured to be aware
it was rendering an instant app. This change properly sets the value
and adds tests to ensure it is correclty set in the future.

Test: make RunSettingsRoboTests -j30
Bug: 37919863
Change-Id: I0cbe2cb03bcd44208408f68188387e53ae98d8fb
diff --git a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
index 0cbfd54..7a2e4c0 100644
--- a/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
+++ b/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetail.java
@@ -28,7 +28,6 @@
 import android.support.annotation.VisibleForTesting;
 import android.support.v14.preference.PreferenceFragment;
 import android.support.v7.preference.Preference;
-import android.text.TextUtils;
 import android.view.View;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -45,6 +44,7 @@
 import com.android.settings.enterprise.DevicePolicyManagerWrapper;
 import com.android.settings.enterprise.DevicePolicyManagerWrapperImpl;
 import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState;
 
 import java.util.ArrayList;
@@ -202,7 +202,11 @@
             mState.ensureIcon(mAppEntry);
             controller.setLabel(mAppEntry);
             controller.setIcon(mAppEntry);
-            controller.setSummary(getString(Utils.getInstallationStatus(mAppEntry.info)));
+            boolean isInstantApp = AppUtils.isInstant(mAppEntry.info);
+            CharSequence summary = isInstantApp
+                    ? null : getString(Utils.getInstallationStatus(mAppEntry.info));
+            controller.setIsInstantApp(AppUtils.isInstant(mAppEntry.info));
+            controller.setSummary(summary);
         }
 
         controller.done(context, true /* rebindActions */);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
index 4305dc7..7ec0816 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/AdvancedPowerUsageDetailTest.java
@@ -17,6 +17,7 @@
 package com.android.settings.fuelgauge;
 
 import static com.google.common.truth.Truth.assertThat;
+
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
 import static org.mockito.Matchers.anyLong;
@@ -46,7 +47,9 @@
 import com.android.settings.applications.AppHeaderController;
 import com.android.settings.applications.LayoutPreference;
 import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settingslib.applications.AppUtils;
 import com.android.settingslib.applications.ApplicationsState;
+import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -58,7 +61,6 @@
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.robolectric.RuntimeEnvironment;
-
 import org.robolectric.annotation.Config;
 import org.robolectric.util.ReflectionHelpers;
 
@@ -175,11 +177,37 @@
 
     @Test
     public void testInitHeader_HasAppEntry_BuildByAppEntry() {
+        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+                new InstantAppDataProvider() {
+                    @Override
+                    public boolean isInstantApp(ApplicationInfo info) {
+                        return false;
+                    }
+                });
         mFragment.mAppEntry = mAppEntry;
         mFragment.initHeader();
 
         verify(mAppHeaderController).setIcon(mAppEntry);
         verify(mAppHeaderController).setLabel(mAppEntry);
+        verify(mAppHeaderController).setIsInstantApp(false);
+    }
+
+    @Test
+    public void testInitHeader_HasAppEntry_InstantApp() {
+        ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
+                new InstantAppDataProvider() {
+                    @Override
+                    public boolean isInstantApp(ApplicationInfo info) {
+                        return true;
+                    }
+                });
+        mFragment.mAppEntry = mAppEntry;
+        mFragment.initHeader();
+
+        verify(mAppHeaderController).setIcon(mAppEntry);
+        verify(mAppHeaderController).setLabel(mAppEntry);
+        verify(mAppHeaderController).setIsInstantApp(true);
+        verify(mAppHeaderController).setSummary((CharSequence) null);
     }
 
     @Test