Skip to content

Commit 70225db

Browse files
authored
Merge pull request #3249 from PhilippC/bugfix/stability-improvements-1.15r1
fix several potential crashes
2 parents cf3bd9a + 9644fc1 commit 70225db

6 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/Kp2aBusinessLogic/database/CheckDatabaseForChanges.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace keepass2android
3030
{
3131
public class CheckDatabaseForChanges : OperationWithFinishHandler
3232
{
33-
private readonly Context _context;
3433
private readonly IKp2aApp _app;
3534

3635

@@ -66,7 +65,7 @@ public override void Run()
6665

6766
if (!MemUtil.ArraysEqual(_app.CurrentDb.KpDatabase.HashOfFileOnDisk, hashingRemoteStream.Hash))
6867
{
69-
_app.TriggerReload(_context, null);
68+
_app.TriggerReload(null, null);
7069
Finish(true);
7170
}
7271
else

src/java/KP2ASoftkeyboard_AS/app/src/main/java/keepass2android/softkeyboard/KP2AKeyboard.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,15 @@ public void onConfigurationChanged(Configuration conf) {
521521
// locale (mSystemLocale), then reload the input locale list from the
522522
// latin ime settings (shared prefs) and reset the input locale
523523
// to the first one.
524-
final String systemLocale = conf.locale.toString();
524+
final Locale configLocale = conf.locale != null ? conf.locale
525+
: (conf.getLocales().size() > 0 ? conf.getLocales().get(0) : Locale.getDefault());
526+
final String systemLocale = configLocale.toString();
525527
if (!TextUtils.equals(systemLocale, mSystemLocale)) {
526528
mSystemLocale = systemLocale;
527529
if (mLanguageSwitcher != null) {
528530
mLanguageSwitcher.loadLocales(
529531
PreferenceManager.getDefaultSharedPreferences(this));
530-
mLanguageSwitcher.setSystemLocale(conf.locale);
532+
mLanguageSwitcher.setSystemLocale(configLocale);
531533
toggleLanguage(true, true);
532534
} else {
533535
reloadKeyboards();

src/keepass2android-app/app/App.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,17 @@ public void UpdateOngoingNotification()
360360
var ctx = LocaleManager.LocalizedAppContext;
361361
if (DatabaseIsUnlocked || QuickLocked)
362362
{
363-
ContextCompat.StartForegroundService(ctx, new Intent(ctx, typeof(OngoingNotificationsService)));
363+
try
364+
{
365+
ContextCompat.StartForegroundService(ctx, new Intent(ctx, typeof(OngoingNotificationsService)));
366+
}
367+
catch (Exception e)
368+
{
369+
// ForegroundServiceStartNotAllowedException (Android 12+): startForegroundService() is
370+
// not allowed when called from a background-restricted context such as onTaskRemoved().
371+
// In this case the notification simply cannot be updated; this is acceptable.
372+
Kp2aLog.LogUnexpectedError(e);
373+
}
364374
}
365375
else
366376
{
@@ -1023,7 +1033,10 @@ public void TriggerReload(Context ctx, Action<bool> actionOnResult)
10231033
Handler handler = new Handler(Looper.MainLooper);
10241034
handler.Post(() =>
10251035
{
1026-
AskForReload((Activity)ctx, actionOnResult);
1036+
var activity = (ctx as Activity) ?? (ActiveContext as Activity);
1037+
if (activity == null)
1038+
return;
1039+
AskForReload(activity, actionOnResult);
10271040
});
10281041
}
10291042

src/keepass2android-app/services/BackgroundSyncService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void OnCreate()
5151

5252
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
5353
{
54-
if (intent.Action == ActionStop)
54+
if (intent?.Action == ActionStop)
5555
{
5656
Log.Debug(Tag, "OnStartCommand: STOP");
5757
StopForeground(StopForegroundFlags.Remove);

src/keepass2android-app/views/GroupListItemView.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public override bool Activated
7777

7878
public void SetRightArrowVisibility(bool visible)
7979
{
80-
FindViewById(Resource.Id.right_arrow).Visibility = visible ? ViewStates.Visible : ViewStates.Invisible;
80+
var arrow = FindViewById(Resource.Id.right_arrow);
81+
if (arrow != null)
82+
arrow.Visibility = visible ? ViewStates.Visible : ViewStates.Invisible;
8183
}
8284

8385
public abstract void OnClick();

src/keepass2android-app/views/PwEntryView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ private PwEntryView(GroupBaseActivity groupActivity, PwEntry pw, int pos) : base
8080
_textView = (TextView)ev.FindViewById(Resource.Id.entry_text);
8181
_textView.TextSize = PrefsUtil.GetListTextSize(groupActivity);
8282

83-
Database db = App.Kp2a.FindDatabaseForElement(pw);
83+
Database db = App.Kp2a.TryFindDatabaseForElement(pw);
8484

85-
ev.FindViewById(Resource.Id.entry_icon_bkg).Visibility = db.DrawableFactory.IsWhiteIconSet ? ViewStates.Visible : ViewStates.Gone;
85+
ev.FindViewById(Resource.Id.entry_icon_bkg).Visibility = db?.DrawableFactory.IsWhiteIconSet == true ? ViewStates.Visible : ViewStates.Gone;
8686

8787
_textviewDetails = (TextView)ev.FindViewById(Resource.Id.entry_text_detail);
8888
_textviewDetails.TextSize = PrefsUtil.GetListDetailTextSize(groupActivity);

0 commit comments

Comments
 (0)