Messaging: Fix a few android related things

* NotificationBuilder.addPerson(String) -> .addPerson(Person)
* Wearableextenter.addPage deprecated without replacement
* Html.fromHtml(String) -> .fromHtml(String, int)
* Handlers need Loopers
* Resource-IDs are not final by default (if-else instead of switch-case)
* call super.onFinishInflate() in override of onFinishInflate()
* Configuration.locale -> configuration.getLocales().get(0)
* SimpleDateFormat needs localization as well
* AudioAttributes instead of setAudioStreamType()
* isDataEnabled() is a public method, no need for reflection anymore

Change-Id: Icd830768b86edca3e0b44f1edc6c57facc9f731a
This commit is contained in:
Michael W
2024-12-26 15:54:37 +01:00
parent e128bff457
commit d940ab74ad
33 changed files with 313 additions and 388 deletions
+4 -3
View File
@@ -110,8 +110,8 @@ public class Dates {
flags = FORCE_12_HOUR;
}
return getOlderThanAYearTimestamp(time,
context.getResources().getConfiguration().locale, false /*abbreviated*/,
flags);
context.getResources().getConfiguration().getLocales().get(0),
false /*abbreviated*/, flags);
}
private static CharSequence getTimeString(final long time, final boolean abbreviated,
@@ -124,7 +124,8 @@ public class Dates {
flags = FORCE_12_HOUR;
}
return getTimestamp(time, System.currentTimeMillis(), abbreviated,
context.getResources().getConfiguration().locale, flags, minPeriodToday);
context.getResources().getConfiguration().getLocales().get(0), flags,
minPeriodToday);
}
@VisibleForTesting
+3 -2
View File
@@ -1,5 +1,6 @@
/*
* 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.
@@ -21,7 +22,6 @@ import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import com.android.messaging.Factory;
import com.android.messaging.R;
@@ -39,7 +39,8 @@ public class FileUtil {
private static synchronized File getNewFile(File directory, String extension,
String fileNameFormat) throws IOException {
final Date date = new Date(System.currentTimeMillis());
final SimpleDateFormat dateFormat = new SimpleDateFormat(fileNameFormat);
final SimpleDateFormat dateFormat = new SimpleDateFormat(fileNameFormat,
Locale.getDefault(Locale.Category.FORMAT));
final String numberedFileNameFormat = dateFormat.format(date) + "_%02d" + "." + extension;
for (int i = 1; i <= 99; i++) { // Only save 99 of the same file name.
final String newName = String.format(Locale.US, numberedFileNameFormat, i);
@@ -18,6 +18,7 @@ package com.android.messaging.util;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
@@ -37,7 +38,9 @@ public class MediaUtilImpl extends MediaUtil {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
try {
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
AudioAttributes.Builder attributes = new AudioAttributes.Builder();
attributes.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION);
mediaPlayer.setAudioAttributes(attributes.build());
final AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId);
mediaPlayer.setDataSource(
afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
@@ -18,6 +18,7 @@
package com.android.messaging.util;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
@@ -92,7 +93,9 @@ public class NotificationPlayer implements OnCompletionListener {
.getSystemService(Context.AUDIO_SERVICE);
try {
final MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(mCmd.stream);
AudioAttributes.Builder attributes = new AudioAttributes.Builder();
attributes.setLegacyStreamType(mCmd.stream);
player.setAudioAttributes(attributes.build());
player.setDataSource(Factory.get().getApplicationContext(), mCmd.uri);
player.setLooping(mCmd.looping);
player.setVolume(mCmd.volume, mCmd.volume);
+1 -15
View File
@@ -40,13 +40,11 @@ import com.android.messaging.Factory;
import com.android.messaging.R;
import com.android.messaging.datamodel.data.ParticipantData;
import com.android.messaging.sms.MmsSmsUtils;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -297,19 +295,7 @@ public class PhoneUtils {
* @return true if mobile data is enabled, false otherwise
*/
public boolean isMobileDataEnabled() {
boolean mobileDataEnabled = false;
try {
final Class cmClass = mTelephonyManager.getClass();
final Method method = cmClass.getDeclaredMethod("getDataEnabled", Integer.TYPE);
method.setAccessible(true); // Make the method callable
// get the setting for "mobile data"
mobileDataEnabled = (Boolean) method.invoke(
mTelephonyManager, Integer.valueOf(mSubId));
} catch (final Exception e) {
LogUtil.e(TAG, "PhoneUtil.isMobileDataEnabled: system api not found", e);
}
return mobileDataEnabled;
return mTelephonyManager.createForSubscriptionId(mSubId).isDataEnabled();
}
/**