diff --git a/src/Kp2aBusinessLogic/database/CheckDatabaseForChanges.cs b/src/Kp2aBusinessLogic/database/CheckDatabaseForChanges.cs index 3e7b7ec47..0d2616a88 100644 --- a/src/Kp2aBusinessLogic/database/CheckDatabaseForChanges.cs +++ b/src/Kp2aBusinessLogic/database/CheckDatabaseForChanges.cs @@ -30,7 +30,6 @@ namespace keepass2android { public class CheckDatabaseForChanges : OperationWithFinishHandler { - private readonly Context _context; private readonly IKp2aApp _app; @@ -66,7 +65,7 @@ public override void Run() if (!MemUtil.ArraysEqual(_app.CurrentDb.KpDatabase.HashOfFileOnDisk, hashingRemoteStream.Hash)) { - _app.TriggerReload(_context, null); + _app.TriggerReload(null, null); Finish(true); } else diff --git a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KP2AKeyboard.java b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KP2AKeyboard.java index f1a40f6bb..dba897f2b 100644 --- a/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KP2AKeyboard.java +++ b/src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KP2AKeyboard.java @@ -521,13 +521,15 @@ public void onConfigurationChanged(Configuration conf) { // locale (mSystemLocale), then reload the input locale list from the // latin ime settings (shared prefs) and reset the input locale // to the first one. - final String systemLocale = conf.locale.toString(); + final Locale configLocale = conf.locale != null ? conf.locale + : (conf.getLocales().size() > 0 ? conf.getLocales().get(0) : Locale.getDefault()); + final String systemLocale = configLocale.toString(); if (!TextUtils.equals(systemLocale, mSystemLocale)) { mSystemLocale = systemLocale; if (mLanguageSwitcher != null) { mLanguageSwitcher.loadLocales( PreferenceManager.getDefaultSharedPreferences(this)); - mLanguageSwitcher.setSystemLocale(conf.locale); + mLanguageSwitcher.setSystemLocale(configLocale); toggleLanguage(true, true); } else { reloadKeyboards(); diff --git a/src/keepass2android-app/app/App.cs b/src/keepass2android-app/app/App.cs index 4123500a2..2ebd5f7c7 100644 --- a/src/keepass2android-app/app/App.cs +++ b/src/keepass2android-app/app/App.cs @@ -360,7 +360,17 @@ public void UpdateOngoingNotification() var ctx = LocaleManager.LocalizedAppContext; if (DatabaseIsUnlocked || QuickLocked) { - ContextCompat.StartForegroundService(ctx, new Intent(ctx, typeof(OngoingNotificationsService))); + try + { + ContextCompat.StartForegroundService(ctx, new Intent(ctx, typeof(OngoingNotificationsService))); + } + catch (Exception e) + { + // ForegroundServiceStartNotAllowedException (Android 12+): startForegroundService() is + // not allowed when called from a background-restricted context such as onTaskRemoved(). + // In this case the notification simply cannot be updated; this is acceptable. + Kp2aLog.LogUnexpectedError(e); + } } else { @@ -1023,7 +1033,10 @@ public void TriggerReload(Context ctx, Action actionOnResult) Handler handler = new Handler(Looper.MainLooper); handler.Post(() => { - AskForReload((Activity)ctx, actionOnResult); + var activity = (ctx as Activity) ?? (ActiveContext as Activity); + if (activity == null) + return; + AskForReload(activity, actionOnResult); }); } diff --git a/src/keepass2android-app/services/BackgroundSyncService.cs b/src/keepass2android-app/services/BackgroundSyncService.cs index 924d97627..4e724e0f8 100644 --- a/src/keepass2android-app/services/BackgroundSyncService.cs +++ b/src/keepass2android-app/services/BackgroundSyncService.cs @@ -51,7 +51,7 @@ public override void OnCreate() public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId) { - if (intent.Action == ActionStop) + if (intent?.Action == ActionStop) { Log.Debug(Tag, "OnStartCommand: STOP"); StopForeground(StopForegroundFlags.Remove); diff --git a/src/keepass2android-app/views/GroupListItemView.cs b/src/keepass2android-app/views/GroupListItemView.cs index 3fd49ab7f..6859d7424 100644 --- a/src/keepass2android-app/views/GroupListItemView.cs +++ b/src/keepass2android-app/views/GroupListItemView.cs @@ -77,7 +77,9 @@ public override bool Activated public void SetRightArrowVisibility(bool visible) { - FindViewById(Resource.Id.right_arrow).Visibility = visible ? ViewStates.Visible : ViewStates.Invisible; + var arrow = FindViewById(Resource.Id.right_arrow); + if (arrow != null) + arrow.Visibility = visible ? ViewStates.Visible : ViewStates.Invisible; } public abstract void OnClick(); diff --git a/src/keepass2android-app/views/PwEntryView.cs b/src/keepass2android-app/views/PwEntryView.cs index 4dc4ace4a..5e9508837 100644 --- a/src/keepass2android-app/views/PwEntryView.cs +++ b/src/keepass2android-app/views/PwEntryView.cs @@ -80,9 +80,9 @@ private PwEntryView(GroupBaseActivity groupActivity, PwEntry pw, int pos) : base _textView = (TextView)ev.FindViewById(Resource.Id.entry_text); _textView.TextSize = PrefsUtil.GetListTextSize(groupActivity); - Database db = App.Kp2a.FindDatabaseForElement(pw); + Database db = App.Kp2a.TryFindDatabaseForElement(pw); - ev.FindViewById(Resource.Id.entry_icon_bkg).Visibility = db.DrawableFactory.IsWhiteIconSet ? ViewStates.Visible : ViewStates.Gone; + ev.FindViewById(Resource.Id.entry_icon_bkg).Visibility = db?.DrawableFactory.IsWhiteIconSet == true ? ViewStates.Visible : ViewStates.Gone; _textviewDetails = (TextView)ev.FindViewById(Resource.Id.entry_text_detail); _textviewDetails.TextSize = PrefsUtil.GetListDetailTextSize(groupActivity);