/**
         * Wraps autofill data in a LoginCredential  Dataset object which can then be sent back to the
         * client View.
         */
        public static Dataset NewDataset(
            Context context,
            AutofillFieldMetadataCollection autofillFields,
            FilledAutofillFieldCollection filledAutofillFieldCollection,
            bool datasetAuth)
        {
            var datasetName = filledAutofillFieldCollection.GetDatasetName();

            if (datasetName != null)
            {
                Dataset.Builder datasetBuilder;
                if (datasetAuth)
                {
                    datasetBuilder = new Dataset.Builder
                                         (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_lock_black_24dp));
                    var sender = AuthActivity.GetAuthIntentSenderForDataset(context, datasetName);
                    datasetBuilder.SetAuthentication(sender);
                }
                else
                {
                    datasetBuilder = new Dataset.Builder
                                         (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_person_black_24dp));
                }

                var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder);
                if (setValueAtLeastOnce)
                {
                    return(datasetBuilder.Build());
                }
            }

            return(null);
        }
        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);
        }
Пример #3
0
        public static FilledAutofillFieldCollection FilterForPartition(FilledAutofillFieldCollection autofillFields, int partitionIndex)
        {
            FilledAutofillFieldCollection filteredCollection =
                new FilledAutofillFieldCollection {
                DatasetName = autofillFields.DatasetName
            };

            if (partitionIndex == -1)
            {
                return(filteredCollection);
            }

            foreach (var field in autofillFields.HintMap.Values.Distinct())
            {
                foreach (var hint in field.AutofillHints)
                {
                    if (GetPartitionIndex(hint) == partitionIndex)
                    {
                        filteredCollection.Add(field);
                        break;
                    }
                }
            }

            return(filteredCollection);
        }
        private List <Dataset> BuildEntryDatasets(string query, string queryDomain, string queryPackage, AutofillId[] autofillIds, StructureParser parser,
                                                  DisplayWarning warning)
        {
            List <Dataset> result = new List <Dataset>();

            Kp2aLog.Log("AF: BuildEntryDatasets");
            var suggestedEntries = GetSuggestedEntries(query).ToDictionary(e => e.DatasetName, e => e);

            Kp2aLog.Log("AF: BuildEntryDatasets found " + suggestedEntries.Count + " entries");
            foreach (var filledAutofillFieldCollection in suggestedEntries.Values)
            {
                if (filledAutofillFieldCollection == null)
                {
                    continue;
                }

                if (warning == DisplayWarning.None)
                {
                    FilledAutofillFieldCollection partitionData =
                        AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, parser.AutofillFields.FocusedAutofillCanonicalHints);

                    Kp2aLog.Log("AF: Add dataset");

                    result.Add(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder));
                }
                else
                {
                    //return an "auth" dataset (actually for just warning the user in case domain/package dont match)
                    var sender =
                        IntentBuilder.GetAuthIntentSenderForWarning(this, query, queryDomain, queryPackage, warning);
                    var datasetName = filledAutofillFieldCollection.DatasetName;
                    if (datasetName == null)
                    {
                        Kp2aLog.Log("AF: dataset name is null");
                        continue;
                    }

                    RemoteViews presentation =
                        AutofillHelper.NewRemoteViews(PackageName, datasetName, AppNames.LauncherIcon);

                    var datasetBuilder = new Dataset.Builder(presentation);
                    datasetBuilder.SetAuthentication(sender);
                    //need to add placeholders so we can directly fill after ChooseActivity
                    foreach (var autofillId in autofillIds)
                    {
                        datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER"));
                    }
                    Kp2aLog.Log("AF: Add auth dataset");
                    result.Add(datasetBuilder.Build());
                }
            }

            return(result);
        }
Пример #5
0
        public static FilledAutofillFieldCollection FilterForPartition(FilledAutofillFieldCollection filledAutofillFieldCollection, List <string> autofillFieldsFocusedAutofillCanonicalHints)
        {
            //only apply partition data if we have FocusedAutofillCanonicalHints. This may be empty on buggy Firefox.
            if (autofillFieldsFocusedAutofillCanonicalHints.Any())
            {
                int partitionIndex = AutofillHintsHelper.GetPartitionIndex(autofillFieldsFocusedAutofillCanonicalHints.FirstOrDefault());
                return(AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, partitionIndex));
            }

            return(filledAutofillFieldCollection);
        }
        public void SaveFilledAutofillFieldCollection(Context context,
                                                      FilledAutofillFieldCollection filledAutofillFieldCollection)
        {
            var datasetName = "dataset-" + GetDatasetNumber(context);

            filledAutofillFieldCollection.SetDatasetName(datasetName);
            var allAutofillData = GetAllAutofillDataStringSet(context);

            allAutofillData.Add(JsonConvert.SerializeObject(filledAutofillFieldCollection));
            SaveAllAutofillDataStringSet(context, allAutofillData);
            IncrementDatasetNumber(context);
        }
Пример #7
0
        private Dataset AddEntryDataset(string query, StructureParser parser)
        {
            var filledAutofillFieldCollection = GetSuggestedEntry(query);

            if (filledAutofillFieldCollection == null)
            {
                return(null);
            }
            int partitionIndex = AutofillHintsHelper.GetPartitionIndex(parser.AutofillFields.FocusedAutofillCanonicalHints.FirstOrDefault());
            FilledAutofillFieldCollection partitionData = AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, partitionIndex);

            return(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder));
        }
