Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-5760] Add autofill support for Spin Browser #2942

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 15 additions & 14 deletions src/Android/Accessibility/AccessibilityHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static class AccessibilityHelpers
new Browser("com.mmbox.browser", "search_box"),
new Browser("com.mmbox.xbrowser", "search_box"),
new Browser("com.mycompany.app.soulbrowser", "edit_text"),
new Browser("com.nationaledtech.spinbrowser", "mozac_browser_toolbar_url_view"),
new Browser("com.naver.whale", "url_bar"),
new Browser("com.neeva.app", "full_url_text_view"),
new Browser("com.opera.browser", "url_field"),
Expand Down Expand Up @@ -528,7 +529,7 @@ public static void FillEditText(AccessibilityNodeInfo editTextNode, string value
return nodes;
}

public static AccessibilityNodeInfo GetUsernameEditText(string uriString,
public static AccessibilityNodeInfo GetUsernameEditText(string uriString,
IEnumerable<AccessibilityNodeInfo> allEditTexts)
{
string uriAuthority = null;
Expand Down Expand Up @@ -621,7 +622,7 @@ public static void FillEditText(AccessibilityNodeInfo editTextNode, string value
// no match found, attempt to establish username field based on password field
return GetUsernameEditTextIfPasswordExists(allEditTexts);
}

private static AccessibilityNodeInfo GetUsernameEditTextIfPasswordExists(
IEnumerable<AccessibilityNodeInfo> allEditTexts)
{
Expand Down Expand Up @@ -670,15 +671,15 @@ public static bool OverlayPermitted()
{
return true;
}

var appOpsMgr = (AppOpsManager)Application.Context.GetSystemService(Context.AppOpsService);
var mode = appOpsMgr.CheckOpNoThrow("android:system_alert_window", Process.MyUid(),
Application.Context.PackageName);
if (mode == AppOpsManagerMode.Allowed || mode == AppOpsManagerMode.Ignored)
{
return true;
}

try
{
var wm = Application.Context.GetSystemService(Context.WindowService)
Expand All @@ -694,10 +695,10 @@ public static bool OverlayPermitted()
return true;
}
catch { }

return false;
}

// older android versions are always true
return true;
}
Expand Down Expand Up @@ -738,15 +739,15 @@ public static WindowManagerLayoutParams GetOverlayLayoutParams()
return layoutParams;
}

public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorView,
public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorView,
int overlayViewHeight, bool isOverlayAboveAnchor)
{
var anchorViewRect = new Rect();
anchorView.GetBoundsInScreen(anchorViewRect);
var anchorViewX = anchorViewRect.Left;
var anchorViewY = isOverlayAboveAnchor ? anchorViewRect.Top : anchorViewRect.Bottom;
anchorViewRect.Dispose();

if (isOverlayAboveAnchor)
{
anchorViewY -= overlayViewHeight;
Expand All @@ -756,8 +757,8 @@ public static WindowManagerLayoutParams GetOverlayLayoutParams()
return new Point(anchorViewX, anchorViewY);
}

public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorNode,
AccessibilityNodeInfo root, IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight,
public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorNode,
AccessibilityNodeInfo root, IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight,
bool isOverlayAboveAnchor)
{
Point point = null;
Expand Down Expand Up @@ -809,7 +810,7 @@ public static WindowManagerLayoutParams GetOverlayLayoutParams()
point.X = -1;
point.Y = -1;
}
}
}
else if (point.Y > (maxY - overlayViewHeight))
{
if (isOverlayAboveAnchor)
Expand All @@ -824,7 +825,7 @@ public static WindowManagerLayoutParams GetOverlayLayoutParams()
point.X = 0;
point.Y = -1;
}
}
}
else if (isOverlayAboveAnchor && point.Y < (maxY - (overlayViewHeight * 2) - GetNodeHeight(anchorNode)))
{
// This else block forces the overlay to return to bottom alignment as soon as space is available
Expand Down Expand Up @@ -873,11 +874,11 @@ public static int GetInputMethodHeight(IEnumerable<AccessibilityWindowInfo> wind
}
return inputMethodWindowHeight;
}

