2019-04-30 21:33:00 +03:00
|
|
|
using Android.App;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.OS;
|
|
|
|
using Android.Runtime;
|
|
|
|
using Android.Views;
|
|
|
|
using System;
|
2020-03-26 19:15:33 +03:00
|
|
|
using Bit.Core.Abstractions;
|
|
|
|
using Bit.Core.Utilities;
|
2019-04-30 21:33:00 +03:00
|
|
|
|
|
|
|
namespace Bit.Droid.Accessibility
|
|
|
|
{
|
2019-06-04 16:36:45 +03:00
|
|
|
[Activity(Theme = "@style/LightTheme.Splash", WindowSoftInputMode = SoftInput.StateHidden)]
|
2019-04-30 21:33:00 +03:00
|
|
|
public class AccessibilityActivity : Activity
|
|
|
|
{
|
|
|
|
private DateTime? _lastLaunch = null;
|
|
|
|
private string _lastQueriedUri;
|
|
|
|
|
|
|
|
protected override void OnCreate(Bundle bundle)
|
|
|
|
{
|
|
|
|
base.OnCreate(bundle);
|
2020-03-26 19:15:33 +03:00
|
|
|
HandleIntent(Intent, 932473);
|
2019-04-30 21:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnNewIntent(Intent intent)
|
|
|
|
{
|
|
|
|
base.OnNewIntent(intent);
|
2020-03-26 19:15:33 +03:00
|
|
|
HandleIntent(intent, 489729);
|
2019-04-30 21:33:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
|
|
|
{
|
|
|
|
base.OnDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnResume()
|
|
|
|
{
|
|
|
|
base.OnResume();
|
2020-03-28 16:16:28 +03:00
|
|
|
if (!Intent.HasExtra("uri"))
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
Finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Intent.RemoveExtra("uri");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
|
|
|
|
{
|
|
|
|
base.OnActivityResult(requestCode, resultCode, data);
|
2020-03-28 16:16:28 +03:00
|
|
|
if (data == null)
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
AccessibilityHelpers.LastCredentials = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
if (data.GetStringExtra("canceled") != null)
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
AccessibilityHelpers.LastCredentials = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var uri = data.GetStringExtra("uri");
|
|
|
|
var username = data.GetStringExtra("username");
|
|
|
|
var password = data.GetStringExtra("password");
|
|
|
|
AccessibilityHelpers.LastCredentials = new Credentials
|
|
|
|
{
|
|
|
|
Username = username,
|
|
|
|
Password = password,
|
|
|
|
Uri = uri,
|
|
|
|
LastUri = _lastQueriedUri
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
AccessibilityHelpers.LastCredentials = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
|
2020-03-26 19:15:33 +03:00
|
|
|
private void HandleIntent(Intent callingIntent, int requestCode)
|
|
|
|
{
|
2020-03-28 16:16:28 +03:00
|
|
|
if (callingIntent?.GetBooleanExtra("autofillTileClicked", false) ?? false)
|
2020-03-26 19:15:33 +03:00
|
|
|
{
|
|
|
|
Intent.RemoveExtra("autofillTileClicked");
|
|
|
|
var messagingService = ServiceContainer.Resolve<IMessagingService>("messagingService");
|
|
|
|
messagingService.Send("OnAutofillTileClick");
|
|
|
|
Finish();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LaunchMainActivity(callingIntent, requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 21:33:00 +03:00
|
|
|
private void LaunchMainActivity(Intent callingIntent, int requestCode)
|
|
|
|
{
|
|
|
|
_lastQueriedUri = callingIntent?.GetStringExtra("uri");
|
2020-03-28 16:16:28 +03:00
|
|
|
if (_lastQueriedUri == null)
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
Finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var now = DateTime.UtcNow;
|
2020-03-28 16:16:28 +03:00
|
|
|
if (_lastLaunch.HasValue && (now - _lastLaunch.Value) <= TimeSpan.FromSeconds(2))
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_lastLaunch = now;
|
|
|
|
var intent = new Intent(this, typeof(MainActivity));
|
2020-03-28 16:16:28 +03:00
|
|
|
if (!callingIntent.Flags.HasFlag(ActivityFlags.LaunchedFromHistory))
|
2019-04-30 21:33:00 +03:00
|
|
|
{
|
|
|
|
intent.PutExtra("uri", _lastQueriedUri);
|
|
|
|
}
|
|
|
|
StartActivityForResult(intent, requestCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|