项目:android-AutofillFramework
文件:AuthActivity.java
private void onSuccess() {
Intent intent = getIntent();
boolean forResponse = intent.getBooleanExtra(EXTRA_FOR_RESPONSE,true);
Bundle clientState = intent.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE);
AssistStructure structure = intent.getParcelableExtra(EXTRA_ASSIST_STRUCTURE);
StructureParser parser = new StructureParser(getApplicationContext(),structure);
parser.parseForFill();
AutofillFieldMetadataCollection autofillFields = parser.getAutofillFields();
int saveTypes = autofillFields.getSaveType();
mReplyIntent = new Intent();
HashMap<String,FilledAutofillFieldCollection> clientFormDataMap =
SharedPrefsAutofillRepository.getInstance().getFilledAutofillFieldCollection
(this,autofillFields.getFocusedHints(),autofillFields.getAllHints());
if (forResponse) {
setResponseIntent(AutofillHelper.newResponse
(this,clientState,false,autofillFields,clientFormDataMap));
} else {
String datasetName = intent.getStringExtra(EXTRA_DATASET_NAME);
setDatasetIntent(AutofillHelper.newDataset
(this,clientFormDataMap.get(datasetName),false));
}
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onHandleAssist(Bundle data,AssistStructure structure,AssistContent content) {
super.onHandleAssist(data,structure,content);
ComponentName componentName=structure.getActivityComponent();
if (componentName.getPackageName().equals(HIDE_FLOAT_VIEW_PACKAGE_NAME)){
tipViewController.hide();
}else {
tipViewController.show(1,"");
}
}
项目:android-AutofillFramework
文件:Util.java
public static void dumpStructure(AssistStructure structure) {
if (logVerboseEnabled()) {
int nodeCount = structure.getwindowNodeCount();
logv("dumpStructure(): component=%s numberNodes=%d",structure.getActivityComponent(),nodeCount);
for (int i = 0; i < nodeCount; i++) {
logv("node #%d",i);
WindowNode node = structure.getwindowNodeAt(i);
dumpNode(new StringBuilder()," ",node.getRootViewNode(),0);
}
}
}
项目:android-AutofillFramework
文件:Util.java
/**
* Gets a node if it matches the filter criteria for the given id.
*/
public static ViewNode findNodeByFilter(@NonNull AssistStructure structure,@NonNull Object id,@NonNull NodeFilter filter) {
logv("Parsing request for activity %s",structure.getActivityComponent());
final int nodes = structure.getwindowNodeCount();
for (int i = 0; i < nodes; i++) {
final WindowNode windowNode = structure.getwindowNodeAt(i);
final ViewNode rootNode = windowNode.getRootViewNode();
final ViewNode node = findNodeByFilter(rootNode,id,filter);
if (node != null) {
return node;
}
}
return null;
}
项目:android-AutofillFramework
文件:Util.java
public static void dumpStructure(AssistStructure structure) {
int nodeCount = structure.getwindowNodeCount();
Log.v(TAG,"dumpStructure(): component=" + structure.getActivityComponent()
+ " numberNodes=" + nodeCount);
for (int i = 0; i < nodeCount; i++) {
Log.v(TAG,"node #" + i);
WindowNode node = structure.getwindowNodeAt(i);
dumpNode(" ",node.getRootViewNode());
}
}
@Override
public void onHandleAssistSecondary(Bundle data,AssistContent content,int index,int count) {
super.onHandleAssistSecondary(data,content,index,count);
}
@Override
public void onHandleAssist(Bundle data,content);
}
@Override
public void onHandleAssistSecondary(Bundle data,count);
}
项目:android-AutofillFramework
文件:StructureParser.java
StructureParser(Context context,AssistStructure structure) {
mContext = context;
mStructure = structure;
}
项目:android-AutofillFramework
文件:MyAutofillService.java
@Override
public void onFillRequest(FillRequest request,CancellationSignal cancellationSignal,FillCallback callback) {
AssistStructure structure = request.getFillContexts()
.get(request.getFillContexts().size() - 1).getStructure();
String packageName = structure.getActivityComponent().getPackageName();
if (!SharedPrefsPackageVerificationRepository.getInstance()
.putPackageSignatures(getApplicationContext(),packageName)) {
callback.onFailure(
getApplicationContext().getString(R.string.invalid_package_signature));
return;
}
final Bundle clientState = request.getClientState();
if (logVerboseEnabled()) {
logv("onFillRequest(): clientState=%s",bundletoString(clientState));
}
dumpStructure(structure);
cancellationSignal.setonCancelListener(() ->
logw("Cancel autofill not implemented in this sample.")
);
// Parse AutoFill data in Activity
StructureParser parser = new StructureParser(getApplicationContext(),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.
logw(e,"Security exception handling %s",request);
callback.onFailure(e.getMessage());
return;
}
AutofillFieldMetadataCollection autofillFields = parser.getAutofillFields();
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// Check user's settings for authenticating Responses and Datasets.
boolean responseAuth = MyPreferences.getInstance(this).isResponseAuth();
AutofillId[] autofillIds = autofillFields.getAutofillIds();
if (responseAuth && !Arrays.asList(autofillIds).isEmpty()) {
// If the entire Autofill Response is authenticated,AuthActivity is used
// to generate Response.
IntentSender sender = AuthActivity.getAuthIntentSenderForResponse(this);
RemoteViews presentation = AutofillHelper
.newRemoteViews(getPackageName(),getString(R.string.autofill_sign_in_prompt),R.drawable.ic_lock_black_24dp);
responseBuilder
.setAuthentication(autofillIds,sender,presentation);
callback.onSuccess(responseBuilder.build());
} else {
boolean datasetAuth = MyPreferences.getInstance(this).isDatasetAuth();
HashMap<String,FilledAutofillFieldCollection> clientFormDataMap =
SharedPrefsAutofillRepository.getInstance().getFilledAutofillFieldCollection(
this,autofillFields.getAllHints());
FillResponse response = AutofillHelper.newResponse
(this,datasetAuth,clientFormDataMap);
callback.onSuccess(response);
}
}
项目:android-AutofillFramework
文件:MyAutofillService.java
@Override
public void onSaveRequest(SaveRequest request,SaveCallback callback) {
List<FillContext> fillContexts = request.getFillContexts();
int size = fillContexts.size();
AssistStructure structure = fillContexts.get(size - 1).getStructure();
String packageName = structure.getActivityComponent().getPackageName();
if (!SharedPrefsPackageVerificationRepository.getInstance()
.putPackageSignatures(getApplicationContext(),packageName)) {
callback.onFailure(getApplicationContext().getString(R.string.invalid_package_signature));
return;
}
Bundle clientState = request.getClientState();
if (logVerboseEnabled()) {
logv("onSaveRequest(): clientState=%s",bundletoString(clientState));
}
dumpStructure(structure);
// Todo: hardcode check for partial username
if (clientState != null) {
String usernameKey =
String.format(CLIENT_STATE_PARTIAL_ID_TEMPLATE,View.AUTOFILL_HINT_USERNAME);
AutofillId usernameId = clientState.getParcelable(usernameKey);
logd("client state for %s: %s",usernameKey,usernameId);
if (usernameId != null) {
String passwordKey =
String.format(CLIENT_STATE_PARTIAL_ID_TEMPLATE,View.AUTOFILL_HINT_PASSWORD);
AutofillId passwordId = clientState.getParcelable(passwordKey);
logd("Scanning %d contexts for username ID %s and password ID %s.",size,usernameId,passwordId);
AssistStructure.ViewNode usernameNode =
findNodeByFilter(fillContexts,AUTOFILL_ID_FILTER);
AssistStructure.ViewNode passwordNode =
findNodeByFilter(fillContexts,passwordId,AUTOFILL_ID_FILTER);
String username = null,password = null;
if (usernameNode != null) {
username = usernameNode.getAutofillValue().getTextValue().toString();
}
if (passwordNode != null) {
password = passwordNode.getAutofillValue().getTextValue().toString();
}
if (username != null && password != null) {
logd("user: %s,pass: %s",username,password);
// Todo: save it
callback.onFailure("Todo: save " + username + "/" + password);
return;
} else {
logw(" missing user (%s) or pass (%s)",password);
}
}
}
StructureParser parser = new StructureParser(getApplicationContext(),structure);
parser.parseForSave();
FilledAutofillFieldCollection filledAutofillFieldCollection = parser.getClientFormData();
SharedPrefsAutofillRepository.getInstance()
.saveFilledAutofillFieldCollection(this,filledAutofillFieldCollection);
}
@Override
public void onHandleAssist(Bundle data,AssistContent content) {
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。