From 9a2567bf78570e905581ec8734f6f34075db0c8e Mon Sep 17 00:00:00 2001 From: Michael W Date: Sun, 24 Feb 2019 21:34:10 +0100 Subject: [PATCH] Trust: Onboarding: Listen for locale changes * When SuW is not yet done, the notification is already posted * This results in an english notification text when the SuW is finished because the notification doesn't update when the locale changes -> Listen for locale changes and post the notification again (= update) Change-Id: I920a52c5c85c91adb7333a20d410a5464e80a812 --- .../internal/TrustInterfaceService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java index 2dcb9385..51e6d321 100644 --- a/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java +++ b/lineage/lib/main/java/org/lineageos/platform/internal/TrustInterfaceService.java @@ -21,9 +21,11 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.admin.DevicePolicyManager; +import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.net.Uri; import android.os.Build; import android.os.IBinder; @@ -98,6 +100,7 @@ public class TrustInterfaceService extends LineageSystemService { // Onboard if (!hasOnboardedUser()) { postOnBoardingNotification(); + registerLocaleChangedReceiver(); return; } @@ -354,6 +357,26 @@ public class TrustInterfaceService extends LineageSystemService { LineageSettings.System.TRUST_INTERFACE_HINTED, 0) == 1; } + private void registerLocaleChangedReceiver() { + IntentFilter filter = new IntentFilter(Intent.ACTION_LOCALE_CHANGED); + mContext.registerReceiver(mReceiver, filter); + } + + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction() == Intent.ACTION_LOCALE_CHANGED) { + if (!hasOnboardedUser()) { + // When are not onboarded, we want to change the language of the notification + postOnBoardingNotification(); + } else { + // We don't care anymore about language changes + context.unregisterReceiver(this); + } + } + } + }; + /* Service */ private final IBinder mService = new ITrustInterface.Stub() {