コード例 #1
0
        private void OnFieldSelected(FilledAutofillField field, FieldType fieldType)
        {
            DatasetWithFilledAutofillFields datasetWithFilledAutofillFields = new DatasetWithFilledAutofillFields();
            String newDatasetId             = Guid.NewGuid().ToString();
            FilledAutofillField copyOfField = new FilledAutofillField(newDatasetId, PackageName,
                                                                      field.GetFieldTypeName(), field.GetTextValue(), field.GetDateValue(), field.GetToggleValue());
            String          datasetName     = "dataset-manual";
            AutofillDataset autofillDataset = new AutofillDataset(newDatasetId, datasetName);

            datasetWithFilledAutofillFields.filledAutofillFields =
                new List <FilledAutofillField>()
            {
                copyOfField
            }.ToImmutableList();
            datasetWithFilledAutofillFields.autofillDataset = autofillDataset;
            Intent       intent       = Intent;
            var          structure    = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            ClientParser clientParser = new ClientParser(structure);

            mReplyIntent = new Intent();
            mLocalAutofillDataSource.GetFieldTypeByAutofillHints(new DataCallback2
            {
                that         = this,
                datasetName  = datasetName,
                fieldType    = fieldType,
                field        = field,
                clientParser = clientParser
            });
        }
コード例 #2
0
        private void ParseAutofillFields(AssistStructure.ViewNode viewNode,
                                         Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
                                         Dictionary <string, FilledAutofillField> filledAutofillFieldsByTypeName,
                                         Dataset.Builder builder, MutableBoolean setValueAtLeastOnce)
        {
            var rawHints = viewNode.GetAutofillHints();

            if (rawHints == null || rawHints.Length == 0)
            {
                Util.Logv("No af hints at ViewNode - %s", viewNode.IdEntry);
                return;
            }
            string fieldTypeName = AutofillHints.GetFieldTypeNameFromAutofillHints(
                fieldTypesByAutofillHint, rawHints.ToList());

            if (fieldTypeName == null)
            {
                return;
            }
            FilledAutofillField field = filledAutofillFieldsByTypeName[fieldTypeName];

            if (field == null)
            {
                return;
            }
            BindValueToNode(viewNode, field, builder, setValueAtLeastOnce);
        }
コード例 #3
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);

                filledAutofillField.SetTextValue(string.Format(Text, seed));
                return(filledAutofillField);
            }
コード例 #4
0
        public static FilledAutofillFieldCollection GetFilledAutofillFieldCollectionFromEntry(PwEntryOutput pwEntryOutput, Context context)
        {
            if (pwEntryOutput == null)
            {
                return(null);
            }
            FilledAutofillFieldCollection fieldCollection = new FilledAutofillFieldCollection();
            var pwEntry = pwEntryOutput.Entry;

            foreach (string key in pwEntryOutput.OutputStrings.GetKeys())
            {
                FilledAutofillField field =
                    new FilledAutofillField
                {
                    AutofillHints = GetCanonicalHintsFromKp2aField(key).ToArray(),
                    TextValue     = pwEntryOutput.OutputStrings.ReadSafe(key)
                };
                fieldCollection.Add(field);
            }
            if (IsCreditCard(pwEntry, context) && pwEntry.Expires)
            {
                DateTime            expTime = pwEntry.ExpiryTime;
                FilledAutofillField field   =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationDate },
                    DateValue     = (long)(1000 * TimeUtil.SerializeUnix(expTime))
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationDay },
                    TextValue     = expTime.Day.ToString()
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationMonth },
                    TextValue     = expTime.Month.ToString()
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationYear },
                    TextValue     = expTime.Year.ToString()
                };
                fieldCollection.Add(field);
            }


            fieldCollection.DatasetName = pwEntry.Strings.ReadSafe(PwDefs.TitleField);

            return(fieldCollection);
        }
コード例 #5
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);

                filledAutofillField.SetTextValue((seed % Number).ToString());
                return(filledAutofillField);
            }
コード例 #6
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);

                filledAutofillField.SetListValue(Array, seed % Array.Length);
                return(filledAutofillField);
            }
コード例 #7
0
 public void Bind(FilledAutofillField field)
 {
     mFieldTypeText.Text = field.GetFieldTypeName();
     mRootView.Click    += delegate
     {
         ((ManualFieldPickerActivity)mActivity).OnSelectedDataset(field);
     };
 }
