Exemplo n.º 1
0
        private void OnSuccess()
        {
            var intent      = Intent;
            var forResponse = intent.GetBooleanExtra(CommonUtil.EXTRA_FOR_RESPONSE, true);
            var structure   = (AssistStructure)intent.GetParcelableExtra(AutofillManager.ExtraAssistStructure);
            var parser      = new StructureParser(ApplicationContext, structure);

            parser.ParseForFill();
            var autofillFields = parser.GetAutofillFields();

            mReplyIntent = new Intent();
            var clientFormDataMap = SharedPrefsAutofillRepository.GetInstance().GetFilledAutofillFieldCollection
                                        (this, autofillFields.GetFocusedHints(), autofillFields.GetAllHints());

            if (forResponse)
            {
                SetResponseIntent(AutofillHelper.NewResponse
                                      (this, false, autofillFields, clientFormDataMap));
            }
            else
            {
                var datasetName = intent.GetStringExtra(CommonUtil.EXTRA_DATASET_NAME);
                SetDatasetIntent(AutofillHelper.NewDataset
                                     (this, autofillFields, clientFormDataMap[datasetName], false));
            }
        }
Exemplo n.º 2
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));
            }
        }
 public AutofillFieldMetadata(ViewNode view)
 {
     AutofillId      = view.AutofillId;
     AutofillType    = view.AutofillType;
     AutofillOptions = view.GetAutofillOptions();
     Focused         = view.IsFocused;
     SetHints(AutofillHelper.FilterForSupportedHints(view.GetAutofillHints()));
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 5
0
        public override void OnFillRequest(FillRequest request, CancellationSignal cancellationSignal,
                                           FillCallback callback)
        {
            var structure   = request.FillContexts[request.FillContexts.Count - 1].Structure;
            var packageName = structure.ActivityComponent.PackageName;

            if (!SharedPrefsPackageVerificationRepository.GetInstance()
                .PutPackageSignatures(ApplicationContext, packageName))
            {
                callback.OnFailure(
                    ApplicationContext.GetString(AutofillService.Resource.String.invalid_package_signature));
                return;
            }

            var data = request.ClientState;

            if (CommonUtil.VERBOSE)
            {
                Log.Verbose(CommonUtil.TAG, "onFillRequest(): data=" + CommonUtil.BundleToString(data));
                CommonUtil.DumpStructure(structure);
            }

            cancellationSignal.SetOnCancelListener(new CancelListener());

            // Parse AutoFill data in Activity
            var parser = new StructureParser(ApplicationContext, structure);

            // TODO: try / catch on other places (onSave, auth activity, etc...)
            try
            {
                parser.ParseForFill();
            }
            catch (SecurityException e)
            {
                // TODO: handle cases where DAL didn't pass by showing a custom UI asking the user
                // to confirm the mapping. Might require subclassing SecurityException.
                Log.Warn(CommonUtil.TAG, "Security exception handling " + request, e);
                callback.OnFailure(e.Message);
                return;
            }

            var autofillFields  = parser.GetAutofillFields();
            var responseBuilder = new FillResponse.Builder();
            // Check user's settings for authenticating Responses and Datasets.
            var 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().GetFilledAutofillFieldCollection(
                    this, autofillFields.GetFocusedHints(), autofillFields.GetAllHints());
                var response = AutofillHelper.NewResponse(this, datasetAuth, autofillFields, clientFormDataMap);
                callback.OnSuccess(response);
            }
        }