1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-07 09:20:04 +01:00

Added null checking throughout autofill service

This commit is contained in:
Kyle Spearrin 2017-02-22 19:00:50 -05:00
parent 27202fd740
commit 98a6a5c93d

View File

@ -54,8 +54,8 @@ namespace Bit.Android
public override void OnAccessibilityEvent(AccessibilityEvent e) public override void OnAccessibilityEvent(AccessibilityEvent e)
{ {
var root = RootInActiveWindow; var root = RootInActiveWindow;
if(string.IsNullOrWhiteSpace(e.PackageName) || e.PackageName == SystemUiPackage || if(e == null || root == null || string.IsNullOrWhiteSpace(e.PackageName) ||
root?.PackageName != e.PackageName) e.PackageName == SystemUiPackage || root.PackageName != e.PackageName)
{ {
return; return;
} }
@ -67,7 +67,7 @@ namespace Bit.Android
testNodes = null; testNodes = null;
*/ */
var notificationManager = ((NotificationManager)GetSystemService(NotificationService)); var notificationManager = (NotificationManager)GetSystemService(NotificationService);
switch(e.EventType) switch(e.EventType)
{ {
case EventTypes.WindowContentChanged: case EventTypes.WindowContentChanged:
@ -76,7 +76,7 @@ namespace Bit.Android
if(e.PackageName == BitwardenPackage) if(e.PackageName == BitwardenPackage)
{ {
notificationManager.Cancel(AutoFillNotificationId); notificationManager?.Cancel(AutoFillNotificationId);
break; break;
} }
@ -112,14 +112,14 @@ namespace Bit.Android
if(cancelNotification) if(cancelNotification)
{ {
notificationManager.Cancel(AutoFillNotificationId); notificationManager?.Cancel(AutoFillNotificationId);
} }
break; break;
default: default:
break; break;
} }
notificationManager.Dispose(); notificationManager?.Dispose();
notificationManager = null; notificationManager = null;
root.Dispose(); root.Dispose();
root = null; root = null;
@ -201,11 +201,16 @@ namespace Bit.Android
private static bool EditText(AccessibilityNodeInfo n) private static bool EditText(AccessibilityNodeInfo n)
{ {
return n.ClassName != null && n.ClassName.Contains("EditText"); return n?.ClassName?.Contains("EditText") ?? false;
} }
private void NotifyToAutofill(string uri, NotificationManager notificationManager) private void NotifyToAutofill(string uri, NotificationManager notificationManager)
{ {
if(notificationManager == null || string.IsNullOrWhiteSpace(uri))
{
return;
}
var intent = new Intent(this, typeof(AutofillActivity)); var intent = new Intent(this, typeof(AutofillActivity));
intent.PutExtra("uri", uri); intent.PutExtra("uri", uri);
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop); intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.SingleTop | ActivityFlags.ClearTop);
@ -234,10 +239,10 @@ namespace Bit.Android
private void FillCredentials(AccessibilityNodeInfo usernameNode, IEnumerable<AccessibilityNodeInfo> passwordNodes) private void FillCredentials(AccessibilityNodeInfo usernameNode, IEnumerable<AccessibilityNodeInfo> passwordNodes)
{ {
FillEditText(usernameNode, AutofillActivity.LastCredentials.Username); FillEditText(usernameNode, AutofillActivity.LastCredentials?.Username);
foreach(var n in passwordNodes) foreach(var n in passwordNodes)
{ {
FillEditText(n, AutofillActivity.LastCredentials.Password); FillEditText(n, AutofillActivity.LastCredentials?.Password);
} }
} }