Messaging: We don't need to check for verbose logging everywhere
We can just do this in the actual method Change-Id: I80e89b0ab97926749851628b1bd34e8cd9dc82f2
This commit is contained in:
@@ -577,8 +577,6 @@ public class ImageUtils {
|
||||
* @return whether the image can be down subsampled
|
||||
*/
|
||||
private boolean canBeCompressed() {
|
||||
final boolean logv = LogUtil.isLoggable(LogUtil.BUGLE_IMAGE_TAG, LogUtil.VERBOSE);
|
||||
|
||||
int imageHeight = mHeight;
|
||||
int imageWidth = mWidth;
|
||||
|
||||
@@ -611,13 +609,11 @@ public class ImageUtils {
|
||||
Assert.fail("Image cannot be resized"); // http://b/18926934
|
||||
return false;
|
||||
}
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"computeInitialSampleSize: Increasing sampleSize to " + sampleSize
|
||||
+ " as h=" + imageHeight + " vs " + heightLimitWithSlop
|
||||
+ " w=" + imageWidth + " vs " + widthLimitWithSlop
|
||||
+ " p=" + imageHeight * imageWidth + " vs " + pixelLimit);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"computeInitialSampleSize: Increasing sampleSize to " + sampleSize
|
||||
+ " as h=" + imageHeight + " vs " + heightLimitWithSlop
|
||||
+ " w=" + imageWidth + " vs " + widthLimitWithSlop
|
||||
+ " p=" + imageHeight * imageWidth + " vs " + pixelLimit);
|
||||
imageHeight = mHeight / sampleSize;
|
||||
imageWidth = mWidth / sampleSize;
|
||||
fits = (imageHeight < heightLimitWithSlop &&
|
||||
@@ -625,13 +621,11 @@ public class ImageUtils {
|
||||
imageHeight * imageWidth < pixelLimit);
|
||||
}
|
||||
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"computeInitialSampleSize: Initial sampleSize " + sampleSize
|
||||
+ " for h=" + imageHeight + " vs " + heightLimitWithSlop
|
||||
+ " w=" + imageWidth + " vs " + widthLimitWithSlop
|
||||
+ " p=" + imageHeight * imageWidth + " vs " + pixelLimit);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"computeInitialSampleSize: Initial sampleSize " + sampleSize
|
||||
+ " for h=" + imageHeight + " vs " + heightLimitWithSlop
|
||||
+ " w=" + imageWidth + " vs " + widthLimitWithSlop
|
||||
+ " p=" + imageHeight * imageWidth + " vs " + pixelLimit);
|
||||
|
||||
mSampleSize = sampleSize;
|
||||
return true;
|
||||
@@ -646,12 +640,9 @@ public class ImageUtils {
|
||||
byte[] encoded = null;
|
||||
try {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
final boolean logv = LogUtil.isLoggable(LogUtil.BUGLE_IMAGE_TAG, LogUtil.VERBOSE);
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: attempt=" + attempt
|
||||
+ " limit (w=" + mWidthLimit + " h=" + mHeightLimit + ") quality="
|
||||
+ mQuality + " scale=" + mScaleFactor + " sampleSize=" + mSampleSize);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: attempt=" + attempt
|
||||
+ " limit (w=" + mWidthLimit + " h=" + mHeightLimit + ") quality="
|
||||
+ mQuality + " scale=" + mScaleFactor + " sampleSize=" + mSampleSize);
|
||||
if (mScaled == null) {
|
||||
if (mDecoded == null) {
|
||||
mOptions.inSampleSize = mSampleSize;
|
||||
@@ -661,17 +652,13 @@ public class ImageUtils {
|
||||
// Ignore
|
||||
}
|
||||
if (mDecoded == null) {
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: got empty decoded bitmap");
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: got empty decoded bitmap");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: decoded w,h="
|
||||
+ mDecoded.getWidth() + "," + mDecoded.getHeight());
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: decoded w,h="
|
||||
+ mDecoded.getWidth() + "," + mDecoded.getHeight());
|
||||
// Make sure to scale the decoded image if dimension is not within limit
|
||||
final int decodedWidth = mDecoded.getWidth();
|
||||
final int decodedHeight = mDecoded.getHeight();
|
||||
@@ -693,23 +680,19 @@ public class ImageUtils {
|
||||
mScaled = Bitmap.createBitmap(mDecoded, 0, 0, decodedWidth, decodedHeight,
|
||||
mMatrix, false /* filter */);
|
||||
if (mScaled == null) {
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: got empty scaled bitmap");
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: got empty scaled bitmap");
|
||||
return null;
|
||||
}
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: scaled w,h="
|
||||
+ mScaled.getWidth() + "," + mScaled.getHeight());
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: scaled w,h="
|
||||
+ mScaled.getWidth() + "," + mScaled.getHeight());
|
||||
} else {
|
||||
mScaled = mDecoded;
|
||||
}
|
||||
}
|
||||
// Now encode it at current quality
|
||||
encoded = ImageUtils.bitmapToBytes(mScaled, mQuality);
|
||||
if (encoded != null && logv) {
|
||||
if (encoded != null) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Encoded down to " + encoded.length + "@"
|
||||
+ mScaled.getWidth() + "/" + mScaled.getHeight() + "~"
|
||||
@@ -729,7 +712,6 @@ public class ImageUtils {
|
||||
* @param currentSize encoded image size (will be 0 if OOM)
|
||||
*/
|
||||
private void updateRecodeParameters(final int currentSize) {
|
||||
final boolean logv = LogUtil.isLoggable(LogUtil.BUGLE_IMAGE_TAG, LogUtil.VERBOSE);
|
||||
// Only return data within the limit
|
||||
if (currentSize > 0 &&
|
||||
mQuality > MINIMUM_IMAGE_COMPRESSION_QUALITY) {
|
||||
@@ -738,10 +720,8 @@ public class ImageUtils {
|
||||
mQuality = Math.max(MINIMUM_IMAGE_COMPRESSION_QUALITY,
|
||||
Math.min((int) (mQuality * Math.sqrt((1.0 * mByteLimit) / currentSize)),
|
||||
(int) (mQuality * QUALITY_SCALE_DOWN_RATIO)));
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying at quality " + mQuality);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying at quality " + mQuality);
|
||||
} else if (currentSize > 0 &&
|
||||
mScaleFactor < 2.0 * MIN_SCALE_DOWN_RATIO * MIN_SCALE_DOWN_RATIO) {
|
||||
// JPEG compression failed to hit target size - need smaller image
|
||||
@@ -751,10 +731,8 @@ public class ImageUtils {
|
||||
// 2.0 / MIN_SCALE_DOWN_RATIO (arbitrary limit)
|
||||
mQuality = IMAGE_COMPRESSION_QUALITY;
|
||||
mScaleFactor = mScaleFactor / MIN_SCALE_DOWN_RATIO;
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying at scale " + mScaleFactor);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying at scale " + mScaleFactor);
|
||||
// Release scaled bitmap to trigger rescaling
|
||||
if (mScaled != null && mScaled != mDecoded) {
|
||||
mScaled.recycle();
|
||||
@@ -764,19 +742,15 @@ public class ImageUtils {
|
||||
// Then before we subsample try cleaning up our cached memory
|
||||
Factory.get().reclaimMemory();
|
||||
mHasReclaimedMemory = true;
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying after reclaiming memory ");
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying after reclaiming memory ");
|
||||
} else {
|
||||
// Last resort - subsample image by another factor of 2 and try again
|
||||
mSampleSize = mSampleSize * 2;
|
||||
mQuality = IMAGE_COMPRESSION_QUALITY;
|
||||
mScaleFactor = 1.0f;
|
||||
if (logv) {
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,
|
||||
"getResizedImageData: Retrying at sampleSize " + mSampleSize);
|
||||
}
|
||||
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, "getResizedImageData: Retrying at sampleSize "
|
||||
+ mSampleSize);
|
||||
// Release all bitmaps to trigger subsampling
|
||||
if (mScaled != null && mScaled != mDecoded) {
|
||||
mScaled.recycle();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
* Copyright (C) 2024-2025 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.android.messaging.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Log utility class.
|
||||
*/
|
||||
@@ -43,7 +45,9 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
public static void v(final String tag, final String msg) {
|
||||
println(android.util.Log.VERBOSE, tag, msg);
|
||||
if (isLoggable(tag, VERBOSE)) {
|
||||
println(VERBOSE, tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,8 +58,7 @@ public class LogUtil {
|
||||
* @param tr An exception to log
|
||||
*/
|
||||
public static void v(final String tag, final String msg, final Throwable tr) {
|
||||
println(android.util.Log.VERBOSE, tag, msg + '\n'
|
||||
+ android.util.Log.getStackTraceString(tr));
|
||||
println(VERBOSE, tag, msg + '\n' + Log.getStackTraceString(tr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +68,7 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
public static void d(final String tag, final String msg) {
|
||||
println(android.util.Log.DEBUG, tag, msg);
|
||||
println(DEBUG, tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,8 +79,7 @@ public class LogUtil {
|
||||
* @param tr An exception to log
|
||||
*/
|
||||
public static void d(final String tag, final String msg, final Throwable tr) {
|
||||
println(android.util.Log.DEBUG, tag, msg + '\n'
|
||||
+ android.util.Log.getStackTraceString(tr));
|
||||
println(DEBUG, tag, msg + '\n' + Log.getStackTraceString(tr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +89,7 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
public static void i(final String tag, final String msg) {
|
||||
println(android.util.Log.INFO, tag, msg);
|
||||
println(INFO, tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +100,7 @@ public class LogUtil {
|
||||
* @param tr An exception to log
|
||||
*/
|
||||
public static void i(final String tag, final String msg, final Throwable tr) {
|
||||
println(android.util.Log.INFO, tag, msg + '\n'
|
||||
+ android.util.Log.getStackTraceString(tr));
|
||||
println(INFO, tag, msg + '\n' + Log.getStackTraceString(tr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +110,7 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
public static void w(final String tag, final String msg) {
|
||||
println(android.util.Log.WARN, tag, msg);
|
||||
println(WARN, tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,8 +121,8 @@ public class LogUtil {
|
||||
* @param tr An exception to log
|
||||
*/
|
||||
public static void w(final String tag, final String msg, final Throwable tr) {
|
||||
println(android.util.Log.WARN, tag, msg);
|
||||
println(android.util.Log.WARN, tag, android.util.Log.getStackTraceString(tr));
|
||||
println(WARN, tag, msg);
|
||||
println(WARN, tag, android.util.Log.getStackTraceString(tr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +132,7 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
public static void e(final String tag, final String msg) {
|
||||
println(android.util.Log.ERROR, tag, msg);
|
||||
println(ERROR, tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +143,8 @@ public class LogUtil {
|
||||
* @param tr An exception to log
|
||||
*/
|
||||
public static void e(final String tag, final String msg, final Throwable tr) {
|
||||
println(android.util.Log.ERROR, tag, msg);
|
||||
println(android.util.Log.ERROR, tag, android.util.Log.getStackTraceString(tr));
|
||||
println(ERROR, tag, msg);
|
||||
println(ERROR, tag, Log.getStackTraceString(tr));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +159,7 @@ public class LogUtil {
|
||||
public static void wtf(final String tag, final String msg) {
|
||||
// Make sure this goes into our log buffer
|
||||
println(android.util.Log.ASSERT, tag, "wtf\n" + msg);
|
||||
android.util.Log.wtf(tag, msg, new Exception());
|
||||
wtf(tag, msg, new Exception());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,8 +175,8 @@ public class LogUtil {
|
||||
public static void wtf(final String tag, final String msg, final Throwable tr) {
|
||||
// Make sure this goes into our log buffer
|
||||
println(android.util.Log.ASSERT, tag, "wtf\n" + msg + '\n' +
|
||||
android.util.Log.getStackTraceString(tr));
|
||||
android.util.Log.wtf(tag, msg, tr);
|
||||
Log.getStackTraceString(tr));
|
||||
Log.wtf(tag, msg, tr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +187,7 @@ public class LogUtil {
|
||||
* @param msg The message you would like logged.
|
||||
*/
|
||||
private static void println(final int level, final String tag, final String msg) {
|
||||
android.util.Log.println(level, tag, msg);
|
||||
Log.println(level, tag, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +195,7 @@ public class LogUtil {
|
||||
* See {@link android.util.Log#isLoggable(String, int)} for more discussion.
|
||||
*/
|
||||
public static boolean isLoggable(final String tag, final int level) {
|
||||
return android.util.Log.isLoggable(tag, level);
|
||||
return Log.isLoggable(tag, level);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +208,7 @@ public class LogUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (android.util.Log.isLoggable(BUGLE_TAG, android.util.Log.DEBUG)) {
|
||||
if (Log.isLoggable(BUGLE_TAG, DEBUG)) {
|
||||
return text;
|
||||
} else {
|
||||
return "Redacted-" + text.length();
|
||||
|
||||
@@ -47,10 +47,7 @@ public class LoggingTimer {
|
||||
*/
|
||||
public void start() {
|
||||
mStartMillis = SystemClock.elapsedRealtime();
|
||||
|
||||
if (LogUtil.isLoggable(mTag, LogUtil.VERBOSE)) {
|
||||
LogUtil.v(mTag, "Timer start for " + mName);
|
||||
}
|
||||
LogUtil.v(mTag, "Timer start for " + mName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +62,7 @@ public class LoggingTimer {
|
||||
|
||||
if (mWarnLimitMillis != NO_WARN_LIMIT && elapsedMs > mWarnLimitMillis) {
|
||||
LogUtil.w(mTag, logMessage);
|
||||
} else if (LogUtil.isLoggable(mTag, LogUtil.VERBOSE)) {
|
||||
} else {
|
||||
LogUtil.v(mTag, logMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
* Copyright (C) 2024 The LineageOS Project
|
||||
* Copyright (C) 2024-2025 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,9 +54,7 @@ public final class Trace {
|
||||
* most 127 Unicode code units long.
|
||||
*/
|
||||
public static void beginSection(String sectionName) {
|
||||
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
|
||||
LogUtil.v(TAG, "beginSection() " + sectionName);
|
||||
}
|
||||
LogUtil.v(TAG, "beginSection() " + sectionName);
|
||||
sTrace.beginSection(sectionName);
|
||||
}
|
||||
|
||||
@@ -69,9 +67,7 @@ public final class Trace {
|
||||
*/
|
||||
public static void endSection() {
|
||||
sTrace.endSection();
|
||||
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
|
||||
LogUtil.v(TAG, "endSection()");
|
||||
}
|
||||
LogUtil.v(TAG, "endSection()");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user