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); }
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); }
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); } }
public override void OnProvideAutofillVirtualStructure(ViewStructure structure, AutofillFlags flags) { // Build a ViewStructure that will get passed to the AutofillService by the framework // when it is time to find autofill suggestions. structure.SetClassName(Class.Name); int childrenSize = mVirtualViews.Size(); if (DEBUG) { Log.Debug(TAG, "onProvideAutofillVirtualStructure(): flags = " + flags + ", items = " + childrenSize + ", extras: " + CommonUtil.BundleToString(structure.Extras)); } int index = structure.AddChildCount(childrenSize); // Traverse through the view hierarchy, including virtual child views. For each view, we // need to set the relevant autofill metadata and add it to the ViewStructure. for (int i = 0; i < childrenSize; i++) { var item = mVirtualViews.ValueAt(i); if (DEBUG) { Log.Debug(TAG, "Adding new child at index " + index + ": " + item); } var child = structure.NewChild(index); child.SetAutofillId(structure.AutofillId, item.id); child.SetAutofillHints(item.hints); child.SetAutofillType(item.type); child.SetAutofillValue(item.GetAutofillValue()); child.SetDataIsSensitive(!item.sanitized); child.SetFocused(item.focused); child.SetVisibility(ViewStates.Visible); child.SetDimens(item.line.mBounds.Left, item.line.mBounds.Top, 0, 0, item.line.mBounds.Width(), item.line.mBounds.Height()); child.SetId(item.id, Context.PackageName, null, item.idEntry); child.SetClassName(item.GetClassName()); child.SetDimens(item.line.mBounds.Left, item.line.mBounds.Top, 0, 0, item.line.mBounds.Width(), item.line.mBounds.Height()); index++; } }
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); } }