• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings.accounts;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.UserHandle;
22 import android.os.UserManager;
23 import android.provider.SearchIndexableResource;
24 
25 import com.android.settings.R;
26 import com.android.settings.Utils;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.search.BaseSearchIndexProvider;
29 import com.android.settings.search.Indexable;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 import java.util.ArrayList;
34 import java.util.List;
35 
36 /**
37  * Activity asking a user to select an account to be set up.
38  */
39 @SearchIndexable
40 public class ChooseAccountFragment extends DashboardFragment {
41 
42     private static final String TAG = "ChooseAccountFragment";
43 
44     @Override
getMetricsCategory()45     public int getMetricsCategory() {
46         return SettingsEnums.ACCOUNTS_CHOOSE_ACCOUNT_ACTIVITY;
47     }
48 
49     @Override
onAttach(Context context)50     public void onAttach(Context context) {
51         super.onAttach(context);
52 
53         final String[] authorities = getIntent().getStringArrayExtra(
54                 AccountPreferenceBase.AUTHORITIES_FILTER_KEY);
55         final String[] accountTypesFilter = getIntent().getStringArrayExtra(
56                 AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY);
57         final UserManager userManager = UserManager.get(getContext());
58         final UserHandle userHandle = Utils.getSecureTargetUser(getActivity().getActivityToken(),
59                 userManager, null /* arguments */, getIntent().getExtras());
60 
61         use(ChooseAccountPreferenceController.class).initialize(authorities, accountTypesFilter,
62                 userHandle, getActivity());
63         use(EnterpriseDisclosurePreferenceController.class).setFooterPreferenceMixin(
64                 mFooterPreferenceMixin);
65     }
66 
67     @Override
getPreferenceScreenResId()68     protected int getPreferenceScreenResId() {
69         return R.xml.add_account_settings;
70     }
71 
72     @Override
getLogTag()73     protected String getLogTag() {
74         return TAG;
75     }
76 
77     @Override
createPreferenceControllers(Context context)78     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
79         return buildControllers(context);
80     }
81 
buildControllers(Context context)82     private static List<AbstractPreferenceController> buildControllers(Context context) {
83         final List<AbstractPreferenceController> controllers = new ArrayList<>();
84         controllers.add(new EnterpriseDisclosurePreferenceController(context));
85         return controllers;
86     }
87 
88     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
89             new BaseSearchIndexProvider() {
90                 @Override
91                 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
92                         boolean enabled) {
93                     final ArrayList<SearchIndexableResource> result = new ArrayList<>();
94 
95                     final SearchIndexableResource sir = new SearchIndexableResource(context);
96                     sir.xmlResId = R.xml.add_account_settings;
97                     result.add(sir);
98                     return result;
99                 }
100 
101                 @Override
102                 public List<AbstractPreferenceController> createPreferenceControllers(
103                         Context context) {
104                     return buildControllers(context);
105                 }
106             };
107 }
108