コード例 #8
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);
                int year = Instance.Get(Year) - seed * 10;

                filledAutofillField.SetTextValue("" + year);
                return(filledAutofillField);
            }
コード例 #9
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);
                var calendar            = Instance;

                calendar.Set(Year, calendar.Get(Year) + seed);
                filledAutofillField.SetDateValue(calendar.TimeInMillis);
                return(filledAutofillField);
            }
コード例 #10
0
        public void OnSelectedDataset(FilledAutofillField field)
        {
            Intent data = new Intent()
                          .PutExtra(EXTRA_SELECTED_FIELD_DATASET_ID, field.GetDatasetId())
                          .PutExtra(EXTRA_SELECTED_FIELD_TYPE_NAME, field.GetFieldTypeName());

            SetResult(Result.Ok, data);
            Finish();
        }
コード例 #11
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);
                var calendar            = Android.Icu.Util.Calendar.Instance;

                calendar.Set(Year, calendar.Get(Year) - seed * 10);
                calendar.Set(Month, seed % 12);
                calendar.Set(Date, seed % 27);
                filledAutofillField.SetDateValue(calendar.TimeInMillis);
                return(filledAutofillField);
            }
コード例 #12
0
            public FilledAutofillField Generate(int seed)
            {
                FilledAutofillField filledAutofillField = new FilledAutofillField(Type);
                var calendar = Instance;
                int expYear  = calendar.Get(Year) + seed;

                calendar.Set(Year, expYear);
                filledAutofillField.SetDateValue(calendar.TimeInMillis);
                filledAutofillField.SetTextValue(expYear.ToString());
                return(filledAutofillField);
            }
コード例 #13
0
        public Dataset BuildDatasetForFocusedNode(FilledAutofillField filledAutofillField, FieldType fieldType,
                                                  RemoteViews remoteViews)
        {
            Dataset.Builder datasetBuilder     = new Dataset.Builder(remoteViews);
            bool            setAtLeastOneValue = BindDatasetToFocusedNode(filledAutofillField, fieldType, datasetBuilder);

            if (!setAtLeastOneValue)
            {
                return(null);
            }
            return(datasetBuilder.Build());
        }
コード例 #14
0
            public FilledAutofillField Generate(int seed)
            {
                var days = DayRange();
                int day  = seed % days.Length;
                var filledAutofillField = new FilledAutofillField(Type);
                var calendar            = Instance;

                calendar.Set(Date, day);
                filledAutofillField.SetListValue(days, day);
                filledAutofillField.SetTextValue(day.ToString());
                filledAutofillField.SetDateValue(calendar.TimeInMillis);
                return(filledAutofillField);
            }
コード例 #15
0
        private bool BindDatasetToFocusedNode(FilledAutofillField field, FieldType fieldType, Dataset.Builder builder)
        {
            MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);

            mClientParser.Parse(new BindDatasetToFocusedNodeProcessor()
            {
                field               = field,
                builder             = builder,
                datasetAdapter      = this,
                setValueAtLeastOnce = setValueAtLeastOnce
            });
            return(setValueAtLeastOnce.Value);
        }
コード例 #16
0
        public FillResponse BuildResponseForFocusedNode(string datasetName, FilledAutofillField field, FieldType fieldType)
        {
            FillResponse.Builder responseBuilder = new FillResponse.Builder();
            RemoteViews          remoteViews     = RemoteViewsHelper.ViewsWithNoAuth(
                mPackageName, datasetName);
            Dataset dataset = mDatasetAdapter.BuildDatasetForFocusedNode(field, fieldType, remoteViews);

            if (dataset != null)
            {
                responseBuilder.AddDataset(dataset);
                return(responseBuilder.Build());
            }
            return(null);
        }
コード例 #17
0
            public FilledAutofillField Generate(int seed)
            {
                var months   = MonthRange();
                int month    = seed % months.Length;
                var calendar = Instance;

                calendar.Set(Month, month);
                var filledAutofillField = new FilledAutofillField(Type);

                filledAutofillField.SetListValue(months, month);
                filledAutofillField.SetTextValue(month.ToString());
                filledAutofillField.SetDateValue(calendar.TimeInMillis);
                return(filledAutofillField);
            }
