1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-31 07:33:46 +00:00

More null checks. Catch null exception in accessibility service.

This commit is contained in:
Kyle Spearrin
2017-02-25 16:10:18 -05:00
parent 910658aa93
commit 8e5a01d82c
5 changed files with 101 additions and 83 deletions

View File

@@ -17,7 +17,7 @@
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />

View File

@@ -53,76 +53,76 @@ namespace Bit.Android
public override void OnAccessibilityEvent(AccessibilityEvent e)
{
var root = RootInActiveWindow;
if(e == null || root == null || string.IsNullOrWhiteSpace(e.PackageName) ||
e.PackageName == SystemUiPackage || root.PackageName != e.PackageName)
try
{
return;
}
var root = RootInActiveWindow;
if(e == null || root == null || string.IsNullOrWhiteSpace(e.PackageName) ||
e.PackageName == SystemUiPackage || root.PackageName != e.PackageName)
{
return;
}
/*
var testNodes = GetWindowNodes(root, e, n => n.ViewIdResourceName != null && n.Text != null, false);
var testNodesData = testNodes.Select(n => new { id = n.ViewIdResourceName, text = n.Text });
testNodes.Dispose();
*/
/*
var testNodes = GetWindowNodes(root, e, n => n.ViewIdResourceName != null && n.Text != null, false);
var testNodesData = testNodes.Select(n => new { id = n.ViewIdResourceName, text = n.Text });
testNodes.Dispose();
*/
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
switch(e.EventType)
{
case EventTypes.WindowContentChanged:
case EventTypes.WindowStateChanged:
var cancelNotification = true;
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
switch(e.EventType)
{
case EventTypes.WindowContentChanged:
case EventTypes.WindowStateChanged:
var cancelNotification = true;
if(e.PackageName == BitwardenPackage)
{
notificationManager?.Cancel(AutoFillNotificationId);
break;
}
var passwordNodes = GetWindowNodes(root, e, n => n.Password, false);
if(passwordNodes.Count > 0)
{
var uri = GetUri(root);
if(uri != null && !uri.Contains(BitwardenWebsite))
if(e.PackageName == BitwardenPackage)
{
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
{
var allEditTexts = GetWindowNodes(root, e, n => EditText(n), false);
var usernameEditText = allEditTexts.TakeWhile(n => !n.Password).LastOrDefault();
FillCredentials(usernameEditText, passwordNodes);
allEditTexts.Dispose();
//allEditTexts = null;
usernameEditText.Dispose();
//usernameEditText = null;
}
else
{
NotifyToAutofill(uri, notificationManager);
cancelNotification = false;
}
notificationManager?.Cancel(AutoFillNotificationId);
break;
}
AutofillActivity.LastCredentials = null;
}
var passwordNodes = GetWindowNodes(root, e, n => n.Password, false);
if(passwordNodes.Count > 0)
{
var uri = GetUri(root);
if(uri != null && !uri.Contains(BitwardenWebsite))
{
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
{
var allEditTexts = GetWindowNodes(root, e, n => EditText(n), false);
var usernameEditText = allEditTexts.TakeWhile(n => !n.Password).LastOrDefault();
FillCredentials(usernameEditText, passwordNodes);
passwordNodes.Dispose();
//passwordNodes = null;
allEditTexts.Dispose();
usernameEditText.Dispose();
}
else
{
NotifyToAutofill(uri, notificationManager);
cancelNotification = false;
}
}
if(cancelNotification)
{
notificationManager?.Cancel(AutoFillNotificationId);
}
break;
default:
break;
AutofillActivity.LastCredentials = null;
}
passwordNodes.Dispose();
if(cancelNotification)
{
notificationManager?.Cancel(AutoFillNotificationId);
}
break;
default:
break;
}
notificationManager?.Dispose();
root.Dispose();
e.Dispose();
}
notificationManager?.Dispose();
//notificationManager = null;
root.Dispose();
//root = null;
e.Dispose();
// Some unknown condition is causing NullReferenceException's in production. Suppress it for now.
catch(NullReferenceException) { }
}
public override void OnInterrupt()
@@ -141,7 +141,6 @@ namespace Bit.Android
{
uri = ExtractUri(uri, addressNode, SupportedBrowsers[root.PackageName]);
addressNode.Dispose();
//addressNode = null;
}
}
@@ -233,7 +232,6 @@ namespace Bit.Android
notificationManager.Notify(AutoFillNotificationId, builder.Build());
builder.Dispose();
//builder = null;
}
private void FillCredentials(AccessibilityNodeInfo usernameNode, IEnumerable<AccessibilityNodeInfo> passwordNodes)

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.x8bit.bitwarden" android:versionName="1.4.2" android:installLocation="auto" android:versionCode="101">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.x8bit.bitwarden" android:versionName="1.4.3" android:installLocation="auto" android:versionCode="502">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />