示例#1
0
            public void Run()
            {
                // Room does not support TypeConverters for collections.
                var autofillDatasetFields = mAutofillDao.GetDatasetsWithName(allAutofillHints, datasetName);

                if (autofillDatasetFields != null && autofillDatasetFields.Count != 0)
                {
                    if (autofillDatasetFields.Count > 1)
                    {
                        Util.Logw("More than 1 dataset with name %s", datasetName);
                    }
                    DatasetWithFilledAutofillFields dataset = autofillDatasetFields[0];

                    mAppExecutors.mainThread.Execute(new MainThreadRunable3OnLoaded
                    {
                        dataset          = dataset,
                        datasetsCallback = datasetsCallback
                    });
                }
                else
                {
                    mAppExecutors.mainThread.Execute(new MainThreadRunable3OnDataNotAvailable
                    {
                        datasetsCallback = datasetsCallback
                    });
                }
            }
示例#2
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
            });
        }
        private void AppendViewMetadata([NonNull] DatasetWithFilledAutofillFields

                                        datasetWithFilledAutofillFields, [NonNull] string[] hints, int partition,
                                        [Nullable] string textValue, [Nullable] long dateValue, [Nullable] bool toggleValue,
                                        [Nullable] string[] autofillOptions, [Nullable] int listIndex)
        {
            for (int i = 0; i < hints.Length; i++)
            {
                String hint = hints[i];
                // Then check if the "actual" hint is supported.
                FieldTypeWithHeuristics fieldTypeWithHeuristics = mFieldTypesByAutofillHint[hint];
                if (fieldTypeWithHeuristics != null)
                {
                    FieldType fieldType = fieldTypeWithHeuristics.fieldType;
                    if (!AutofillHints.MatchesPartition(fieldType.GetPartition(), partition))
                    {
                        continue;
                    }
                    // Only add the field if the hint is supported by the type.
                    if (textValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Text))
                        {
                            Util.Loge("Text is invalid type for hint '%s'", hint);
                        }
                    }
                    if (autofillOptions != null && listIndex != null && autofillOptions.Length > listIndex)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.List))
                        {
                            Util.Loge("List is invalid type for hint '%s'", hint);
                        }
                        textValue = autofillOptions[listIndex];
                    }
                    if (dateValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Date))
                        {
                            Util.Loge("Date is invalid type for hint '%s'", hint);
                        }
                    }
                    if (toggleValue != null)
                    {
                        if (!fieldType.GetAutofillTypes().ints.Contains((int)AutofillType.Toggle))
                        {
                            Util.Loge("Toggle is invalid type for hint '%s'", hint);
                        }
                    }
                    String datasetId = datasetWithFilledAutofillFields.autofillDataset.GetId();
                    datasetWithFilledAutofillFields.Add(new FilledAutofillField(datasetId,
                                                                                mPackageName, fieldType.GetTypeName(), textValue, dateValue, toggleValue));
                }
                else
                {
                    Util.Loge("Invalid hint: %s", hint);
                }
            }
        }