Пример #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>
        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);
            }
        }
        protected void OnSuccess(FilledAutofillFieldCollection clientFormDataMap, bool isManual)
        {
            var             intent    = Intent;
            AssistStructure structure = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            StructureParser parser    = new StructureParser(this, structure);

            parser.ParseForFill(isManual);
            AutofillFieldMetadataCollection autofillFields = parser.AutofillFields;
            int partitionIndex = AutofillHintsHelper.GetPartitionIndex(autofillFields.FocusedAutofillCanonicalHints.FirstOrDefault());
            FilledAutofillFieldCollection partitionData = AutofillHintsHelper.FilterForPartition(clientFormDataMap, partitionIndex);

            ReplyIntent = new Intent();
            SetDatasetIntent(AutofillHelper.NewDataset(this, autofillFields, partitionData, IntentBuilder));
        }
        public static FilledAutofillFieldCollection GetFakeFieldCollection(int partition, int seed)
        {
            var filledAutofillFieldCollection = new FilledAutofillFieldCollection();

            foreach (var hint in sValidHints.Keys)
            {
                if (hint != null && sValidHints[hint].GetPartition() == partition)
                {
                    var fakeField = GetFakeField(hint, seed);
                    filledAutofillFieldCollection.Add(fakeField);
                }
            }

            return(filledAutofillFieldCollection);
        }
        public void SaveFilledAutofillFieldCollection(FilledAutofillFieldCollection filledAutofillFieldCollection)
        {
            var datasetName = "dataset-" + GetDatasetNumber();

            filledAutofillFieldCollection.DatasetName = datasetName;
            ICollection <string> allAutofillData = GetAllAutofillDataStringSet();
            var json = JsonConvert.SerializeObject(filledAutofillFieldCollection, Formatting.Indented, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            allAutofillData.Add(json);
            SaveAllAutofillDataStringSet(allAutofillData);
            IncrementDatasetNumber();
        }
        protected void OnSuccess(FilledAutofillFieldCollection clientFormDataMap, bool isManual)
        {
            var             intent    = Intent;
            AssistStructure structure = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            StructureParser parser    = new StructureParser(this, structure);

            parser.ParseForFill(isManual);
            AutofillFieldMetadataCollection autofillFields = parser.AutofillFields;
            var partitionData = AutofillHintsHelper.FilterForPartition(clientFormDataMap, parser.AutofillFields.FocusedAutofillCanonicalHints);



            ReplyIntent = new Intent();
            SetDatasetIntent(AutofillHelper.NewDataset(this, autofillFields, partitionData, IntentBuilder, null /*TODO can we get the inlinePresentationSpec here?*/));
            SetResult(Result.Ok, ReplyIntent);
        }
        /**
         * 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");
                }
            }
        }
Пример #14
0
        private Dataset BuildEntryDataset(string query, string queryDomain, string queryPackage, AutofillId[] autofillIds, StructureParser parser,
                                          DisplayWarning warning)
        {
            var filledAutofillFieldCollection = GetSuggestedEntry(query);

            if (filledAutofillFieldCollection == null)
            {
                return(null);
            }

            if (warning == DisplayWarning.None)
            {
                //can return an actual dataset
                int partitionIndex = AutofillHintsHelper.GetPartitionIndex(parser.AutofillFields.FocusedAutofillCanonicalHints.FirstOrDefault());
                FilledAutofillFieldCollection partitionData = AutofillHintsHelper.FilterForPartition(filledAutofillFieldCollection, partitionIndex);

                return(AutofillHelper.NewDataset(this, parser.AutofillFields, partitionData, IntentBuilder));
            }
            else
            {
                //return an "auth" dataset (actually for just warning the user in case domain/package dont match)
                var sender      = IntentBuilder.GetAuthIntentSenderForWarning(this, query, queryDomain, queryPackage, warning);
                var datasetName = filledAutofillFieldCollection.DatasetName;
                if (datasetName == null)
                {
                    return(null);
                }

                RemoteViews presentation = AutofillHelper.NewRemoteViews(PackageName, datasetName, AppNames.LauncherIcon);

                var datasetBuilder = new Dataset.Builder(presentation);
                datasetBuilder.SetAuthentication(sender);
                //need to add placeholders so we can directly fill after ChooseActivity
                foreach (var autofillId in autofillIds)
                {
                    datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER"));
                }

                return(datasetBuilder.Build());
            }
        }
Пример #15
0
        /**
         * Builds mock autofill data and saves it to repository.
         */
        private bool BuildAndSaveMockedAutofillFieldCollection(Context context, int numOfDatasets)
        {
            if (numOfDatasets < 0 || numOfDatasets > 10)
            {
                Log.Warn(TAG, "Number of Datasets out of range.");
                return(false);
            }

            for (int i = 0; i < numOfDatasets * 2; i += 2)
            {
                foreach (int partition in AutofillHints.PARTITIONS)
                {
                    FilledAutofillFieldCollection filledAutofillFieldCollection =
                        AutofillHints.GetFakeFieldCollection(partition, i);
                    SharedPrefsAutofillRepository.GetInstance().SaveFilledAutofillFieldCollection(
                        context, filledAutofillFieldCollection);
                }
            }

            return(true);
        }
Пример #16
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);
        }