Messaging: Explicitly specify Locale where needed

Change-Id: I636e9cceed0e73bcf957ebbda5e239982e681fd7
This commit is contained in:
Michael W
2025-04-10 13:44:52 +02:00
parent 37e5757779
commit 9fd4fa6bb9
7 changed files with 39 additions and 25 deletions

View File

@@ -28,6 +28,7 @@ import com.android.messaging.util.ThreadUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
@@ -273,7 +274,8 @@ public class ActionMonitor {
newMonitorState = monitor.mState;
}
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS",
Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
LogUtil.v(TAG, "Operation-" + action.actionKey + ": @" + df.format(new Date())
+ "UTC State = " + oldMonitorState + " - " + newMonitorState);
@@ -341,7 +343,8 @@ public class ActionMonitor {
unregisterActionMonitorIfComplete(action.actionKey, monitor);
}
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS",
Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
LogUtil.v(TAG, "Operation-" + action.actionKey + ": @" + df.format(new Date())
+ "UTC State = " + oldMonitorState + " - " + STATE_COMPLETE);
@@ -399,7 +402,8 @@ public class ActionMonitor {
monitor.executed(action, expectedOldState, hasBackgroundActions, result);
}
if (LogUtil.isLoggable(TAG, LogUtil.VERBOSE)) {
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS",
Locale.getDefault());
df.setTimeZone(TimeZone.getTimeZone("UTC"));
LogUtil.v(TAG, "Operation-" + action.actionKey + ": @" + df.format(new Date())
+ "UTC State = " + oldMonitorState + " - EXECUTED");

View File

