• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Intent;
18 import android.os.Bundle;
19 import android.view.autofill.AutofillManager;
20 
21 import com.android.settings.applications.defaultapps.DefaultAutofillPicker;
22 
23 /**
24  * Standalone activity used to launch a {@link DefaultAutofillPicker} fragment from a
25  * {@link android.provider.Settings#ACTION_REQUEST_SET_AUTOFILL_SERVICE} intent.
26  *
27  * <p>It first check for cases that can fail fast, then forward to {@link AutofillPickerActivity}
28  * if necessary.
29  */
30 public class AutofillPickerTrampolineActivity extends Activity {
31 
32     @Override
onCreate(Bundle savedInstanceState)33     protected void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35 
36         // First check if the current user's service already belongs to the app...
37         final Intent intent = getIntent();
38         final String packageName = intent.getData().getSchemeSpecificPart();
39         final String currentService = DefaultAutofillPicker.getDefaultKey(this);
40         if (currentService != null && currentService.startsWith(packageName)) {
41             // ...and succeed right away if it does.
42             setResult(RESULT_OK);
43             finish();
44             return;
45         }
46 
47         // Then check if the Autofill is available for the current user...
48         final AutofillManager afm = getSystemService(AutofillManager.class);
49         if (afm == null || !afm.hasAutofillFeature() || !afm.isAutofillSupported()) {
50             // ... and fail right away if it is not.
51             setResult(RESULT_CANCELED);
52             finish();
53             return;
54         }
55 
56         // Otherwise, go ahead and show the real UI...
57         final Intent newIntent = new Intent(this, AutofillPickerActivity.class)
58                 .setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT)
59                 .setData(intent.getData());
60         startActivity(newIntent);
61         finish();
62     }
63 }
64