コード例 #18
0
        void BindValueToNode(AssistStructure.ViewNode viewNode,
                             FilledAutofillField field, Dataset.Builder builder,
                             MutableBoolean setValueAtLeastOnce)
        {
            AutofillId autofillId = viewNode.AutofillId;

            if (autofillId == null)
            {
                Util.Logw("Autofill ID null for %s", viewNode.ToString());
                return;
            }
            int autofillType = (int)viewNode.AutofillType;

            switch (autofillType)
            {
            case (int)AutofillType.List:
                var options   = viewNode.GetAutofillOptions();
                int listValue = -1;
                if (options != null)
                {
                    listValue = Util.IndexOf(viewNode.GetAutofillOptions(), field.GetTextValue());
                }
                if (listValue != -1)
                {
                    builder.SetValue(autofillId, AutofillValue.ForList(listValue));
                    setValueAtLeastOnce.Value = true;
                }
                break;

            case (int)AutofillType.Date:
                var dateValue = field.GetDateValue();
                if (dateValue != null)
                {
                    builder.SetValue(autofillId, AutofillValue.ForDate(dateValue));
                    setValueAtLeastOnce.Value = true;
                }
                break;

            case (int)AutofillType.Text:
                string textValue = field.GetTextValue();
                if (textValue != null)
                {
                    builder.SetValue(autofillId, AutofillValue.ForText(textValue));
                    setValueAtLeastOnce.Value = true;
                }
                break;

            case (int)AutofillType.Toggle:
                var toggleValue = field.GetToggleValue();
                if (toggleValue != null)
                {
                    builder.SetValue(autofillId, AutofillValue.ForToggle(toggleValue));
                    setValueAtLeastOnce.Value = true;
                }
                break;

            case (int)AutofillType.None:
                break;

            default:
                Util.Logw("Invalid autofill type - %d", autofillType);
                break;
            }
        }
コード例 #19
0
            public FilledAutofillField Generate(int seed)
            {
                var filledAutofillField = new FilledAutofillField(Type);

                return(filledAutofillField);
            }
コード例 #20
0
        void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain)
        {
            String webDomain = viewNode.WebDomain;

            if ((PackageId == null) && (!string.IsNullOrWhiteSpace(viewNode.IdPackage)) &&
                (viewNode.IdPackage != "android"))
            {
                PackageId = viewNode.IdPackage;
            }

            DomainName outDomain;

            if (DomainName.TryParse(webDomain, domainSuffixParserCache, out outDomain))
            {
                webDomain = outDomain.RawDomainName;
            }

            if (webDomain != null)
            {
                if (!string.IsNullOrEmpty(validWebdomain))
                {
                    if (webDomain != validWebdomain)
                    {
                        throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}");
                    }
                }
                else
                {
                    validWebdomain = webDomain;
                }
            }

            string[] viewHints = viewNode.GetAutofillHints();
            if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused &&
                isManualRequest)
            {
                viewHints[0] = "on";
            }

            /*if (viewHints != null && viewHints.Any())
             * {
             *  CommonUtil.logd("viewHints=" + viewHints);
             *  CommonUtil.logd("class=" + viewNode.ClassName);
             *  CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)"));
             * }*/


            if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/)
            {
                if (forFill)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(viewNode));
                }
                else
                {
                    FilledAutofillField filledAutofillField = new FilledAutofillField(viewNode);
                    ClientFormData.Add(filledAutofillField);
                }
            }
            else
            {
                if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input")
                {
                    _editTextsWithoutHint.Add(viewNode);
                }
            }
            var childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain);
                }
            }
        }
