Skip load app name from PackageManager while init the BatteryEntry.
- getApplicationLabel is time-consuming. [Before] https://pprof.corp.google.com/?id=bade2601da25f6169b0685a3e2a3e5cc https://screenshot.googleplex.com/86R5DhMgcyQakys [After] https://pprof.corp.google.com/?id=2ccb1e88222e96db1fbcc072470a254c https://screenshot.googleplex.com/7QviDFSpgzoQcg6 Bug: 349120408 Fix: 349120408 Test: atest + pprof Flag: EXEMPT bug fix Change-Id: I1eed60cea9c5bd3f77f38993f7d04906aa811da5
This commit is contained in:
@@ -22,7 +22,6 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.IPackageManager;
|
import android.content.pm.IPackageManager;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.BatteryConsumer;
|
import android.os.BatteryConsumer;
|
||||||
@@ -176,18 +175,7 @@ public class BatteryEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mDefaultPackageName != null) {
|
if (mDefaultPackageName != null) {
|
||||||
PackageManager pm = context.getPackageManager();
|
mName = mDefaultPackageName;
|
||||||
try {
|
|
||||||
ApplicationInfo appInfo =
|
|
||||||
pm.getApplicationInfo(mDefaultPackageName, 0 /* no flags */);
|
|
||||||
mName = pm.getApplicationLabel(appInfo).toString();
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
Log.d(
|
|
||||||
TAG,
|
|
||||||
"PackageManager failed to retrieve ApplicationInfo for: "
|
|
||||||
+ mDefaultPackageName);
|
|
||||||
mName = mDefaultPackageName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mTimeInForegroundMs =
|
mTimeInForegroundMs =
|
||||||
uidBatteryConsumer.getTimeInProcessStateMs(
|
uidBatteryConsumer.getTimeInProcessStateMs(
|
||||||
|
@@ -132,7 +132,7 @@ public class BatteryEntryTest {
|
|||||||
createBatteryEntryForApp(null, APP_DEFAULT_PACKAGE_NAME, HIGH_DRAIN_PACKAGE);
|
createBatteryEntryForApp(null, APP_DEFAULT_PACKAGE_NAME, HIGH_DRAIN_PACKAGE);
|
||||||
|
|
||||||
assertThat(entry.getDefaultPackageName()).isEqualTo(APP_DEFAULT_PACKAGE_NAME);
|
assertThat(entry.getDefaultPackageName()).isEqualTo(APP_DEFAULT_PACKAGE_NAME);
|
||||||
assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + APP_DEFAULT_PACKAGE_NAME);
|
assertThat(entry.getLabel()).isEqualTo(APP_DEFAULT_PACKAGE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,7 +152,7 @@ public class BatteryEntryTest {
|
|||||||
|
|
||||||
BatteryEntry entry = createBatteryEntryForApp(null, null, HIGH_DRAIN_PACKAGE);
|
BatteryEntry entry = createBatteryEntryForApp(null, null, HIGH_DRAIN_PACKAGE);
|
||||||
|
|
||||||
assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + HIGH_DRAIN_PACKAGE);
|
assertThat(entry.getLabel()).isEqualTo(HIGH_DRAIN_PACKAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -163,7 +163,7 @@ public class BatteryEntryTest {
|
|||||||
null,
|
null,
|
||||||
HIGH_DRAIN_PACKAGE);
|
HIGH_DRAIN_PACKAGE);
|
||||||
|
|
||||||
assertThat(entry.getLabel()).isEqualTo(LABEL_PREFIX + HIGH_DRAIN_PACKAGE);
|
assertThat(entry.getLabel()).isEqualTo(HIGH_DRAIN_PACKAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user