Ejemplo n.º 1
0
        public static FillResponse BuildFillResponse(Parser parser, List <FilledItem> items, bool locked,
                                                     bool inlineAutofillEnabled, FillRequest fillRequest = null)
        {
            // Acquire inline presentation specs on Android 11+
            IList <InlinePresentationSpec> inlinePresentationSpecs = null;
            var inlinePresentationSpecsCount = 0;
            var inlineMaxSuggestedCount      = 0;

            if (inlineAutofillEnabled && fillRequest != null && (int)Build.VERSION.SdkInt >= 30)
            {
                var inlineSuggestionsRequest = fillRequest.InlineSuggestionsRequest;
                inlineMaxSuggestedCount      = inlineSuggestionsRequest?.MaxSuggestionCount ?? 0;
                inlinePresentationSpecs      = inlineSuggestionsRequest?.InlinePresentationSpecs;
                inlinePresentationSpecsCount = inlinePresentationSpecs?.Count ?? 0;
            }

            // Build response
            var responseBuilder = new FillResponse.Builder();

            if (items != null && items.Count > 0)
            {
                var maxItems = items.Count;
                if (inlineMaxSuggestedCount > 0)
                {
                    // -1 to adjust for 'open vault' option
                    maxItems = Math.Min(maxItems, inlineMaxSuggestedCount - 1);
                }
                for (int i = 0; i < maxItems; i++)
                {
                    InlinePresentationSpec inlinePresentationSpec = null;
                    if (inlinePresentationSpecs != null)
                    {
                        if (i < inlinePresentationSpecsCount)
                        {
                            inlinePresentationSpec = inlinePresentationSpecs[i];
                        }
                        else
                        {
                            // If the max suggestion count is larger than the number of specs in the list, then
                            // the last spec is used for the remainder of the suggestions
                            inlinePresentationSpec = inlinePresentationSpecs[inlinePresentationSpecsCount - 1];
                        }
                    }
                    var dataset = BuildDataset(parser.ApplicationContext, parser.FieldCollection, items[i],
                                               inlinePresentationSpec);
                    if (dataset != null)
                    {
                        responseBuilder.AddDataset(dataset);
                    }
                }
            }
            responseBuilder.AddDataset(BuildVaultDataset(parser.ApplicationContext, parser.FieldCollection,
                                                         parser.Uri, locked, inlinePresentationSpecs));
            AddSaveInfo(parser, fillRequest, responseBuilder, parser.FieldCollection);
            responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray());
            return(responseBuilder.Build());
        }
Ejemplo n.º 2
0
        public static FillResponse BuildFillResponse(Parser parser, List <FilledItem> items, bool locked)
        {
            var responseBuilder = new FillResponse.Builder();

            if (items != null && items.Count > 0)
            {
                foreach (var item in items)
                {
                    var dataset = BuildDataset(parser.ApplicationContext, parser.FieldCollection, item);
                    if (dataset != null)
                    {
                        responseBuilder.AddDataset(dataset);
                    }
                }
            }
            responseBuilder.AddDataset(BuildVaultDataset(parser.ApplicationContext, parser.FieldCollection,
                                                         parser.Uri, locked));
            AddSaveInfo(parser, responseBuilder, parser.FieldCollection);
            responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray());
            return(responseBuilder.Build());
        }
Ejemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            string requestedUrl = Intent.GetStringExtra(ChooseForAutofillActivityBase.ExtraQueryString);

            if (requestedUrl == null)
            {
                Toast.MakeText(this, "Cannot execute query for null.", ToastLength.Long).Show();
                RestartApp();
                return;
            }

            var prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            bool isDisable = Intent.GetBooleanExtra(ExtraIsDisable, true);

            var disabledValues = prefs.GetStringSet("AutoFillDisabledQueries", new HashSet <string>()
            {
            }).ToHashSet();

            if (isDisable)
            {
                disabledValues.Add(requestedUrl);
            }
            else
            {
                disabledValues.Remove(requestedUrl);
            }


            prefs.Edit().PutStringSet("AutoFillDisabledQueries", disabledValues).Commit();

            bool isManual = Intent.GetBooleanExtra(ChooseForAutofillActivityBase.ExtraIsManualRequest, false);

            Intent reply = new Intent();

            FillResponse.Builder builder   = new FillResponse.Builder();
            AssistStructure      structure = (AssistStructure)Intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            StructureParser      parser    = new StructureParser(this, structure);

            try
            {
                parser.ParseForFill(isManual);
            }
            catch (Java.Lang.SecurityException e)
            {
                Log.Warn(CommonUtil.Tag, "Security exception handling request");
                SetResult(Result.Canceled);
                return;
            }

            AutofillFieldMetadataCollection autofillFields = parser.AutofillFields;


            var autofillIds = autofillFields.GetAutofillIds();

            builder.SetIgnoredIds(autofillIds);
            Bundle state = new Bundle();

            state.PutStringArray("AutoFillDisabledQueries", disabledValues.ToArray());

            builder.SetClientState(state);
            try
            {
                var response = builder.Build();
                reply.PutExtra(AutofillManager.ExtraAuthenticationResult, response);
            }
            catch (Exception e)
            {
                Kp2aLog.LogUnexpectedError(e);
                throw;
            }

            SetResult(Result.Ok, reply);


            Finish();
        }