Skip to content

Commit

Permalink
Merge pull request #2766 from PhilippC/bugfix/potential-crashes-when-…
Browse files Browse the repository at this point in the history
…registering-receivers

fix potential crashes
  • Loading branch information
PhilippC authored Feb 11, 2025
2 parents c4d6e18 + ee41a60 commit 4619431
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,13 @@ public void onCreate() {
pFilter.addAction("android.intent.action.PACKAGE_ADDED");
pFilter.addAction("android.intent.action.PACKAGE_REPLACED");
pFilter.addAction("android.intent.action.PACKAGE_REMOVED");
registerReceiver(mPluginManager, pFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(mPluginManager, pFilter, RECEIVER_EXPORTED);
}
else
{
registerReceiver(mPluginManager, pFilter);
}


LatinIMEUtil.GCUtils.getInstance().reset();
Expand All @@ -375,16 +381,28 @@ public void onCreate() {

// register to receive ringer mode changes for silent mode
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(mSilentModeReceiver, filter);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(mSilentModeReceiver, filter, RECEIVER_EXPORTED);
}
else
{
registerReceiver(mSilentModeReceiver, filter);
}

prefs.registerOnSharedPreferenceChangeListener(this);

//check if we have KP2A data available:
mHadKp2aData = mShowKp2aKeyboard = keepass2android.kbbridge.KeyboardData.hasData();
mHadKp2aData = mShowKp2aKeyboard = KeyboardData.hasData();

mClearKeyboardReceiver = new ClearKeyboardBroadcastReceiver();
registerReceiver(mClearKeyboardReceiver, new IntentFilter(get_KEEPASS2ANDROID_KEYBOARD_CLEARED(this)));
android.util.Log.d("KP2AK", "registered receiver for clear keyboard broadcast: "+get_KEEPASS2ANDROID_KEYBOARD_CLEARED(this));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
registerReceiver(mClearKeyboardReceiver, new IntentFilter(get_KEEPASS2ANDROID_KEYBOARD_CLEARED(this)), RECEIVER_EXPORTED);
}
else
{
registerReceiver(mClearKeyboardReceiver, new IntentFilter(get_KEEPASS2ANDROID_KEYBOARD_CLEARED(this)));
}
Log.d("KP2AK", "registered receiver for clear keyboard broadcast: "+get_KEEPASS2ANDROID_KEYBOARD_CLEARED(this));

}

Expand Down
5 changes: 3 additions & 2 deletions src/keepass2android-app/EntryActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ You should have received a copy of the GNU General Public License
using KeeTrayTOTP.Libraries;
using Boolean = Java.Lang.Boolean;
using Android.Util;
using AndroidX.Core.Content;
using Google.Android.Material.Dialog;
using keepass2android;

Expand Down Expand Up @@ -491,9 +492,9 @@ protected override void OnCreate(Bundle savedInstanceState)
App.Kp2a.LastOpenedEntry = new PwEntryOutput(Entry, App.Kp2a.CurrentDb);

_pluginActionReceiver = new PluginActionReceiver(this);
RegisterReceiver(_pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction), ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _pluginActionReceiver, new IntentFilter(Strings.ActionAddEntryAction), (int)ReceiverFlags.Exported);
_pluginFieldReceiver = new PluginFieldReceiver(this);
RegisterReceiver(_pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField), ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _pluginFieldReceiver, new IntentFilter(Strings.ActionSetEntryField), (int)ReceiverFlags.Exported);

var notifyPluginsOnOpenThread = new Thread(NotifyPluginsOnOpen);
notifyPluginsOnOpenThread.Start();
Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/LockCloseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using AndroidX.Core.Content;
using KeePassLib.Serialization;

namespace keepass2android
Expand Down Expand Up @@ -69,7 +70,7 @@ protected override void OnCreate(Bundle savedInstanceState)
IntentFilter filter = new IntentFilter();
filter.AddAction(Intents.DatabaseLocked);
filter.AddAction(Intent.ActionScreenOff);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);
}

protected override void OnDestroy()
Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/LockCloseListActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ You should have received a copy of the GNU General Public License
using Android.Preferences;
using Android.Runtime;
using Android.Views;
using AndroidX.Core.Content;
using KeePassLib.Serialization;

namespace keepass2android
Expand Down Expand Up @@ -55,7 +56,7 @@ protected override void OnCreate(Bundle savedInstanceState)

filter.AddAction(Intents.DatabaseLocked);
filter.AddAction(Intent.ActionScreenOff);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);

}

Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/LockingClosePreferenceActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You should have received a copy of the GNU General Public License
using System;
using Android.Content;
using Android.OS;
using AndroidX.Core.Content;
using KeePassLib.Serialization;

