Skip to content

Fad logs file provider #2999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ AppDistributionReleaseInternal getNewReleaseFromClient(
return retrievedNewRelease;
} else {
// Return null if retrieved new release is older or currently installed
LogWrapper.getInstance().v(TAG + "New Release is older or is currently installed");
return null;
}
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -207,6 +208,7 @@ private boolean hasSameHashAsInstalledRelease(AppDistributionReleaseInternal new
// TODO: Consider removing this when all returned releases have the efficient ApkHash
String externalCodeHash =
releaseIdentifierStorage.getExternalCodeHash(installedReleaseApkHash);
LogWrapper.getInstance().v(TAG + "Defaulting to external codehash " + externalCodeHash);
return externalCodeHash != null && externalCodeHash.equals(newRelease.getCodeHash());
}
// If the hash of the zipped APK for the retrieved newRelease is equal to the stored hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

package com.google.firebase.appdistribution;

import static android.content.ContentValues.TAG;
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.AUTHENTICATION_FAILURE;
import static com.google.firebase.appdistribution.FirebaseAppDistributionException.Status.NETWORK_FAILURE;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.gms.common.util.AndroidUtilsLight;
import com.google.android.gms.common.util.Hex;
Expand Down Expand Up @@ -114,7 +112,7 @@ class FirebaseAppDistributionTesterApiClient {
} finally {
connection.disconnect();
}

LogWrapper.getInstance().v("Zip hash for the new release " + newRelease.getApkHash());
return newRelease;
}

Expand Down Expand Up @@ -219,13 +217,12 @@ private String getFingerprintHashForPackage(Context context) {
hash = AndroidUtilsLight.getPackageCertificateHashBytes(context, context.getPackageName());

if (hash == null) {
Log.e(TAG, "Could not get fingerprint hash for package: " + context.getPackageName());
return null;
} else {
return Hex.bytesToStringUppercase(hash, /* zeroTerminated= */ false);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "No such package: " + context.getPackageName(), e);
LogWrapper.getInstance().e(TAG + "No such package: " + context.getPackageName(), e);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void onCreate(@NonNull Bundle savedInstanceState) {
Uri apkUri =
FileProvider.getUriForFile(
getApplicationContext(),
getApplicationContext().getPackageName() + ".appdistro.fileprovider",
getApplicationContext().getPackageName() + ".FirebaseAppDistributionFileProvider",
apkFile);
intent.setDataAndType(apkUri, APK_MIME_TYPE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
package com.google.firebase.appdistribution;

import android.util.Log;
import androidx.annotation.NonNull;

/** Wrapper that handles Android logcat logging. */
class LogWrapper {
public class LogWrapper {

private static final String LOG_TAG = "FirebaseAppDistribution";
private static LogWrapper instance;

@NonNull
public static synchronized LogWrapper getInstance() {
if (instance == null) {
instance = new LogWrapper();
Expand All @@ -30,27 +32,27 @@ public static synchronized LogWrapper getInstance() {
return instance;
}

void d(String msg) {
public void d(@NonNull String msg) {
Log.d(LOG_TAG, msg);
}

void v(String msg) {
public void v(@NonNull String msg) {
Log.v(LOG_TAG, msg);
}

void i(String msg) {
public void i(@NonNull String msg) {
Log.i(LOG_TAG, msg);
}

void w(String msg) {
public void w(@NonNull String msg) {
Log.w(LOG_TAG, msg);
}

void e(String msg) {
public void e(@NonNull String msg) {
Log.e(LOG_TAG, msg);
}

void e(String msg, Throwable tr) {
public void e(@NonNull String msg, @NonNull Throwable tr) {
Log.e(LOG_TAG, msg, tr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.firebase.appdistribution.LogWrapper;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
Expand All @@ -46,15 +46,15 @@ public static String extractInternalAppSharingArtifactId(@NonNull Context appCon
}
return packageInfo.applicationInfo.metaData.getString("com.android.vending.internal.apk.id");
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Could not extract internal app sharing artifact ID");
LogWrapper.getInstance().w(TAG + "Could not extract internal app sharing artifact ID");
return null;
}
}

@Nullable
public static String calculateApkHash(@NonNull File file) {
Log.v(TAG, String.format("Calculating release id for %s", file.getPath()));
Log.v(TAG, String.format("File size: %d", file.length()));
LogWrapper.getInstance().v(TAG + "Calculating release id for " + file.getPath());
LogWrapper.getInstance().v(TAG + "File size: " + file.length());

long start = System.currentTimeMillis();
long entries = 0;
Expand Down Expand Up @@ -90,20 +90,23 @@ public static String calculateApkHash(@NonNull File file) {
zipFingerprint = sb.toString();

} catch (IOException | NoSuchAlgorithmException e) {
Log.v(TAG, String.format("id calculation failed for %s", file.getPath()));
LogWrapper.getInstance().v(TAG + "id calculation failed for " + file.getPath());
return null;
} finally {
long elapsed = System.currentTimeMillis() - start;
if (elapsed > 2 * 1000) {
Log.v(
TAG,
String.format(
"Long id calculation time %d ms and %d entries for %s",
elapsed, entries, file.getPath()));
LogWrapper.getInstance()
.v(
TAG
+ String.format(
"Long id calculation time %d ms and %d entries for %s",
elapsed, entries, file.getPath()));
}

Log.v(TAG, String.format("Finished calculating %d entries in %d ms", entries, elapsed));
Log.v(TAG, String.format("%s hashes to %s", file.getPath(), zipFingerprint));
LogWrapper.getInstance()
.v(TAG + String.format("Finished calculating %d entries in %d ms", entries, elapsed));
LogWrapper.getInstance()
.v(TAG + String.format("%s hashes to %s", file.getPath(), zipFingerprint));
}

return zipFingerprint;
Expand Down