public static bool IsAutofillServicePromptVisible(IEnumerable<AccessibilityWindowInfo> windows)
{
// Autofill framework not available until API 26
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
{
return windows?.Any(w => w.Title?.ToLower().Contains("autofill") ?? false) ?? false;
}
Expand Down
31 changes: 16 additions & 15 deletions src/Android/Autofill/AutofillHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public static class AutofillHelpers
"com.mmbox.browser",
"com.mmbox.xbrowser",
"com.mycompany.app.soulbrowser",
"com.nationaledtech.spinbrowser",
"com.naver.whale",
"com.neeva.app",
"com.opera.browser",
Expand Down Expand Up @@ -119,7 +120,7 @@ public static class AutofillHelpers
"mark.via.gp",
"net.dezor.browser",
"net.slions.fulguris.full.download",
"net.slions.fulguris.full.download.debug",
"net.slions.fulguris.full.download.debug",
"net.slions.fulguris.full.playstore",
"net.slions.fulguris.full.playstore.debug",
"org.adblockplus.browser",
Expand Down Expand Up @@ -190,7 +191,7 @@ public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICip
inlinePresentationSpecs = inlineSuggestionsRequest?.InlinePresentationSpecs;
inlinePresentationSpecsCount = inlinePresentationSpecs?.Count ?? 0;
}

// Build response
var responseBuilder = new FillResponse.Builder();
if (items != null && items.Count > 0)
Expand All @@ -217,7 +218,7 @@ public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICip
inlinePresentationSpec = inlinePresentationSpecs[inlinePresentationSpecsCount - 1];
}
}
var dataset = BuildDataset(parser.ApplicationContext, parser.FieldCollection, items[i],
var dataset = BuildDataset(parser.ApplicationContext, parser.FieldCollection, items[i],
true, inlinePresentationSpec);
if (dataset != null)
{
Expand All @@ -239,13 +240,13 @@ public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICip
filledItem.Subtitle,
filledItem.Icon,
context);

var inlinePresentation = BuildInlinePresentation(
inlinePresentationSpec,
filledItem.Name,
filledItem.Subtitle,
filledItem.Icon,
null,
inlinePresentationSpec,
filledItem.Name,
filledItem.Subtitle,
filledItem.Icon,
null,
context);

var datasetBuilder = new Dataset.Builder(overlayPresentation);
Expand Down Expand Up @@ -301,11 +302,11 @@ public static async Task<List<FilledItem>> GetFillItemsAsync(Parser parser, ICip
context);

var inlinePresentation = BuildInlinePresentation(
inlinePresentationSpecs?.Last(),
AppResources.Bitwarden,
locked ? AppResources.VaultIsLocked : AppResources.MyVault,
Resource.Drawable.icon,
pendingIntent,
inlinePresentationSpecs?.Last(),
AppResources.Bitwarden,
locked ? AppResources.VaultIsLocked : AppResources.MyVault,
Resource.Drawable.icon,
pendingIntent,
context);

var datasetBuilder = new Dataset.Builder(overlayPresentation);
Expand Down Expand Up @@ -402,7 +403,7 @@ public static RemoteViews BuildOverlayPresentation(string text, string subtext,
return contentBuilder.Build().JavaCast<InlineSuggestionUi.Content>()?.Slice;
}

public static void AddSaveInfo(Parser parser, FillRequest fillRequest, FillResponse.Builder responseBuilder,
public static void AddSaveInfo(Parser parser, FillRequest fillRequest, FillResponse.Builder responseBuilder,
FieldCollection fields)
{
// Docs state that password fields cannot be reliably saved in Compat mode since they will show as
Expand Down
3 changes: 3 additions & 0 deletions src/Android/Resources/xml/autofillservice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<compatibility-package
android:name="com.mycompany.app.soulbrowser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.nationaledtech.spinbrowser"
android:maxLongVersionCode="10000000000"/>
<compatibility-package
android:name="com.naver.whale"
android:maxLongVersionCode="10000000000"/>
Expand Down