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