Only log the names of the app packages which are installed from Google Play Store in battery usage app optimization page
This is to meet the Guidelines for Logging Package Names: go/package-name-logging-guidance Bug: 267430574 Fix: 267430574 Test: presubmit Change-Id: Icf10000f5dcf87e45175d4005af8365191ad444d
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.InstallSourceInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
@@ -34,6 +35,7 @@ import android.os.SystemClock;
|
||||
import android.os.UidBatteryConsumer;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
@@ -83,6 +85,8 @@ public class BatteryUtils {
|
||||
|
||||
public static final String BYPASS_DOCK_DEFENDER_ACTION = "battery.dock.defender.bypass";
|
||||
|
||||
private static final String GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending";
|
||||
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({StatusType.SCREEN_USAGE,
|
||||
StatusType.FOREGROUND,
|
||||
@@ -597,6 +601,21 @@ public class BatteryUtils {
|
||||
return -1L;
|
||||
}
|
||||
|
||||
/** Whether the package is installed from Google Play Store or not */
|
||||
public static boolean isAppInstalledFromGooglePlayStore(Context context, String packageName) {
|
||||
if (TextUtils.isEmpty(packageName)) {
|
||||
return false;
|
||||
}
|
||||
InstallSourceInfo installSourceInfo;
|
||||
try {
|
||||
installSourceInfo = context.getPackageManager().getInstallSourceInfo(packageName);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
return false;
|
||||
}
|
||||
return installSourceInfo != null
|
||||
&& GOOGLE_PLAY_STORE_PACKAGE.equals(installSourceInfo.getInitiatingPackageName());
|
||||
}
|
||||
|
||||
/** Gets the latest sticky battery intent from the Android system. */
|
||||
public static Intent getBatteryIntent(Context context) {
|
||||
return context.registerReceiver(
|
||||
|
Reference in New Issue
Block a user