Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Add installer package
Browse files Browse the repository at this point in the history
Reviewed By: yukonfb

Differential Revision: D33284842

fbshipit-source-id: 5c75b47a63a89bb5431a53485b1d63b63639f7a6
  • Loading branch information
Delyan Kratunov authored and facebook-github-bot committed Jan 5, 2022
1 parent bc342ac commit dc799bc
Showing 1 changed file with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class PackageInfoProvider extends MetadataTraceProvider {

@Nullable private String mVersionName;
@Nullable private String mInstaller;
private int mVersionCode;
private final Context mContext;

Expand All @@ -40,13 +41,19 @@ private void resolvePackageInfo() {
PackageInfo pi;
try {
pi = pm.getPackageInfo(mContext.getPackageName(), 0);
mVersionName = pi.versionName;
mVersionCode = pi.versionCode;
} catch (PackageManager.NameNotFoundException e) {
return;
} catch (RuntimeException e) {
return;
}
mVersionName = pi.versionName;
mVersionCode = pi.versionCode;

try {
mInstaller = pm.getInstallerPackageName(mContext.getPackageName());
} catch (RuntimeException e) {
mInstaller = "<exception>";
}
}

@Override
Expand All @@ -67,15 +74,13 @@ protected void logOnTraceEnd(TraceContext context, ExtraDataFileProvider dataFil
Identifiers.APP_VERSION_NAME,
ProfiloConstants.NO_MATCH,
(long) 0);
if ("App version" != null) {
returnedMatchID =
BufferLogger.writeBytesEntry(
context.mainBuffer,
ProfiloConstants.NONE,
EntryType.STRING_KEY,
returnedMatchID,
"App version");
}
returnedMatchID =
BufferLogger.writeBytesEntry(
context.mainBuffer,
ProfiloConstants.NONE,
EntryType.STRING_KEY,
returnedMatchID,
"App version");
BufferLogger.writeBytesEntry(
context.mainBuffer,
ProfiloConstants.NONE,
Expand All @@ -92,5 +97,29 @@ protected void logOnTraceEnd(TraceContext context, ExtraDataFileProvider dataFil
Identifiers.APP_VERSION_CODE,
ProfiloConstants.NONE,
(long) mVersionCode);

returnedMatchID =
BufferLogger.writeStandardEntry(
context.mainBuffer,
Logger.FILL_TIMESTAMP | Logger.FILL_TID,
EntryType.TRACE_ANNOTATION,
ProfiloConstants.NONE,
ProfiloConstants.NONE,
ProfiloConstants.NONE,
ProfiloConstants.NONE,
ProfiloConstants.NONE);
returnedMatchID =
BufferLogger.writeBytesEntry(
context.mainBuffer,
ProfiloConstants.NONE,
EntryType.STRING_KEY,
returnedMatchID,
"Installer");
BufferLogger.writeBytesEntry(
context.mainBuffer,
ProfiloConstants.NONE,
EntryType.STRING_VALUE,
returnedMatchID,
mInstaller != null ? mInstaller : "null");
}
}

0 comments on commit dc799bc

Please sign in to comment.