/**
         * Traverse AssistStructure and add ViewNode metadata to a flat list.
         */
        private void Parse(bool forFill)
        {
            _filledAutofillFieldCollection = new FilledAutofillFieldCollection();

            for (var i = 0; i < _structure.WindowNodeCount; i++)
            {
                var node = _structure.GetWindowNodeAt(i);
                var view = node.RootViewNode;
                ParseLocked(forFill, view);
            }
        }
Beispiel #2
0
        public static void DumpStructure(AssistStructure structure)
        {
            int nodeCount = structure.WindowNodeCount;

            Log.Verbose(TAG, "dumpStructure(): component=" + structure.ActivityComponent
                        + " numberNodes=" + nodeCount);
            for (int i = 0; i < nodeCount; i++)
            {
                Log.Verbose(TAG, "node #" + i);
                AssistStructure.WindowNode node = structure.GetWindowNodeAt(i);
                DumpNode("  ", node.RootViewNode);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Traverse AssistStructure and add ViewNode metadata to a flat list.
        /// </summary>
        /// <returns>The parse.</returns>
        /// <param name="forFill">If set to <c>true</c> for fill.</param>
        void Parse(bool forFill)
        {
            Log.Debug(CommonUtil.Tag, "Parsing structure for " + Structure.ActivityComponent);
            var nodes = Structure.WindowNodeCount;

            ClientFormData = new FilledAutofillFieldCollection();
            for (int i = 0; i < nodes; i++)
            {
                var node = Structure.GetWindowNodeAt(i);
                var view = node.RootViewNode;
                ParseLocked(forFill, view);
            }
        }
 public static void DumpStructure(AssistStructure structure)
 {
     if (LogVerboseEnabled())
     {
         int nodeCount = structure.WindowNodeCount;
         Logv("dumpStructure(): component=%s numberNodes=%d",
              structure.ActivityComponent, nodeCount);
         for (int i = 0; i < nodeCount; i++)
         {
             Logv("node #%d", i);
             var node = structure.GetWindowNodeAt(i);
             DumpNode(new StringBuilder(), "  ", node.RootViewNode, 0);
         }
     }
 }
        /**
         * Gets a node if it matches the filter criteria for the given id.
         */
        public static AssistStructure.ViewNode FindNodeByFilter([NonNull] AssistStructure structure, [NonNull] object id, [NonNull] NodeFilter filter)
        {
            Logv("Parsing request for activity %s", structure.ActivityComponent);
            int nodes = structure.WindowNodeCount;

            for (int i = 0; i < nodes; i++)
            {
                AssistStructure.WindowNode windowNode = structure.GetWindowNodeAt(i);
                AssistStructure.ViewNode   rootNode   = windowNode.RootViewNode;
                AssistStructure.ViewNode   node       = FindNodeByFilter(rootNode, id, filter);
                if (node != null)
                {
                    return(node);
                }
            }
            return(null);
        }
        /**
         * Traverse AssistStructure and add ViewNode metadata to a flat list.
         */
        private void Parse(bool forFill)
        {
            if (CommonUtil.DEBUG)
            {
                Log.Debug(CommonUtil.TAG, "Parsing structure for " + mStructure.ActivityComponent);
            }
            int nodes = mStructure.WindowNodeCount;

            mFilledAutofillFieldCollection = new FilledAutofillFieldCollection();
            var webDomain = new StringBuilder();

            for (int i = 0; i < nodes; i++)
            {
                var node = mStructure.GetWindowNodeAt(i);
                var view = node.RootViewNode;
                ParseLocked(forFill, view, webDomain);
            }

            if (webDomain.Length() > 0)
            {
                var packageName = mStructure.ActivityComponent.PackageName;
                var valid       = SharedPrefsDigitalAssetLinksRepository.GetInstance()
                                  .IsValid(mContext, webDomain.ToString(), packageName);
                if (!valid)
                {
                    throw new SecurityException(mContext.GetString(Resource.String.invalid_link_association, webDomain,
                                                                   packageName));
                }

                if (CommonUtil.DEBUG)
                {
                    Log.Debug(CommonUtil.TAG, "Domain " + webDomain + " is valid for " + packageName);
                }
            }
            else
            {
                if (CommonUtil.DEBUG)
                {
                    Log.Debug(CommonUtil.TAG, "no web domain");
                }
            }
        }
        /// <summary>
        /// Traverse AssistStructure and add ViewNode metadata to a flat list.
        /// </summary>
        /// <returns>The parse.</returns>
        /// <param name="forFill">If set to <c>true</c> for fill.</param>
        /// <param name="isManualRequest"></param>
        string Parse(bool forFill, bool isManualRequest)
        {
            Log.Debug(CommonUtil.Tag, "Parsing structure for " + Structure.ActivityComponent);
            var nodes = Structure.WindowNodeCount;

            ClientFormData = new FilledAutofillFieldCollection();
            String webDomain = null;

            _editTextsWithoutHint.Clear();

            for (int i = 0; i < nodes; i++)
            {
                var node = Structure.GetWindowNodeAt(i);
                var view = node.RootViewNode;
                ParseLocked(forFill, isManualRequest, view, ref webDomain);
            }



            if (AutofillFields.Empty)
            {
                var passwordFields = _editTextsWithoutHint
                                     .Where(IsPassword).ToList();
                if (!passwordFields.Any())
                {
                    passwordFields = _editTextsWithoutHint.Where(HasPasswordHint).ToList();
                }
                foreach (var passwordField in passwordFields)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(passwordField, new[] { View.AutofillHintPassword }));
                    var usernameField = _editTextsWithoutHint.TakeWhile(f => f.AutofillId != passwordField.AutofillId).LastOrDefault();
                    if (usernameField != null)
                    {
                        AutofillFields.Add(new AutofillFieldMetadata(usernameField, new[] { View.AutofillHintUsername }));
                    }
                }
                //for some pages with two-step login, we don't see a password field and don't display the autofill for non-manual requests. But if the user forces autofill,
                //let's assume it is a username field:
                if (isManualRequest && !passwordFields.Any() && _editTextsWithoutHint.Count == 1)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(_editTextsWithoutHint.First(), new[] { View.AutofillHintUsername }));
                }
            }

            //force focused fields to be included in autofill fields when request was triggered manually. This allows to fill fields which are "off" or don't have a hint (in case there are hints)
            if (isManualRequest)
            {
                foreach (AssistStructure.ViewNode editText in _editTextsWithoutHint)
                {
                    if (editText.IsFocused)
                    {
                        AutofillFields.Add(new AutofillFieldMetadata(editText, new[] { IsPassword(editText) || HasPasswordHint(editText) ? View.AutofillHintPassword : View.AutofillHintUsername }));
                        break;
                    }
                }
            }



            String packageName = Structure.ActivityComponent.PackageName;

            if (!string.IsNullOrEmpty(webDomain))
            {
                bool valid = Kp2aDigitalAssetLinksDataSource.Instance.IsValid(mContext, webDomain, packageName);
                if (!valid)
                {
                    CommonUtil.loge($"DAL verification failed for {packageName}/{webDomain}");
                    webDomain = null;
                }
            }
            if (string.IsNullOrEmpty(webDomain))
            {
                webDomain = "androidapp://" + packageName;
                Log.Debug(CommonUtil.Tag, "no web domain. Using package name.");
            }
            return(webDomain);
        }
