mirror of
https://github.com/bitwarden/android.git
synced 2024-12-19 07:41:52 +03:00
More null checks. Catch null exception in accessibility service.
This commit is contained in:
parent
910658aa93
commit
8e5a01d82c
5 changed files with 101 additions and 83 deletions
|
@ -17,7 +17,7 @@
|
||||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||||
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
|
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
|
||||||
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
|
||||||
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
|
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
|
||||||
<AndroidStoreUncompressedFileExtensions />
|
<AndroidStoreUncompressedFileExtensions />
|
||||||
<MandroidI18n />
|
<MandroidI18n />
|
||||||
|
|
|
@ -53,76 +53,76 @@ namespace Bit.Android
|
||||||
|
|
||||||
public override void OnAccessibilityEvent(AccessibilityEvent e)
|
public override void OnAccessibilityEvent(AccessibilityEvent e)
|
||||||
{
|
{
|
||||||
var root = RootInActiveWindow;
|
try
|
||||||
if(e == null || root == null || string.IsNullOrWhiteSpace(e.PackageName) ||
|
|
||||||
e.PackageName == SystemUiPackage || root.PackageName != e.PackageName)
|
|
||||||
{
|
{
|
||||||
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 testNodes = GetWindowNodes(root, e, n => n.ViewIdResourceName != null && n.Text != null, false);
|
||||||
var testNodesData = testNodes.Select(n => new { id = n.ViewIdResourceName, text = n.Text });
|
var testNodesData = testNodes.Select(n => new { id = n.ViewIdResourceName, text = n.Text });
|
||||||
testNodes.Dispose();
|
testNodes.Dispose();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
var notificationManager = (NotificationManager)GetSystemService(NotificationService);
|
||||||
switch(e.EventType)
|
switch(e.EventType)
|
||||||
{
|
{
|
||||||
case EventTypes.WindowContentChanged:
|
case EventTypes.WindowContentChanged:
|
||||||
case EventTypes.WindowStateChanged:
|
case EventTypes.WindowStateChanged:
|
||||||
var cancelNotification = true;
|
var cancelNotification = true;
|
||||||
|
|
||||||
if(e.PackageName == BitwardenPackage)
|
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(NeedToAutofill(AutofillActivity.LastCredentials, uri))
|
notificationManager?.Cancel(AutoFillNotificationId);
|
||||||
{
|
break;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
allEditTexts.Dispose();
|
||||||
//passwordNodes = null;
|
usernameEditText.Dispose();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NotifyToAutofill(uri, notificationManager);
|
||||||
|
cancelNotification = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(cancelNotification)
|
AutofillActivity.LastCredentials = null;
|
||||||
{
|
}
|
||||||
notificationManager?.Cancel(AutoFillNotificationId);
|
|
||||||
}
|
passwordNodes.Dispose();
|
||||||
break;
|
|
||||||
default:
|
if(cancelNotification)
|
||||||
break;
|
{
|
||||||
|
notificationManager?.Cancel(AutoFillNotificationId);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationManager?.Dispose();
|
||||||
|
root.Dispose();
|
||||||
|
e.Dispose();
|
||||||
}
|
}
|
||||||
|
// Some unknown condition is causing NullReferenceException's in production. Suppress it for now.
|
||||||
notificationManager?.Dispose();
|
catch(NullReferenceException) { }
|
||||||
//notificationManager = null;
|
|
||||||
root.Dispose();
|
|
||||||
//root = null;
|
|
||||||
e.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInterrupt()
|
public override void OnInterrupt()
|
||||||
|
@ -141,7 +141,6 @@ namespace Bit.Android
|
||||||
{
|
{
|
||||||
uri = ExtractUri(uri, addressNode, SupportedBrowsers[root.PackageName]);
|
uri = ExtractUri(uri, addressNode, SupportedBrowsers[root.PackageName]);
|
||||||
addressNode.Dispose();
|
addressNode.Dispose();
|
||||||
//addressNode = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +232,6 @@ namespace Bit.Android
|
||||||
notificationManager.Notify(AutoFillNotificationId, builder.Build());
|
notificationManager.Notify(AutoFillNotificationId, builder.Build());
|
||||||
|
|
||||||
builder.Dispose();
|
builder.Dispose();
|
||||||
//builder = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillCredentials(AccessibilityNodeInfo usernameNode, IEnumerable<AccessibilityNodeInfo> passwordNodes)
|
private void FillCredentials(AccessibilityNodeInfo usernameNode, IEnumerable<AccessibilityNodeInfo> passwordNodes)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
|
|
|
@ -213,29 +213,49 @@ namespace Bit.App.Pages
|
||||||
AlertNoConnection();
|
AlertNoConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
PasswordCell.InitEvents();
|
PasswordCell?.InitEvents();
|
||||||
UsernameCell.InitEvents();
|
UsernameCell?.InitEvents();
|
||||||
UriCell.InitEvents();
|
UriCell?.InitEvents();
|
||||||
NameCell.InitEvents();
|
NameCell?.InitEvents();
|
||||||
NotesCell.InitEvents();
|
NotesCell?.InitEvents();
|
||||||
FolderCell.InitEvents();
|
FolderCell?.InitEvents();
|
||||||
PasswordCell.Button.Clicked += PasswordButton_Clicked;
|
|
||||||
GenerateCell.Tapped += GenerateCell_Tapped;
|
if(PasswordCell?.Button != null)
|
||||||
DeleteCell.Tapped += DeleteCell_Tapped;
|
{
|
||||||
|
PasswordCell.Button.Clicked += PasswordButton_Clicked;
|
||||||
|
}
|
||||||
|
if(GenerateCell != null)
|
||||||
|
{
|
||||||
|
GenerateCell.Tapped += GenerateCell_Tapped;
|
||||||
|
}
|
||||||
|
if(DeleteCell != null)
|
||||||
|
{
|
||||||
|
DeleteCell.Tapped += DeleteCell_Tapped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
PasswordCell.Dispose();
|
PasswordCell?.Dispose();
|
||||||
UsernameCell.Dispose();
|
UsernameCell?.Dispose();
|
||||||
UriCell.Dispose();
|
UriCell?.Dispose();
|
||||||
NameCell.Dispose();
|
NameCell?.Dispose();
|
||||||
NotesCell.Dispose();
|
NotesCell?.Dispose();
|
||||||
FolderCell.Dispose();
|
FolderCell?.Dispose();
|
||||||
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
|
|
||||||
GenerateCell.Tapped -= GenerateCell_Tapped;
|
if(PasswordCell?.Button != null)
|
||||||
DeleteCell.Tapped -= DeleteCell_Tapped;
|
{
|
||||||
|
PasswordCell.Button.Clicked -= PasswordButton_Clicked;
|
||||||
|
}
|
||||||
|
if(GenerateCell != null)
|
||||||
|
{
|
||||||
|
GenerateCell.Tapped -= GenerateCell_Tapped;
|
||||||
|
}
|
||||||
|
if(DeleteCell != null)
|
||||||
|
{
|
||||||
|
DeleteCell.Tapped -= DeleteCell_Tapped;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PasswordButton_Clicked(object sender, EventArgs e)
|
private void PasswordButton_Clicked(object sender, EventArgs e)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
|
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
|
||||||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||||
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
|
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
|
||||||
<TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
|
||||||
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
|
Loading…
Reference in a new issue