Skip to content

Commit

Permalink
Fix a crash for SDK 28 and lower in ICU4J due to previous update
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijitvalluri committed Dec 22, 2020
1 parent 6c7953c commit 6f2d544
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.abhijitvalluri.android.fitnotifications"
minSdkVersion 19
targetSdkVersion 30
versionCode 44
versionName "2.11.0"
versionCode 45
versionName "2.11.1"
}
compileOptions {
encoding "UTF-8"
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 44,
"versionName": "2.11.0",
"versionCode": 45,
"versionName": "2.11.1",
"outputFile": "app-release.apk"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.os.PowerManager;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.widget.RemoteViews;

import com.abhijitvalluri.android.fitnotifications.R;
Expand Down Expand Up @@ -60,6 +61,7 @@
*/
public class NLService extends NotificationListenerService {

private static final String LOG_TAG = "FitNotif_NLService";
private static final Integer NOTIFICATION_ID = (int)((new Date().getTime() / 1000L) % Integer.MAX_VALUE);

private static final MessageExtractor sDefaultExtractor = new GenericMessageExtractor();
Expand All @@ -84,7 +86,7 @@ public class NLService extends NotificationListenerService {
private static int mNotifLimitDurationMillis;

private DebugLog mDebugLog;
private TranslitUtil translitUtil;
private TranslitUtil translitUtil = null;
private NotificationManager mNotificationManager;
private AppSelectionsStore mAppSelectionsStore;
private Map<String, Long> mLastNotificationTimeMap;
Expand Down Expand Up @@ -134,16 +136,17 @@ public void onCreate() {
mNumSplitNotifications = preferences.getInt(
getString(R.string.num_split_notifications_key), Constants.DEFAULT_NUM_NOTIF);
mDisplayAppName = preferences.getBoolean(getString(R.string.display_app_name_key), true);
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);

// base context is needed to access Resources
Resources res = getResources();

translitUtil = new TranslitUtil(res);
try {
translitUtil = new TranslitUtil(res);
} catch (Throwable e) { // FIXME: Ugly hack for now. Next app update should update the ICU4J lib, and/or clean up the transliteration code to fix these horrible errors! :)
if (mDebugLog.isEnabled()) {
mDebugLog.writeLog("Failed to initialize TranslitUtil class. icu4j Transliterator threw: " + e);
}
Log.e(LOG_TAG, "Failed to initialize TranslitUtil class. icu4j Transliterator threw: " + e);
}

// Telegram
mMessageExtractors.put("org.telegram.messenger", new GroupSummaryMessageExtractor(res, true));
Expand Down Expand Up @@ -314,7 +317,7 @@ public void onNotificationPosted(final StatusBarNotification sbn) {
notificationText = "[" + mAppSelectionsStore.getAppName(appPackageName) + "] " + notificationText;
}

if (mTransliterateNotif) {
if (mTransliterateNotif && translitUtil != null) {
notificationTitle = translitUtil.transliterate(notificationTitle);
notificationText = translitUtil.transliterate(notificationText);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* Some Latin symbols returned by ICU4J are not supported by Fitbit.
* This class takes care of replacing them with the supported ones.
*/
public class TranslitUtil {
private static final Transliterator ANY_TO_LATIN = Transliterator.getInstance("Any-Latin");
public class TranslitUtil { // FIXME: See below (line 25)
private static final Transliterator ANY_TO_LATIN = Transliterator.getInstance("Any-Latin"); // FIXME: Throws a java.lang.NoSuchMethodError exception on SDK 28 and below (potentially buggy ICU4J lib, needs updating)

private static final String TAG = "TranslitUtil";

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,14 @@
killers or at least allow them to keep the \"Fit Notifications\" service running.</p>
]]></string>
<string name="whats_new_text"><![CDATA[
<p style=\"font-size: 140%;\">Changes in <b>version 2.11.0:</b></p>
<p style=\"font-size: 140%;\">Changes in <b>version 2.11.1:</b></p>
<ul>
<li>Updated app to support Android 11 platform, general stability improvements, bug fixes, and UI tweaks.<br /><br /></li>
<li>Updated placeholder notification message and added an FAQ entry to explain the importance of placeholder
notifications, and clarify potential issues when using the \"Dismiss placeholder notification\" setting in the app.<br /><br /></li>
<li>Implemented a proper dark theme! Now the app should look even better when you use a system-wide dark/night theme!<br /><br /></li>
<li><b>Emergency update:</b> Fixed a crash observed in the previous update (2.11.0) that occurs on older Android devices.
This crash was due to the transliteration feature not initializing correctly on phones running Android 9 or lower.<br /></li>
</ul>
<p><b>Note: </b>If your Fitbit device does not vibrate but still receives notifications, then
try enabling the \"Always Vibrate\" setting in the Fitbit app, under the \"Notifications\"
Expand Down

0 comments on commit 6f2d544

Please sign in to comment.