Esempio 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));
            }
        }
Esempio 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));
            }
        }
Esempio n. 3
0
        public override void OnSaveRequest(SaveRequest request, SaveCallback callback)
        {
            var context     = request.FillContexts;
            var structure   = context[context.Count - 1].Structure;
            var packageName = structure.ActivityComponent.PackageName;

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

            var data = request.ClientState;

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

            var parser = new StructureParser(ApplicationContext, structure);

            parser.ParseForSave();
            var filledAutofillFieldCollection = parser.GetClientFormData();

            SharedPrefsAutofillRepository.GetInstance()
            .SaveFilledAutofillFieldCollection(this, filledAutofillFieldCollection);
        }
Esempio n. 4
0
 public void OnClick(IDialogInterface dialog, int which)
 {
     SharedPrefsAutofillRepository.GetInstance().Clear(that);
     SharedPrefsPackageVerificationRepository.GetInstance().Clear(that);
     MyPreferences.GetInstance(that).ClearCredentials();
     dialog.Dismiss();
 }
Esempio n. 5
0
        public override void OnSaveRequest(SaveRequest request, SaveCallback callback)
        {
            var context   = request.FillContexts;
            var structure = context[context.Count - 1].Structure;
            var data      = request.ClientState;

            Log.Debug(CommonUtil.Tag, "onSaveRequest(): data=" + CommonUtil.BundleToString(data));
            var parser = new StructureParser(structure);

            parser.ParseForSave();
            var filledAutofillFieldCollection = parser.ClientFormData;

            SharedPrefsAutofillRepository.GetInstance(this).SaveFilledAutofillFieldCollection(filledAutofillFieldCollection);
        }
        Android.Support.V7.App.AlertDialog BuildClearDataDialog()
        {
            var builder = new Android.Support.V7.App.AlertDialog.Builder(this)
                          .SetMessage(Resource.String.settings_clear_data_confirmation)
                          .SetTitle(Resource.String.settings_clear_data_confirmation_title)
                          .SetNegativeButton(Resource.String.cancel, (sender, args) => {
                // Do nothing...
            })
                          .SetPositiveButton(Resource.String.ok, (sender, args) =>
            {
                SharedPrefsAutofillRepository.GetInstance(this).Clear();
                MyPreferences.GetInstance(this).ClearCredentials();
                DismissDataDialog();
            });

            ClearDataDialog = builder.Create();
            return(ClearDataDialog);
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
            }
        }