コード例 #1
0
        protected void OnSuccess()
        {
            var             intent      = Intent;
            var             forResponse = intent.GetBooleanExtra(CommonUtil.EXTRA_FOR_RESPONSE, true);
            AssistStructure structure   = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            StructureParser parser      = new StructureParser(structure);

            parser.ParseForFill();
            AutofillFieldMetadataCollection autofillFields = parser.AutofillFields;
            var saveTypes = autofillFields.SaveType;

            ReplyIntent = new Intent();
            var clientFormDataMap = SharedPrefsAutofillRepository.GetInstance(this).GetFilledAutofillFieldCollection
                                        (autofillFields.FocusedAutofillHints, autofillFields.AllAutofillHints);

            if (forResponse)
            {
                SetResponseIntent(AutofillHelper.NewResponse(this, false, autofillFields, clientFormDataMap));
            }
            else
            {
                String datasetName = intent.GetStringExtra(CommonUtil.EXTRA_DATASET_NAME);
                SetDatasetIntent(AutofillHelper.NewDataset(this, autofillFields, clientFormDataMap[datasetName], false));
            }
        }
コード例 #2
0
        /// <summary>
        /// Wraps autofill data in a Response object (essentially a series of Datasets) which can then
        /// be sent back to the client View.
        /// </summary>
        /// <returns>The response.</returns>
        /// <param name="context">Context.</param>
        /// <param name="datasetAuth">If set to <c>true</c> dataset auth.</param>
        /// <param name="autofillFields">Autofill fields.</param>
        /// <param name="clientFormDataMap">Client form data map.</param>
        public static FillResponse NewResponse(Context context, bool datasetAuth, AutofillFieldMetadataCollection autofillFields,
                                               Dictionary <string, FilledAutofillFieldCollection> clientFormDataMap)
        {
            var responseBuilder = new FillResponse.Builder();

            if (clientFormDataMap != null)
            {
                var datasetNames = clientFormDataMap.Keys;
                foreach (var datasetName in datasetNames)
                {
                    var filledAutofillFieldCollection = clientFormDataMap[datasetName];
                    if (filledAutofillFieldCollection != null)
                    {
                        var dataset = NewDataset(context, autofillFields, filledAutofillFieldCollection, datasetAuth);
                        if (dataset != null)
                        {
                            responseBuilder.AddDataset(dataset);
                        }
                    }
                }
            }
            if (autofillFields.SaveType != 0)
            {
                var autofillIds = autofillFields.GetAutofillIds();
                responseBuilder.SetSaveInfo
                    (new SaveInfo.Builder(autofillFields.SaveType, autofillIds).Build());
                return(responseBuilder.Build());
            }
            else
            {
                Log.Debug(CommonUtil.Tag, "These fields are not meant to be saved by autofill.");
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Wraps autofill data in a LoginCredential  Dataset object which can then be sent back to the
        /// client View.
        /// </summary>
        /// <returns>The dataset.</returns>
        /// <param name="context">Context.</param>
        /// <param name="autofillFields">Autofill fields.</param>
        /// <param name="filledAutofillFieldCollection">Filled autofill field collection.</param>
        /// <param name="datasetAuth">If set to <c>true</c> dataset auth.</param>
        public static Dataset NewDataset(Context context,
                                         AutofillFieldMetadataCollection autofillFields, FilledAutofillFieldCollection filledAutofillFieldCollection, bool datasetAuth)
        {
            var datasetName = filledAutofillFieldCollection.DatasetName;

            if (datasetName != null)
            {
                Dataset.Builder datasetBuilder;
                if (datasetAuth)
                {
                    datasetBuilder = new Dataset.Builder
                                         (NewRemoteViews(context.PackageName, datasetName,
                                                         Resource.Drawable.ic_lock_black_24dp));
                    IntentSender 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);
        }
コード例 #4
0
        public override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal, FillCallback callback)
        {
            var structure = request.FillContexts[request.FillContexts.Count - 1].Structure;
            var data      = request.ClientState;

            Log.Debug(CommonUtil.Tag, "onFillRequest(): data=" + CommonUtil.BundleToString(data));

            cancellationSignal.CancelEvent += (sender, e) => {
                Log.Warn(CommonUtil.Tag, "Cancel autofill not implemented in this sample.");
            };
            // Parse AutoFill data in Activity
            var parser = new StructureParser(structure);

            parser.ParseForFill();
            AutofillFieldMetadataCollection autofillFields = parser.AutofillFields;
            var responseBuilder = new FillResponse.Builder();
            // Check user's settings for authenticating Responses and Datasets.
            bool responseAuth = MyPreferences.GetInstance(this).IsResponseAuth();
            var  autofillIds  = autofillFields.GetAutofillIds();

            if (responseAuth && !(autofillIds.Length == 0))
            {
                // If the entire Autofill Response is authenticated, AuthActivity is used
                // to generate Response.
                var sender       = AuthActivity.GetAuthIntentSenderForResponse(this);
                var presentation = AutofillHelper
                                   .NewRemoteViews(PackageName, GetString(Resource.String.autofill_sign_in_prompt),
                                                   Resource.Drawable.ic_lock_black_24dp);
                responseBuilder
                .SetAuthentication(autofillIds, sender, presentation);
                callback.OnSuccess(responseBuilder.Build());
            }
            else
            {
                var datasetAuth       = MyPreferences.GetInstance(this).IsDatasetAuth();
                var clientFormDataMap = SharedPrefsAutofillRepository.GetInstance(this).GetFilledAutofillFieldCollection
                                            (autofillFields.FocusedAutofillHints, autofillFields.AllAutofillHints);
                var response = AutofillHelper.NewResponse(this, datasetAuth, autofillFields, clientFormDataMap);
                callback.OnSuccess(response);
            }
        }
コード例 #5
0
 public StructureParser(AssistStructure structure)
 {
     Structure      = structure;
     AutofillFields = new AutofillFieldMetadataCollection();
 }