namespace keepass2android
Expand All @@ -39,7 +40,7 @@ protected override void OnCreate(Bundle savedInstanceState)
_intentReceiver = new LockCloseActivityBroadcastReceiver(this);
IntentFilter filter = new IntentFilter();
filter.AddAction(Intents.DatabaseLocked);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);
}

protected override void OnResume() {
Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/PasswordActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ You should have received a copy of the GNU General Public License
using Exception = System.Exception;
using String = System.String;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
using AndroidX.Core.Content;

namespace keepass2android
{
Expand Down Expand Up @@ -647,7 +648,7 @@ protected override void OnCreate(Bundle savedInstanceState)
_intentReceiver = new PasswordActivityBroadcastReceiver(this);
IntentFilter filter = new IntentFilter();
filter.AddAction(Intent.ActionScreenOff);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);


//use FlagSecure to make sure the last (revealed) character of the master password is not visible in recent apps
Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/QuickUnlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ You should have received a copy of the GNU General Public License
using KeePassLib;
using KeePassLib.Serialization;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;
using AndroidX.Core.Content;

namespace keepass2android
{
Expand Down Expand Up @@ -153,7 +154,7 @@ protected override void OnCreate(Bundle bundle)
_intentReceiver = new QuickUnlockBroadcastReceiver(this);
IntentFilter filter = new IntentFilter();
filter.AddAction(Intents.DatabaseLocked);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);

Util.SetNoPersonalizedLearning(FindViewById<EditText>(Resource.Id.QuickUnlock_password));

Expand Down
3 changes: 2 additions & 1 deletion src/keepass2android-app/SelectCurrentDbActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using KeePassLib.Serialization;
using Console = System.Console;
using Object = Java.Lang.Object;
using AndroidX.Core.Content;

namespace keepass2android
{
Expand Down Expand Up @@ -343,7 +344,7 @@ protected override void OnStart()
IntentFilter filter = new IntentFilter();
filter.AddAction(Intents.DatabaseLocked);
filter.AddAction(Intent.ActionScreenOff);
RegisterReceiver(_intentReceiver, filter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _intentReceiver, filter, (int)ReceiverFlags.Exported);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/keepass2android-app/app/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ public override void OnCreate()
intentFilter.AddAction(Intents.LockDatabase);
intentFilter.AddAction(Intents.LockDatabaseByTimeout);
intentFilter.AddAction(Intents.CloseDatabase);
Context.RegisterReceiver(broadcastReceiver, intentFilter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(Context, broadcastReceiver, intentFilter, (int)ReceiverFlags.Exported);

//ZXing.Net.Mobile.Forms.Android.Platform.Init();
}
Expand Down
6 changes: 4 additions & 2 deletions src/keepass2android-app/services/CopyToClipboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You should have received a copy of the GNU General Public License
using keepass2android;
using KeePassLib.Serialization;
using PluginTOTP;
using AndroidX.Core.Content;

namespace keepass2android
{
Expand Down Expand Up @@ -322,7 +323,8 @@ public override StartCommandResult OnStartCommand(Intent intent, StartCommandFla
_stopOnLockBroadcastReceiver = new StopOnLockBroadcastReceiver(this);
IntentFilter filter = new IntentFilter();
filter.AddAction(Intents.DatabaseLocked);
RegisterReceiver(_stopOnLockBroadcastReceiver, filter, ReceiverFlags.Exported);

ContextCompat.RegisterReceiver(this, _stopOnLockBroadcastReceiver, filter, (int)ReceiverFlags.Exported);
}

if ((intent.Action == Intents.ShowNotification) || (intent.Action == Intents.UpdateKeyboard))
Expand Down Expand Up @@ -529,7 +531,7 @@ public void DisplayAccessNotifications(PwEntryOutput entry, bool activateKeyboar
_notificationDeletedBroadcastReceiver = new NotificationDeletedBroadcastReceiver(this);
IntentFilter deletefilter = new IntentFilter();
deletefilter.AddAction(ActionNotificationCancelled);
RegisterReceiver(_notificationDeletedBroadcastReceiver, deletefilter, ReceiverFlags.Exported);
ContextCompat.RegisterReceiver(this, _notificationDeletedBroadcastReceiver, deletefilter, (int)ReceiverFlags.Exported);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
using Android.OS;
using Android.Preferences;
using AndroidX.Core.App;
using AndroidX.Core.Content;
using keepass2android;
using KeePassLib.Utility;

Expand Down Expand Up @@ -60,8 +61,8 @@ public override void OnCreate()
_screenOffReceiver = new ScreenOffReceiver();
IntentFilter filter = new IntentFilter();
filter.AddAction(Intent.ActionScreenOff);
RegisterReceiver(_screenOffReceiver, filter, ReceiverFlags.Exported);
}
ContextCompat.RegisterReceiver(this, _screenOffReceiver, filter, (int)ReceiverFlags.Exported);
}


public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
Expand Down

0 comments on commit 4619431

Please sign in to comment.