Example #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.multiple_partitions_activity);

            mCustomVirtualView = FindViewById <ScrollableCustomVirtualView>(Resource.Id.custom_view);


            mCredentialsPartition =
                mCustomVirtualView.AddPartition(GetString(Resource.String.partition_credentials));
            mCredentialsPartition.AddLine("username", AutofillType.Text,
                                          GetString(Resource.String.username_label),
                                          "         ", false, View.AutofillHintUsername);
            mCredentialsPartition.AddLine("password", AutofillType.Text,
                                          GetString(Resource.String.password_label),
                                          "         ", true, View.AutofillHintPassword);

            AutofillType ccExpirationType = AutofillType.Date;
            // TODO: add a checkbox to switch between text / date instead
            Intent intent = Intent;

            if (intent != null)
            {
                var newType = intent.GetIntExtra("dateType", -1);
                if (newType != -1)
                {
                    ccExpirationType = (AutofillType)newType;
                    var typeMessage = GetString(Resource.String.message_credit_card_expiration_type,
                                                CommonUtil.GetTypeAsString(ccExpirationType));
                    // TODO: display type in a header or proper status widget
                    Toast.MakeText(ApplicationContext, typeMessage, ToastLength.Long).Show();
                }
            }

            mCcPartition = mCustomVirtualView.AddPartition(GetString(Resource.String.partition_credit_card));
            mCcPartition.AddLine("ccNumber", AutofillType.Text,
                                 GetString(Resource.String.credit_card_number_label),
                                 "         ", true, View.AutofillHintCreditCardNumber);
            mCcPartition.AddLine("ccDay", AutofillType.Text,
                                 GetString(Resource.String.credit_card_expiration_day_label),
                                 "         ", true, View.AutofillHintCreditCardExpirationDay);
            mCcPartition.AddLine("ccMonth", ccExpirationType,
                                 GetString(Resource.String.credit_card_expiration_month_label),
                                 "         ", true, View.AutofillHintCreditCardExpirationMonth);
            mCcPartition.AddLine("ccYear", AutofillType.Text,
                                 GetString(Resource.String.credit_card_expiration_year_label),
                                 "         ", true, View.AutofillHintCreditCardExpirationYear);
            mCcPartition.AddLine("ccDate", ccExpirationType,
                                 GetString(Resource.String.credit_card_expiration_date_label),
                                 "         ", true, View.AutofillHintCreditCardExpirationDate);
            mCcPartition.AddLine("ccSecurityCode", AutofillType.Text,
                                 GetString(Resource.String.credit_card_security_code_label),
                                 "         ", true, View.AutofillHintCreditCardSecurityCode);

            FindViewById(Resource.Id.clear).Click += delegate
            {
                ResetFields();
                mCustomVirtualView.ResetPositions();
                mAutofillManager.Cancel();
            };

            mAutofillManager = (AutofillManager)GetSystemService(Class.FromType(typeof(AutofillManager)));
        }
Example #2
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);
            }
        }