From e260b743dca9d9be79167c460c22199c018f7011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Gregorczyk?= Date: Thu, 17 Aug 2023 08:12:10 -0700 Subject: [PATCH] add SoSource.getName() Summary: SoSource.getName() identifies the sosource for the purpose of telemetry. Reviewed By: adicatana Differential Revision: D48040739 fbshipit-source-id: b8eb68a447d4b3c7bc4cba9ee7680dac19965ca8 --- java/com/facebook/soloader/ApkSoSource.java | 5 +++++ java/com/facebook/soloader/ApplicationSoSource.java | 8 +++++++- java/com/facebook/soloader/DirectApkSoSource.java | 7 ++++++- java/com/facebook/soloader/DirectorySoSource.java | 7 ++++++- java/com/facebook/soloader/ExoSoSource.java | 5 +++++ java/com/facebook/soloader/ExtractFromZipSoSource.java | 5 +++++ java/com/facebook/soloader/NoopSoSource.java | 5 +++++ java/com/facebook/soloader/SoSource.java | 5 ++++- java/com/facebook/soloader/UnpackingSoSource.java | 4 ++-- 9 files changed, 45 insertions(+), 6 deletions(-) diff --git a/java/com/facebook/soloader/ApkSoSource.java b/java/com/facebook/soloader/ApkSoSource.java index 9e8fc88..c6bc4af 100644 --- a/java/com/facebook/soloader/ApkSoSource.java +++ b/java/com/facebook/soloader/ApkSoSource.java @@ -55,6 +55,11 @@ public ApkSoSource(Context context, File apkPath, String name, int flags) { mFlags = flags; } + @Override + public String getName() { + return "ApkSoSource"; + } + @Override protected Unpacker makeUnpacker() throws IOException { return new ApkUnpacker(this); diff --git a/java/com/facebook/soloader/ApplicationSoSource.java b/java/com/facebook/soloader/ApplicationSoSource.java index b73e135..84d68a5 100644 --- a/java/com/facebook/soloader/ApplicationSoSource.java +++ b/java/com/facebook/soloader/ApplicationSoSource.java @@ -78,10 +78,16 @@ public void addToLdLibraryPath(Collection paths) { soSource.addToLdLibraryPath(paths); } + @Override + public String getName() { + return "ApplicationSoSource"; + } + @Override public String toString() { return new StringBuilder() - .append("ApplicationSoSource[") + .append(getName()) + .append("[") .append(soSource.toString()) .append("]") .toString(); diff --git a/java/com/facebook/soloader/DirectApkSoSource.java b/java/com/facebook/soloader/DirectApkSoSource.java index c631f22..cca85e5 100644 --- a/java/com/facebook/soloader/DirectApkSoSource.java +++ b/java/com/facebook/soloader/DirectApkSoSource.java @@ -215,10 +215,15 @@ private void buildLibDepsCacheImpl( } } + @Override + public String getName() { + return "DirectApkSoSource"; + } + @Override public String toString() { return new StringBuilder() - .append(getClass().getName()) + .append(getName()) .append("[root = ") .append(mDirectApkLdPaths.toString()) .append(']') diff --git a/java/com/facebook/soloader/DirectorySoSource.java b/java/com/facebook/soloader/DirectorySoSource.java index dd0f605..a44193e 100644 --- a/java/com/facebook/soloader/DirectorySoSource.java +++ b/java/com/facebook/soloader/DirectorySoSource.java @@ -168,6 +168,11 @@ public void addToLdLibraryPath(Collection paths) { } } + @Override + public String getName() { + return "DirectorySoSource"; + } + @Override public String toString() { String path; @@ -177,7 +182,7 @@ public String toString() { path = soDirectory.getName(); } return new StringBuilder() - .append(getClass().getName()) + .append(getName()) .append("[root = ") .append(path) .append(" flags = ") diff --git a/java/com/facebook/soloader/ExoSoSource.java b/java/com/facebook/soloader/ExoSoSource.java index be0ac63..ec9856a 100644 --- a/java/com/facebook/soloader/ExoSoSource.java +++ b/java/com/facebook/soloader/ExoSoSource.java @@ -38,6 +38,11 @@ public ExoSoSource(Context context, String name) { super(context, name); } + @Override + public String getName() { + return "ExoSoSource"; + } + @Override protected MessageDigest getHashingAlgorithm() throws NoSuchAlgorithmException { return MessageDigest.getInstance("SHA-1"); diff --git a/java/com/facebook/soloader/ExtractFromZipSoSource.java b/java/com/facebook/soloader/ExtractFromZipSoSource.java index 0d2dc29..6afeca5 100644 --- a/java/com/facebook/soloader/ExtractFromZipSoSource.java +++ b/java/com/facebook/soloader/ExtractFromZipSoSource.java @@ -54,6 +54,11 @@ public ExtractFromZipSoSource( mZipSearchPattern = zipSearchPattern; } + @Override + public String getName() { + return "ExtractFromZipSoSource"; + } + @Override protected Unpacker makeUnpacker() throws IOException { return new ZipUnpacker(this); diff --git a/java/com/facebook/soloader/NoopSoSource.java b/java/com/facebook/soloader/NoopSoSource.java index 63806c1..888ee95 100644 --- a/java/com/facebook/soloader/NoopSoSource.java +++ b/java/com/facebook/soloader/NoopSoSource.java @@ -30,4 +30,9 @@ public int loadLibrary(String soName, int loadFlags, StrictMode.ThreadPolicy thr public File unpackLibrary(String soName) { throw new UnsupportedOperationException("unpacking not supported in test mode"); } + + @Override + public String getName() { + return "NoopSoSource"; + } } diff --git a/java/com/facebook/soloader/SoSource.java b/java/com/facebook/soloader/SoSource.java index ef30203..280b8fe 100644 --- a/java/com/facebook/soloader/SoSource.java +++ b/java/com/facebook/soloader/SoSource.java @@ -139,6 +139,9 @@ public String[] getSoSourceAbis() { return SysUtil.getSupportedAbis(); } + /** @return the name of this SoSource for logging purposes */ + public abstract String getName(); + /** * Return the class name of the actual instance. Useful for debugging. * @@ -146,6 +149,6 @@ public String[] getSoSourceAbis() { */ @Override public String toString() { - return getClass().getName(); + return getName(); } } diff --git a/java/com/facebook/soloader/UnpackingSoSource.java b/java/com/facebook/soloader/UnpackingSoSource.java index 64c9fff..5ca8d42 100644 --- a/java/com/facebook/soloader/UnpackingSoSource.java +++ b/java/com/facebook/soloader/UnpackingSoSource.java @@ -244,14 +244,14 @@ private void extractDso(InputDso iDso, byte[] ioBuffer) throws IOException { } private void regenerate(InputDsoIterator dsoIterator) throws IOException { - LogUtil.v(TAG, "regenerating DSO store " + getClass().getName()); + LogUtil.v(TAG, "regenerating DSO store " + getName()); byte[] ioBuffer = new byte[32 * 1024]; while (dsoIterator.hasNext()) { try (InputDso iDso = dsoIterator.next()) { extractDso(iDso, ioBuffer); } } - LogUtil.v(TAG, "Finished regenerating DSO store " + getClass().getName()); + LogUtil.v(TAG, "Finished regenerating DSO store " + getName()); } protected MessageDigest getHashingAlgorithm() throws NoSuchAlgorithmException {