Messaging: Further code improvements

* Remove redundant casts
* getParcelable(ArrayList|Exra) without class argument is deprecated
* ViewPager.setOnPageChangeListener -> addOnPageChangeListener
* RecyclerView.setOnScrollListener -> addOnScrollListener
* Remove unused initializations
* Remove unused code

Change-Id: I21beb6c90c675a4f2cfd7e3d5ebbd18b745f5911
This commit is contained in:
Michael W
2025-03-04 18:52:05 +01:00
parent 47f5533a73
commit b2f5e3190e
110 changed files with 289 additions and 561 deletions
@@ -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.
@@ -29,8 +29,6 @@ import com.android.messaging.R;
import javax.annotation.Nullable;
public class AccessibilityUtil {
public static String sContentDescriptionDivider;
public static boolean isTouchExplorationEnabled(final Context context) {
final AccessibilityManager accessibilityManager = (AccessibilityManager)
context.getSystemService(Context.ACCESSIBILITY_SERVICE);
@@ -272,5 +272,5 @@ public final class EmailAddress {
protected boolean valid = false;
protected String user = null;
protected String host = null;
protected boolean allowI18n = false;
protected boolean allowI18n;
}
@@ -107,7 +107,6 @@ public class ImageUtils {
if (oomCount <= MAX_OOM_COUNT) {
Factory.get().reclaimMemory();
} else {
done = true;
LogUtil.w(TAG, "Failed to convert bitmap to bytes. Out of Memory.");
}
throw e;
@@ -186,7 +186,7 @@ public class NotificationPlayer implements OnCompletionListener {
@Override
public void run() {
while (true) {
Command cmd = null;
Command cmd;
synchronized (mCmdQueue) {
if (mDebug) {
@@ -327,31 +327,6 @@ public class NotificationPlayer implements OnCompletionListener {
}
}
/**
* We want to hold a wake lock while we do the prepare and play. The stop probably is
* optional, but it won't hurt to have it too. The problem is that if you start a sound
* while you're holding a wake lock (e.g. an alarm starting a notification), you want the
* sound to play, but if the CPU turns off before mThread gets to work, it won't. The
* simplest way to deal with this is to make it so there is a wake lock held while the
* thread is starting or running. You're going to need the WAKE_LOCK permission if you're
* going to call this.
*
* This must be called before the first time play is called.
*
* @hide
*/
public void setUsesWakeLock() {
if (mWakeLock != null || mThread != null) {
// if either of these has happened, we've already played something.
// and our releases will be out of sync.
throw new RuntimeException("assertion failed mWakeLock=" + mWakeLock
+ " mThread=" + mThread);
}
final PowerManager pm = (PowerManager) Factory.get().getApplicationContext()
.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mTag);
}
private void acquireWakeLock() {
if (mWakeLock != null) {
mWakeLock.acquire();
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 The LineageOS Project
* Copyright (C) 2019-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.
@@ -72,9 +72,4 @@ public final class NotificationsUtil {
NotificationManager manager = context.getSystemService(NotificationManager.class);
return manager.getNotificationChannel(id);
}
public static NotificationChannelGroup getNotificationChannelGroup(Context context, String id) {
NotificationManager manager = context.getSystemService(NotificationManager.class);
return manager.getNotificationChannelGroup(id);
}
}
+1 -16
View File
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 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,20 +55,4 @@ public class TextUtil {
}
return normalizedDigits.toString();
}
/**
* Appends text to the stringBuilder.
* If stringBuilder already has content, separator is prepended to create a separator between
* entries.
* @param stringBuilder The stringBuilder to add to
* @param text The text to append
* @param separator The separator to add if there is already text, typically "," or "\n"
*/
public static void appendWithSeparator(final StringBuilder stringBuilder, final String text,
final String separator) {
if (stringBuilder.length() > 0) {
stringBuilder.append(separator);
}
stringBuilder.append(text);
}
}
@@ -1,70 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.messaging.util;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import androidx.appcompat.graphics.drawable.DrawableWrapperCompat;
/*
* This is directly copied from v7/appcompat/src/androidx.appcompat.internal/widget/TintManager.java
*/
/**
* A {@link DrawableWrapperCompat} which updates it's color filter using a {@link ColorStateList}.
*/
class TintDrawableWrapper extends DrawableWrapperCompat {
private final ColorStateList mTintStateList;
private final PorterDuff.Mode mTintMode;
private int mCurrentColor;
public TintDrawableWrapper(Drawable drawable, ColorStateList tintStateList) {
this(drawable, tintStateList, PorterDuff.Mode.SRC_IN);
}
public TintDrawableWrapper(Drawable drawable, ColorStateList tintStateList,
PorterDuff.Mode tintMode) {
super(drawable);
mTintStateList = tintStateList;
mTintMode = tintMode;
}
@Override
public boolean isStateful() {
return (mTintStateList != null && mTintStateList.isStateful()) || super.isStateful();
}
@Override
public boolean setState(int[] stateSet) {
boolean handled = super.setState(stateSet);
handled = updateTint(stateSet) || handled;
return handled;
}
private boolean updateTint(int[] state) {
if (mTintStateList != null) {
final int color = mTintStateList.getColorForState(state, mCurrentColor);
if (color != mCurrentColor) {
if (color != Color.TRANSPARENT) {
setColorFilter(color, mTintMode);
} else {
clearColorFilter();
}
mCurrentColor = color;
return true;
}
}
return false;
}
}
+1 -28
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.
@@ -18,7 +18,6 @@ package com.android.messaging.util;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.MediaMetadataRetriever;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
@@ -347,32 +346,6 @@ public class UriUtil {
return TextUtil.replaceUnicodeDigits(parts[0]).replace(';', ',');
}
/**
* Return the length of the file to which contentUri refers
*
* @param contentUri URI for the file of which we want the length
* @return Length of the file or AssetFileDescriptor.UNKNOWN_LENGTH
*/
public static long getUriContentLength(final Uri contentUri) {
final Context context = Factory.get().getApplicationContext();
AssetFileDescriptor afd = null;
try {
afd = context.getContentResolver().openAssetFileDescriptor(contentUri, "r");
return afd.getLength();
} catch (final FileNotFoundException e) {
LogUtil.w(LogUtil.BUGLE_TAG, "Failed to query length of " + contentUri);
} finally {
if (afd != null) {
try {
afd.close();
} catch (final IOException e) {
LogUtil.w(LogUtil.BUGLE_TAG, "Failed to close afd for " + contentUri);
}
}
}
return AssetFileDescriptor.UNKNOWN_LENGTH;
}
/** @return string representation of URI or null if URI was null */
public static String stringFromUri(final Uri uri) {
return uri == null ? null : uri.toString();
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 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.
@@ -26,7 +27,6 @@ public final class VersionUtil {
private static final Object sLock = new Object();
private static VersionUtil sInstance;
private final String mSimpleVersionName;
private final int mVersionCode;
public static VersionUtil getInstance(final Context context) {
synchronized (sLock) {
@@ -47,7 +47,6 @@ public final class VersionUtil {
Assert.fail("couldn't get package info " + exception);
versionCode = -1;
}
mVersionCode = versionCode;
final int majorBuildNumber = versionCode / 1000;
// Use US locale to format version number so that other language characters don't
// show up in version string.
@@ -57,10 +56,6 @@ public final class VersionUtil {
majorBuildNumber % 1000);
}
public int getVersionCode() {
return mVersionCode;
}
public String getSimpleName() {
return mSimpleVersionName;
}
@@ -1,119 +0,0 @@
/*
* Copyright (C) 2015 The Android Open Source Project
* Copyright (C) 2024 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.messaging.util;
import android.content.Context;
import android.content.Intent;
import android.os.Debug;
import android.os.PowerManager;
import android.os.Process;
/**
* Helper class used to manage wakelock state
*/
public class WakeLockHelper {
private static final String TAG = LogUtil.BUGLE_DATAMODEL_TAG;
private static final boolean VERBOSE = false;
public static final String EXTRA_CALLING_PID = "pid";
private final Object mLock = new Object();
private final String mWakeLockId;
private final int mMyPid;
private PowerManager.WakeLock mWakeLock;
public WakeLockHelper(final String wakeLockId) {
mWakeLockId = wakeLockId;
mMyPid = Process.myPid();
}
/**
* Acquire the wakelock
*/
public void acquire(final Context context, final Intent intent, final int opcode) {
synchronized (mLock) {
if (mWakeLock == null) {
if (VERBOSE) {
LogUtil.v(TAG, "initializing wakelock");
}
final PowerManager pm = (PowerManager)
context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, mWakeLockId);
}
}
if (VERBOSE) {
LogUtil.v(TAG, "acquiring " + mWakeLockId + " for opcode " + opcode);
}
mWakeLock.acquire();
intent.putExtra(EXTRA_CALLING_PID, mMyPid);
}
/**
* Check if wakelock held by this process
*/
public boolean isHeld(final Intent intent) {
final boolean respectWakeLock = (mMyPid == intent.getIntExtra(EXTRA_CALLING_PID, -1));
return (respectWakeLock && mWakeLock.isHeld());
}
/**
* Ensure that wakelock is held by this process
*/
public boolean ensure(final Intent intent, final int opcode) {
final boolean respectWakeLock = (mMyPid == intent.getIntExtra(EXTRA_CALLING_PID, -1));
if (VERBOSE) {
LogUtil.v(TAG, "WakeLockHelper.ensure Intent " + intent + " "
+ intent.getAction() + " opcode: " + opcode
+ " respectWakeLock " + respectWakeLock);
}
if (respectWakeLock) {
final boolean isHeld = (respectWakeLock && isHeld(intent));
if (!isHeld) {
LogUtil.e(TAG, "WakeLockHelper.ensure called " + intent + " " + intent.getAction()
+ " opcode: " + opcode + " sWakeLock: " + mWakeLock + " isHeld: "
+ ((mWakeLock == null) ? "(null)" : mWakeLock.isHeld()));
if (!Debug.isDebuggerConnected()) {
Assert.fail("WakeLock dropped prior to service starting");
}
}
return true;
}
return false;
}
/**
* Release wakelock (if it is held by this process)
*/
public void release(final Intent intent, final int opcode) {
final boolean respectWakeLock = (mMyPid == intent.getIntExtra(EXTRA_CALLING_PID, -1));
if (respectWakeLock) {
try {
mWakeLock.release();
} catch (final RuntimeException ex) {
LogUtil.e(TAG, "KeepAliveService.onHandleIntent exit crash " + intent + " "
+ intent.getAction() + " opcode: " + opcode + " sWakeLock: " + mWakeLock
+ " isHeld: " + ((mWakeLock == null) ? "(null)" : mWakeLock.isHeld()));
if (!Debug.isDebuggerConnected()) {
Assert.fail("WakeLock no longer held at end of handler");
}
}
}
}
}
@@ -735,7 +735,7 @@ public class ExifInterface {
if (inStream == null) {
throw new IllegalArgumentException(NULL_ARGUMENT_STRING);
}
ExifData d = null;
ExifData d;
try {
d = new ExifReader(this).read(inStream);
} catch (ExifInvalidFormatException e) {
@@ -1000,7 +1000,7 @@ public class ExifInterface {
is = new BufferedInputStream(new FileInputStream(temp));
// Parse beginning of APP1 in exif to find size of exif header.
ExifParser parser = null;
ExifParser parser;
try {
parser = ExifParser.parse(is, this);
} catch (ExifInvalidFormatException e) {
@@ -1048,7 +1048,7 @@ public class ExifInterface {
* changes are made to the ByteBuffer.
*/
public boolean rewriteExif(ByteBuffer buf, Collection<ExifTag> tags) throws IOException {
ExifModifier mod = null;
ExifModifier mod;
try {
mod = new ExifModifier(buf, this);
for (ExifTag t : tags) {
@@ -1079,7 +1079,7 @@ public class ExifInterface {
ExifData tempData = mData;
mData = new ExifData(DEFAULT_BYTE_ORDER);
FileInputStream is = null;
ByteArrayOutputStream bytes = null;
ByteArrayOutputStream bytes;
try {
is = new FileInputStream(filename);
bytes = new ByteArrayOutputStream();
@@ -157,7 +157,7 @@ public class ExifParser {
private ExifTag mStripSizeTag;
private ExifTag mJpegSizeTag;
private boolean mNeedToParseOffsetsInCurrentIfd;
private boolean mContainExifData = false;
private boolean mContainExifData;
private int mApp1End;
private int mOffsetToApp1EndFromSOF = 0;
private byte[] mDataAboveIfd0;
@@ -759,8 +759,8 @@ public class ExifParser {
// Some invalid formatted image contains multiple APP1,
// try to find the one with Exif data.
if (marker == JpegHeader.APP1) {
int header = 0;
short headerTail = 0;
int header;
short headerTail;
if (length >= 8) {
header = dataStream.readInt();
headerTail = dataStream.readShort();
@@ -44,7 +44,7 @@ class ExifReader {
IOException {
ExifParser parser = ExifParser.parse(inputStream, mInterface);
ExifData exifData = new ExifData(parser.getByteOrder());
ExifTag tag = null;
ExifTag tag;
int event = parser.next();
while (event != ExifParser.EVENT_END) {