mirror of
https://github.com/bitwarden/mobile
synced 2025-02-08 07:58:54 +01:00
Added support for Yandex browser. Turned push sevrice back on
This commit is contained in:
parent
f6ca9b9d0f
commit
5bce95a686
@ -20,35 +20,36 @@ namespace Bit.Android
|
|||||||
private const string BitwardenWebsite = "bitwarden.com";
|
private const string BitwardenWebsite = "bitwarden.com";
|
||||||
|
|
||||||
public static bool Enabled { get; set; } = false;
|
public static bool Enabled { get; set; } = false;
|
||||||
private static Dictionary<string, string[]> BrowserPackages => new Dictionary<string, string[]>
|
private static Dictionary<string, Browser> SupportedBrowsers => new List<Browser>
|
||||||
{
|
{
|
||||||
{ "com.android.chrome", new string[] { "url_bar" } },
|
new Browser("com.android.chrome", "url_bar"),
|
||||||
{ "com.chrome.beta", new string[] { "url_bar" } },
|
new Browser("com.chrome.beta", "url_bar"),
|
||||||
{ "com.android.browser", new string[] { "url" } },
|
new Browser("com.android.browser", "url"),
|
||||||
{ "com.brave.browser", new string[] { "url_bar" } },
|
new Browser("com.brave.browser", "url_bar"),
|
||||||
{ "com.opera.browser", new string[] { "url_field" } },
|
new Browser("com.opera.browser", "url_field"),
|
||||||
{ "com.opera.browser.beta", new string[] { "url_field" } },
|
new Browser("com.opera.browser.beta", "url_field"),
|
||||||
{ "com.opera.mini.native", new string[] { "url_field" } },
|
new Browser("com.opera.mini.native", "url_field"),
|
||||||
{ "com.chrome.dev", new string[] { "url_bar" } },
|
new Browser("com.chrome.dev", "url_bar"),
|
||||||
{ "com.chrome.canary", new string[] { "url_bar" } },
|
new Browser("com.chrome.canary", "url_bar"),
|
||||||
{ "com.google.android.apps.chrome", new string[] { "url_bar" } },
|
new Browser("com.google.android.apps.chrome", "url_bar"),
|
||||||
{ "com.google.android.apps.chrome_dev", new string[] { "url_bar" } },
|
new Browser("com.google.android.apps.chrome_dev", "url_bar"),
|
||||||
{ "org.iron.srware", new string[] { "url_bar" } },
|
new Browser("org.iron.srware", "url_bar"),
|
||||||
{ "com.sec.android.app.sbrowser", new string[] { "sbrowser_url_bar" } },
|
new Browser("com.sec.android.app.sbrowser", "sbrowser_url_bar"),
|
||||||
{ "com.yandex.browser", new string[] { "bro_common_omnibox_host", "bro_common_omnibox_edit_text" } },
|
new Browser("com.yandex.browser", "bro_omnibar_address_title_text",
|
||||||
{ "org.mozilla.firefox", new string[] { "url_bar_title" } },
|
(s) => s.Split(' ').FirstOrDefault()),
|
||||||
{ "org.mozilla.firefox_beta", new string[] { "url_bar_title" } },
|
new Browser("org.mozilla.firefox", "url_bar_title"),
|
||||||
{ "com.ghostery.android.ghostery",new string[] { "search_field" } },
|
new Browser("org.mozilla.firefox_beta", "url_bar_title"),
|
||||||
{ "org.adblockplus.browser", new string[] { "url_bar_title" } },
|
new Browser("com.ghostery.android.ghostery", "search_field"),
|
||||||
{ "com.htc.sense.browser", new string[] { "title" } },
|
new Browser("org.adblockplus.browser", "url_bar_title"),
|
||||||
{ "com.amazon.cloud9", new string[] { "url" } },
|
new Browser("com.htc.sense.browser", "title"),
|
||||||
{ "mobi.mgeek.TunnyBrowser", new string[] { "title" } },
|
new Browser("com.amazon.cloud9", "url"),
|
||||||
{ "com.nubelacorp.javelin", new string[] { "enterUrl" } },
|
new Browser("mobi.mgeek.TunnyBrowser", "title"),
|
||||||
{ "com.jerky.browser2", new string[] { "enterUrl" } },
|
new Browser("com.nubelacorp.javelin", "enterUrl"),
|
||||||
{ "com.mx.browser", new string[] { "address_editor_with_progress" } },
|
new Browser("com.jerky.browser2", "enterUrl"),
|
||||||
{ "com.mx.browser.tablet", new string[] { "address_editor_with_progress"} },
|
new Browser("com.mx.browser", "address_editor_with_progress"),
|
||||||
{ "com.linkbubble.playstore", new string[] { "url_text" }}
|
new Browser("com.mx.browser.tablet", "address_editor_with_progress"),
|
||||||
};
|
new Browser("com.linkbubble.playstore", "url_text")
|
||||||
|
}.ToDictionary(n => n.PackageName);
|
||||||
|
|
||||||
public override void OnAccessibilityEvent(AccessibilityEvent e)
|
public override void OnAccessibilityEvent(AccessibilityEvent e)
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ namespace Bit.Android
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(e.EventType)
|
switch(e.EventType)
|
||||||
{
|
{
|
||||||
case EventTypes.WindowContentChanged:
|
case EventTypes.WindowContentChanged:
|
||||||
@ -76,21 +77,24 @@ namespace Bit.Android
|
|||||||
if(passwordNodes.Any())
|
if(passwordNodes.Any())
|
||||||
{
|
{
|
||||||
var uri = GetUri(root);
|
var uri = GetUri(root);
|
||||||
if(uri.Contains(BitwardenWebsite))
|
if(uri != null)
|
||||||
{
|
{
|
||||||
break;
|
if(uri.Contains(BitwardenWebsite))
|
||||||
}
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
|
if(NeedToAutofill(AutofillActivity.LastCredentials, uri))
|
||||||
{
|
{
|
||||||
var allEditTexts = GetWindowNodes(root, e, n => EditText(n));
|
var allEditTexts = GetWindowNodes(root, e, n => EditText(n));
|
||||||
var usernameEditText = allEditTexts.TakeWhile(n => !n.Password).LastOrDefault();
|
var usernameEditText = allEditTexts.TakeWhile(n => !n.Password).LastOrDefault();
|
||||||
FillCredentials(usernameEditText, passwordNodes);
|
FillCredentials(usernameEditText, passwordNodes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NotifyToAutofill(uri);
|
NotifyToAutofill(uri);
|
||||||
cancelNotification = false;
|
cancelNotification = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutofillActivity.LastCredentials = null;
|
AutofillActivity.LastCredentials = null;
|
||||||
@ -132,43 +136,40 @@ namespace Bit.Android
|
|||||||
private string GetUri(AccessibilityNodeInfo root)
|
private string GetUri(AccessibilityNodeInfo root)
|
||||||
{
|
{
|
||||||
var uri = string.Concat(App.Constants.AndroidAppProtocol, root.PackageName);
|
var uri = string.Concat(App.Constants.AndroidAppProtocol, root.PackageName);
|
||||||
if(BrowserPackages.ContainsKey(root.PackageName))
|
if(SupportedBrowsers.ContainsKey(root.PackageName))
|
||||||
{
|
{
|
||||||
foreach(var addressViewId in BrowserPackages[root.PackageName])
|
var addressNode = root.FindAccessibilityNodeInfosByViewId(
|
||||||
|
$"{root.PackageName}:id/{SupportedBrowsers[root.PackageName].UriViewId}").FirstOrDefault();
|
||||||
|
if(addressNode != null)
|
||||||
{
|
{
|
||||||
var addressNode = root.FindAccessibilityNodeInfosByViewId(
|
uri = ExtractUri(uri, addressNode, SupportedBrowsers[root.PackageName]);
|
||||||
$"{root.PackageName}:id/{addressViewId}").FirstOrDefault();
|
|
||||||
if(addressNode == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uri = ExtractUri(uri, addressNode);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ExtractUri(string uri, AccessibilityNodeInfo addressNode)
|
private string ExtractUri(string uri, AccessibilityNodeInfo addressNode, Browser browser)
|
||||||
{
|
{
|
||||||
if(addressNode?.Text != null)
|
if(addressNode?.Text != null)
|
||||||
{
|
{
|
||||||
uri = addressNode.Text;
|
uri = browser.GetUriFunction(addressNode.Text);
|
||||||
if(!uri.Contains("://"))
|
if(uri != null && uri.Contains("."))
|
||||||
{
|
{
|
||||||
uri = string.Concat("http://", uri);
|
if(!uri.Contains("://"))
|
||||||
}
|
|
||||||
else if(Build.VERSION.SdkInt <= BuildVersionCodes.KitkatWatch)
|
|
||||||
{
|
|
||||||
var parts = uri.Split(new string[] { ". " }, StringSplitOptions.None);
|
|
||||||
if(parts.Length > 1)
|
|
||||||
{
|
{
|
||||||
var urlPart = parts.FirstOrDefault(p => p.StartsWith("http"));
|
uri = string.Concat("http://", uri);
|
||||||
if(urlPart != null)
|
}
|
||||||
|
else if(Build.VERSION.SdkInt <= BuildVersionCodes.KitkatWatch)
|
||||||
|
{
|
||||||
|
var parts = uri.Split(new string[] { ". " }, StringSplitOptions.None);
|
||||||
|
if(parts.Length > 1)
|
||||||
{
|
{
|
||||||
uri = urlPart.Trim();
|
var urlPart = parts.FirstOrDefault(p => p.StartsWith("http"));
|
||||||
|
if(urlPart != null)
|
||||||
|
{
|
||||||
|
uri = urlPart.Trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,5 +270,24 @@ namespace Bit.Android
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Browser
|
||||||
|
{
|
||||||
|
public Browser(string packageName, string uriViewId)
|
||||||
|
{
|
||||||
|
PackageName = packageName;
|
||||||
|
UriViewId = uriViewId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Browser(string packageName, string uriViewId, Func<string, string> getUriFunction)
|
||||||
|
: this(packageName, uriViewId)
|
||||||
|
{
|
||||||
|
GetUriFunction = getUriFunction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string PackageName { get; set; }
|
||||||
|
public string UriViewId { get; set; }
|
||||||
|
public Func<string, string> GetUriFunction { get; set; } = (s) => s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,8 @@ namespace Bit.Android
|
|||||||
|
|
||||||
RegisterActivityLifecycleCallbacks(this);
|
RegisterActivityLifecycleCallbacks(this);
|
||||||
AppContext = ApplicationContext;
|
AppContext = ApplicationContext;
|
||||||
//StartPushService();
|
StartPushService();
|
||||||
//HandlePushReregistration();
|
HandlePushReregistration();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandlePushReregistration()
|
private void HandlePushReregistration()
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
android:description="@string/AutoFillServiceDescription"
|
android:description="@string/AutoFillServiceDescription"
|
||||||
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
|
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
|
||||||
android:accessibilityFeedbackType="feedbackGeneric"
|
android:accessibilityFeedbackType="feedbackGeneric"
|
||||||
android:accessibilityFlags="flagDefault"
|
android:accessibilityFlags="flagReportViewIds"
|
||||||
android:notificationTimeout="100"
|
android:notificationTimeout="100"
|
||||||
android:canRetrieveWindowContent="true"/>
|
android:canRetrieveWindowContent="true"/>
|
Loading…
x
Reference in New Issue
Block a user