1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.applications.autofill; 15 16 import android.app.Activity; 17 import android.content.ComponentName; 18 import android.content.Intent; 19 import android.os.Bundle; 20 import android.view.autofill.AutofillManager; 21 22 import com.android.settings.applications.defaultapps.DefaultAutofillPicker; 23 24 /** 25 * Standalone activity used to launch a {@link DefaultAutofillPicker} fragment from a 26 * {@link android.provider.Settings#ACTION_REQUEST_SET_AUTOFILL_SERVICE} intent. 27 * 28 * <p>It first check for cases that can fail fast, then forward to {@link AutofillPickerActivity} 29 * if necessary. 30 */ 31 public class AutofillPickerTrampolineActivity extends Activity { 32 33 @Override onCreate(Bundle savedInstanceState)34 protected void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 37 final AutofillManager afm = getSystemService(AutofillManager.class); 38 39 // First check if the Autofill is available for the current user... 40 if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) { 41 // ... and fail right away if it is not. 42 setResult(RESULT_CANCELED); 43 finish(); 44 return; 45 } 46 47 // Then check if the current user's service already belongs to the app... 48 final Intent intent = getIntent(); 49 final String packageName = intent.getData().getSchemeSpecificPart(); 50 final ComponentName currentService = afm.getAutofillServiceComponentName(); 51 if (currentService != null && currentService.getPackageName().equals(packageName)) { 52 // ...and succeed right away if it does. 53 setResult(RESULT_OK); 54 finish(); 55 return; 56 } 57 58 // Otherwise, go ahead and show the real UI... 59 final Intent newIntent = new Intent(this, AutofillPickerActivity.class) 60 .setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT) 61 .setData(intent.getData()); 62 startActivity(newIntent); 63 finish(); 64 } 65 } 66