示例#4
0
            public void Run()
            {
                DatasetWithFilledAutofillFields dataset = mAutofillDao.GetAutofillDatasetWithId(datasetId);

                mAppExecutors.mainThread.Execute(new MainThreadRunable11
                {
                    dataset  = dataset,
                    callback = callback
                });
            }
        /**
         * Parses a client view structure and build a dataset (in the form of a
         * {@link DatasetWithFilledAutofillFields}) from the view metadata found.
         */
        private DatasetWithFilledAutofillFields BuildDatasetForPartition(AutofillDataset dataset,
                                                                         int partition)
        {
            DatasetWithFilledAutofillFields datasetWithFilledAutofillFields = new DatasetWithFilledAutofillFields();

            datasetWithFilledAutofillFields.autofillDataset = dataset;
            mClientParser.Parse(new PartitionNodeProcessor
            {
                that      = this,
                partition = partition,
                datasetWithFilledAutofillFields = datasetWithFilledAutofillFields
            });
            return(datasetWithFilledAutofillFields);
        }
        public ImmutableList <DatasetWithFilledAutofillFields> BuildDatasetsByPartition(int datasetNumber)
        {
            //Guava
            var listBuilder = ImmutableList.Create <DatasetWithFilledAutofillFields>();

            foreach (int partition in AutofillHints.PARTITIONS)
            {
                AutofillDataset autofillDataset = new AutofillDataset(Guid.NewGuid().ToString(),
                                                                      "dataset-" + datasetNumber + "." + partition);
                DatasetWithFilledAutofillFields dataset =
                    BuildDatasetForPartition(autofillDataset, partition);
                if (dataset != null && dataset.filledAutofillFields != null)
                {
                    listBuilder.Add(dataset);
                }
            }
            return(listBuilder);
        }
        /**
         * Wraps autofill data in a {@link Dataset} object with an IntentSender, which can then be
         * sent back to the client.
         */
        public Dataset BuildDataset(Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
                                    DatasetWithFilledAutofillFields datasetWithFilledAutofillFields,
                                    RemoteViews remoteViews, IntentSender intentSender)
        {
            Dataset.Builder datasetBuilder = new Dataset.Builder(remoteViews);
            if (intentSender != null)
            {
                datasetBuilder.SetAuthentication(intentSender);
            }
            bool setAtLeastOneValue = BindDataset(fieldTypesByAutofillHint,
                                                  datasetWithFilledAutofillFields, datasetBuilder);

            if (!setAtLeastOneValue)
            {
                return(null);
            }
            return(datasetBuilder.Build());
        }
        private DatasetWithFilledAutofillFields BuildCollectionForPartition(
            AutofillDataset dataset, int partition)
        {
            DatasetWithFilledAutofillFields datasetWithFilledAutofillFields =
                new DatasetWithFilledAutofillFields();

            datasetWithFilledAutofillFields.autofillDataset = dataset;
            foreach (var fieldTypeWithHeuristics in mFieldTypesWithHints)
            {
                if (AutofillHints.MatchesPartition(
                        fieldTypeWithHeuristics.getFieldType().GetPartition(), partition))
                {
                    var fakeField = AutofillHints.generateFakeField(fieldTypeWithHeuristics, mPackageName,
                                                                    mSeed, dataset.GetId());
                    datasetWithFilledAutofillFields.Add(fakeField);
                }
            }
            return(datasetWithFilledAutofillFields);
        }
        private void ParseAutofillFields(AssistStructure.ViewNode viewNode,
                                         DatasetWithFilledAutofillFields datasetWithFilledAutofillFields, int partition)
        {
            string[] hints = viewNode.GetAutofillHints();
            if (hints == null || hints.Length == 0)
            {
                return;
            }
            var    autofillValue = viewNode.AutofillValue;
            string textValue     = null;
            long   dateValue     = Long.MinValue;
            bool   toggleValue   = false;

            string[] autofillOptions = null;
            int      listIndex       = Int32.MinValue;

            if (autofillValue != null)
            {
                if (autofillValue.IsText)
                {
                    // Using toString of AutofillValue.getTextValue in order to save it to
                    // SharedPreferences.
                    textValue = autofillValue.TextValue;
                }
                else if (autofillValue.IsDate)
                {
                    dateValue = autofillValue.DateValue;
                }
                else if (autofillValue.IsList)
                {
                    autofillOptions = viewNode.GetAutofillOptions();
                    listIndex       = autofillValue.ListValue;
                }
                else if (autofillValue.IsToggle)
                {
                    toggleValue = autofillValue.ToggleValue;
                }
            }
            AppendViewMetadata(datasetWithFilledAutofillFields, hints, partition, textValue, dateValue, toggleValue, autofillOptions, listIndex);
        }
        /**
         * Build an autofill {@link Dataset} using saved data and the client's AssistStructure.
         */
        private bool BindDataset(Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
                                 DatasetWithFilledAutofillFields datasetWithFilledAutofillFields,
                                 Dataset.Builder datasetBuilder)
        {
            MutableBoolean setValueAtLeastOnce = new MutableBoolean(false);

            var filledAutofillFieldsByTypeName =
                datasetWithFilledAutofillFields
                .filledAutofillFields
                .ToDictionary(x => x.GetFieldTypeName(), x => x);

            mClientParser.Parse(new BindDatasetNodeProcessor
            {
                datasetBuilder                 = datasetBuilder,
                setValueAtLeastOnce            = setValueAtLeastOnce,
                fieldTypesByAutofillHint       = fieldTypesByAutofillHint,
                filledAutofillFieldsByTypeName = filledAutofillFieldsByTypeName,
                datasetAdapter                 = this
            });

            return(setValueAtLeastOnce.Value);
        }
 /**
  * Wraps autofill data in a {@link Dataset} object which can then be sent back to the client.
  */
 public Dataset BuildDataset(Dictionary <string, FieldTypeWithHeuristics> fieldTypesByAutofillHint,
                             DatasetWithFilledAutofillFields datasetWithFilledAutofillFields,
                             RemoteViews remoteViews)
 {
     return(BuildDataset(fieldTypesByAutofillHint, datasetWithFilledAutofillFields, remoteViews, null));
 }