コード例 #21
0
        private void ParseLocked(bool forFill, AssistStructure.ViewNode viewNode, StringBuilder validWebDomain)
        {
            var webDomain = viewNode.WebDomain;

            if (webDomain != null)
            {
                if (CommonUtil.DEBUG)
                {
                    Log.Debug(CommonUtil.TAG, "child web domain: " + webDomain);
                }
                if (validWebDomain.Length() > 0)
                {
                    if (webDomain != validWebDomain.ToString())
                    {
                        throw new SecurityException("Found multiple web domains: valid= "
                                                    + validWebDomain + ", child=" + webDomain);
                    }
                }
                else
                {
                    validWebDomain.Append(webDomain);
                }
            }

            if (viewNode.GetAutofillHints() != null)
            {
                var filteredHints = AutofillHints.FilterForSupportedHints(
                    viewNode.GetAutofillHints());
                if (filteredHints != null && filteredHints.Length > 0)
                {
                    if (forFill)
                    {
                        mAutofillFields.Add(new AutofillFieldMetadata(viewNode));
                    }
                    else
                    {
                        var           filledAutofillField = new FilledAutofillField(viewNode.GetAutofillHints());
                        AutofillValue autofillValue       = viewNode.AutofillValue;
                        if (autofillValue.IsText)
                        {
                            // Using toString of AutofillValue.getTextValue in order to save it to
                            // SharedPreferences.
                            filledAutofillField.SetTextValue(autofillValue.TextValue);
                        }
                        else if (autofillValue.IsDate)
                        {
                            filledAutofillField.SetDateValue(autofillValue.DateValue);
                        }
                        else if (autofillValue.IsList)
                        {
                            filledAutofillField.SetListValue(viewNode.GetAutofillOptions(),
                                                             autofillValue.ListValue);
                        }

                        mFilledAutofillFieldCollection.Add(filledAutofillField);
                    }
                }
            }

            int childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, viewNode.GetChildAt(i), validWebDomain);
                }
            }
        }
コード例 #22
0
        void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain)
        {
            String webDomain = viewNode.WebDomain;

            if (webDomain != null)
            {
                CommonUtil.logd($"child web domain: {webDomain}");
                if (!string.IsNullOrEmpty(validWebdomain))
                {
                    if (webDomain == validWebdomain)
                    {
                        throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}");
                    }
                }
                else
                {
                    validWebdomain = webDomain;
                }
            }

            string[] viewHints = viewNode.GetAutofillHints();
            if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused &&
                isManualRequest)
            {
                viewHints[0] = "on";
            }
            CommonUtil.logd("viewHints=" + viewHints);
            CommonUtil.logd("class=" + viewNode.ClassName);
            CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)"));
            if (viewNode?.HtmlInfo?.Tag == "input")
            {
                foreach (var p in viewNode.HtmlInfo.Attributes)
                {
                    CommonUtil.logd("attr=" + p.First + "/" + p.Second);
                }
            }
            if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/)
            {
                if (forFill)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(viewNode));
                }
                else
                {
                    FilledAutofillField filledAutofillField = new FilledAutofillField(viewNode);
                    ClientFormData.Add(filledAutofillField);
                }
            }
            else
            {
                if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input")
                {
                    _editTextsWithoutHint.Add(viewNode);
                }
            }
            var childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain);
                }
            }
        }
コード例 #23
0
            public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
            {
                FilledAutofillField field = mFields[position];

                ((FieldViewHolder)holder).Bind(field);
            }
コード例 #24
0
        protected override FilledAutofillFieldCollection GetDataset(Intent data)
        {
            if (!App.Kp2a.GetDb().Loaded || (App.Kp2a.QuickLocked))
            {
                return(null);
            }

            FilledAutofillFieldCollection fieldCollection = new FilledAutofillFieldCollection();

            var pwEntry = App.Kp2a.GetDb().LastOpenedEntry.Entry;

            foreach (string key in pwEntry.Strings.GetKeys())
            {
                FilledAutofillField field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { GetCanonicalHintFromKp2aField(pwEntry, key) },
                    TextValue     = pwEntry.Strings.ReadSafe(key),
                    Protected     = pwEntry.Strings.Get(key).IsProtected
                };
                fieldCollection.Add(field);
            }
            if (IsCreditCard(pwEntry) && pwEntry.Expires)
            {
                DateTime            expTime = pwEntry.ExpiryTime;
                FilledAutofillField field   =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationDate },
                    DateValue     = (long)(1000 * TimeUtil.SerializeUnix(expTime)),
                    Protected     = false
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationDay },
                    TextValue     = expTime.Day.ToString(),
                    Protected     = false
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationMonth },
                    TextValue     = expTime.Month.ToString(),
                    Protected     = false
                };
                fieldCollection.Add(field);

                field =
                    new FilledAutofillField
                {
                    AutofillHints = new[] { View.AutofillHintCreditCardExpirationYear },
                    TextValue     = expTime.Year.ToString(),
                    Protected     = false
                };
                fieldCollection.Add(field);
            }



            fieldCollection.DatasetName = pwEntry.Strings.ReadSafe(PwDefs.TitleField);

            return(fieldCollection);
        }