Beispiel #8
0
        /// <summary>
        /// Traverse AssistStructure and add ViewNode metadata to a flat list.
        /// </summary>
        /// <returns>The parse.</returns>
        /// <param name="forFill">If set to <c>true</c> for fill.</param>
        /// <param name="isManualRequest"></param>
        AutofillTargetId Parse(bool forFill, bool isManualRequest)
        {
            AutofillTargetId result = new AutofillTargetId();

            CommonUtil.logd("Parsing structure for " + Structure.ActivityComponent);
            var nodes = Structure.WindowNodeCount;

            ClientFormData = new FilledAutofillFieldCollection();
            String webDomain = null;

            _editTextsWithoutHint.Clear();

            for (int i = 0; i < nodes; i++)
            {
                var node = Structure.GetWindowNodeAt(i);

                var view = node.RootViewNode;
                ParseLocked(forFill, isManualRequest, view, ref webDomain);
            }



            List <AssistStructure.ViewNode> passwordFields = new List <AssistStructure.ViewNode>();
            List <AssistStructure.ViewNode> usernameFields = new List <AssistStructure.ViewNode>();

            if (AutofillFields.Empty)
            {
                passwordFields = _editTextsWithoutHint.Where(IsPassword).ToList();
                if (!passwordFields.Any())
                {
                    passwordFields = _editTextsWithoutHint.Where(HasPasswordHint).ToList();
                }

                usernameFields = _editTextsWithoutHint.Where(HasUsernameHint).ToList();

                if (usernameFields.Any() == false)
                {
                    foreach (var passwordField in passwordFields)
                    {
                        var usernameField = _editTextsWithoutHint
                                            .TakeWhile(f => f.AutofillId != passwordField.AutofillId).LastOrDefault();
                        if (usernameField != null)
                        {
                            usernameFields.Add(usernameField);
                        }
                    }
                }
                if (usernameFields.Any() == false)
                {
                    //for some pages with two-step login, we don't see a password field and don't display the autofill for non-manual requests. But if the user forces autofill,
                    //let's assume it is a username field:
                    if (isManualRequest && !passwordFields.Any() && _editTextsWithoutHint.Count == 1)
                    {
                        usernameFields.Add(_editTextsWithoutHint.First());
                    }
                }
            }

            //force focused fields to be included in autofill fields when request was triggered manually. This allows to fill fields which are "off" or don't have a hint (in case there are hints)
            if (isManualRequest)
            {
                foreach (AssistStructure.ViewNode editText in _editTextsWithoutHint)
                {
                    if (editText.IsFocused)
                    {
                        if (IsPassword(editText) || HasPasswordHint(editText))
                        {
                            passwordFields.Add(editText);
                        }
                        else
                        {
                            usernameFields.Add(editText);
                        }
                        break;
                    }
                }
            }

            if (forFill)
            {
                foreach (var uf in usernameFields)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(uf, new[] { View.AutofillHintUsername }));
                }
                foreach (var pf in passwordFields)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(pf, new[] { View.AutofillHintPassword }));
                }
            }
            else
            {
                foreach (var uf in usernameFields)
                {
                    ClientFormData.Add(new FilledAutofillField(uf, new[] { View.AutofillHintUsername }));
                }
                foreach (var pf in passwordFields)
                {
                    ClientFormData.Add(new FilledAutofillField(pf, new[] { View.AutofillHintPassword }));
                }
            }


            result.WebDomain   = webDomain;
            result.PackageName = Structure.ActivityComponent.PackageName;
            if (!string.IsNullOrEmpty(webDomain))
            {
                result.IncompatiblePackageAndDomain = !kp2aDigitalAssetLinksDataSource.IsTrustedLink(webDomain, result.PackageName);
                if (result.IncompatiblePackageAndDomain)
                {
                    CommonUtil.loge($"DAL verification failed for {result.PackageName}/{result.WebDomain}");
                }
            }
            else
            {
                result.IncompatiblePackageAndDomain = false;
            }
            return(result);
        }