@@ -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.
@@ -327,7 +327,8 @@ public class MmsUtils {
final String extension = ContentType.getExtensionFromMimeType(contentType);
if (ContentType.isImageType(contentType)) {
if (extension != null) {
srcName = String.format("image%06d.%s", index, extension);
srcName = String.format(Locale.getDefault(), "image%06d.%s", index,
extension);
} else {
// There's a good chance that if we selected the image from our media picker
// the content type is image/*. Fix the content type here for gifs so that
@@ -335,35 +336,37 @@ public class MmsUtils {
// checks will only have to do a string comparison which is much cheaper.
final boolean isGif = ImageUtils.isGif(contentType, part.getContentUri());
contentType = isGif ? ContentType.IMAGE_GIF : contentType;
srcName = String.format(isGif ? "image%06d.gif" : "image%06d.jpg", index);
srcName = String.format(Locale.getDefault(),
isGif ? "image%06d.gif" : "image%06d.jpg", index);
}
smilBody.append(String.format(sSmilImagePart, srcName));
totalLength += addPicturePart(context, pb, index, part,
widthLimit, heightLimit, bytesPerImage, srcName, contentType);
hasVisualAttachment = true;
} else if (ContentType.isVideoType(contentType)) {
srcName = String.format("video%06d.%s", index,
srcName = String.format(Locale.getDefault(), "video%06d.%s", index,
extension != null ? extension : "mp4");
final int length = addVideoPart(context, pb, part, srcName);
totalLength += length;
smilBody.append(String.format(sSmilVideoPart, srcName,
smilBody.append(String.format(Locale.getDefault(), sSmilVideoPart, srcName,
getMediaDurationMs(context, part, DEFAULT_DURATION)));
hasVisualAttachment = true;
} else if (ContentType.isVCardType(contentType)) {
srcName = String.format("contact%06d.vcf", index);
srcName = String.format(Locale.getDefault(), "contact%06d.vcf", index);
totalLength += addVCardPart(context, pb, part, srcName);
smilBody.append(String.format(sSmilPart, srcName));
hasNonVisualAttachment = true;
} else if (ContentType.isAudioType(contentType)) {
srcName = String.format("recording%06d.%s",
srcName = String.format(Locale.getDefault(), "recording%06d.%s",
index, extension != null ? extension : "amr");
totalLength += addOtherPart(context, pb, part, srcName);
final int duration = getMediaDurationMs(context, part, -1);
Assert.isTrue(duration != -1);
smilBody.append(String.format(sSmilAudioPart, srcName, duration));
smilBody.append(String.format(Locale.getDefault(), sSmilAudioPart, srcName,
duration));
hasNonVisualAttachment = true;
} else {
srcName = String.format("other%06d.dat", index);
srcName = String.format(Locale.getDefault(), "other%06d.dat", index);
totalLength += addOtherPart(context, pb, part, srcName);
smilBody.append(String.format(sSmilPart, srcName));
}
@@ -375,7 +378,7 @@ public class MmsUtils {
}
if (hasText) {
final String srcName = String.format("text.%06d.txt", index);
final String srcName = String.format(Locale.getDefault(), "text.%06d.txt", index);
final String text = message.getMessageText();
totalLength += addTextPart(context, pb, text, srcName);

View File

@@ -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.
@@ -170,9 +170,9 @@ public class Dates {
final String format24, final String format12) {
SimpleDateFormat formatter;
if ((flags & FORCE_24_HOUR) == FORCE_24_HOUR) {
formatter = new SimpleDateFormat(format24);
formatter = new SimpleDateFormat(format24, Locale.getDefault());
} else {
formatter = new SimpleDateFormat(format12);
formatter = new SimpleDateFormat(format12, Locale.getDefault());
}
return formatter.format(new Date(time));
}

View File

@@ -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.
@@ -23,6 +23,7 @@ import android.text.format.Formatter;
import com.google.common.base.Stopwatch;
import java.io.File;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
/**
@@ -51,7 +52,8 @@ public class GifTranscoder {
final float compression = (inputSize > 0) ? ((float) outputSize / inputSize) : 0;
if (success) {
LogUtil.i(TAG, String.format("Resized GIF (%s) in %d ms, %s => %s (%.0f%%)",
LogUtil.i(TAG, String.format(Locale.getDefault(),
"Resized GIF (%s) in %d ms, %s => %s (%.0f%%)",
LogUtil.sanitizePII(filePath),
elapsedMs,
Formatter.formatShortFileSize(context, inputSize),

View File

@@ -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,6 +54,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Locale;
public class ImageUtils {
private static final String TAG = LogUtil.BUGLE_TAG;
@@ -603,7 +604,7 @@ public class ImageUtils {
sampleSize = sampleSize * 2;
// Note that recodeImage may try using mSampleSize * 2. Hence we use the factor of 4
if (sampleSize >= (Integer.MAX_VALUE / 4)) {
LogUtil.w(LogUtil.BUGLE_IMAGE_TAG, String.format(
LogUtil.w(LogUtil.BUGLE_IMAGE_TAG, String.format(Locale.getDefault(),
"Cannot resize image: widthLimit=%d heightLimit=%d byteLimit=%d " +
"imageWidth=%d imageHeight=%d", mWidthLimit, mHeightLimit, mByteLimit,
mWidth, mHeight));

View File

@@ -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.
@@ -19,6 +19,8 @@ package com.android.messaging.util;
import android.os.SystemClock;
import java.util.Locale;
/**
* A utility timer that logs the execution time of operations
*/
@@ -58,7 +60,8 @@ public class LoggingTimer {
public void stopAndLog() {
final long elapsedMs = SystemClock.elapsedRealtime() - mStartMillis;
final String logMessage = String.format("Used %dms for %s", elapsedMs, mName);
final String logMessage = String.format(Locale.getDefault(), "Used %dms for %s",
elapsedMs, mName);
if (mWarnLimitMillis != NO_WARN_LIMIT && elapsedMs > mWarnLimitMillis) {
LogUtil.w(mTag, logMessage);

View File

@@ -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.
@@ -628,12 +628,13 @@ public class PhoneUtils {
if (mccmnc == null || mccmnc.length != 2) {
return "000000";
}
return String.format("%03d%03d", mccmnc[0], mccmnc[1]);
return String.format(Locale.getDefault(), "%03d%03d", mccmnc[0], mccmnc[1]);
}
public static String canonicalizeMccMnc(final String mcc, final String mnc) {
try {
return String.format("%03d%03d", Integer.parseInt(mcc), Integer.parseInt(mnc));
return String.format(Locale.getDefault(), "%03d%03d", Integer.parseInt(mcc),
Integer.parseInt(mnc));
} catch (final NumberFormatException e) {
// Return invalid as is
LogUtil.w(TAG, "canonicalizeMccMnc: invalid mccmnc:" + mcc + " ," + mnc);