Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.settings.accounts; |
| 17 | |
Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 18 | import static android.provider.Settings.EXTRA_AUTHORITIES; |
| 19 | |
Stanley Wang | 3b02810 | 2019-12-18 18:29:56 +0800 | [diff] [blame] | 20 | import android.accounts.Account; |
| 21 | import android.accounts.AccountManager; |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 22 | import android.app.settings.SettingsEnums; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 23 | import android.content.Context; |
Stanley Wang | 3b02810 | 2019-12-18 18:29:56 +0800 | [diff] [blame] | 24 | import android.content.pm.UserInfo; |
| 25 | import android.os.UserHandle; |
| 26 | import android.os.UserManager; |
Fan Zhang | 6e88635 | 2016-12-05 14:42:49 -0800 | [diff] [blame] | 27 | |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 28 | import com.android.settings.R; |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 29 | import com.android.settings.SettingsPreferenceFragment; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 30 | import com.android.settings.dashboard.DashboardFragment; |
Raff Tsai | 6586629 | 2019-10-05 09:32:19 +0800 | [diff] [blame] | 31 | import com.android.settings.dashboard.profileselector.ProfileSelectFragment; |
Fan Zhang | 6e88635 | 2016-12-05 14:42:49 -0800 | [diff] [blame] | 32 | import com.android.settings.search.BaseSearchIndexProvider; |
Fan Zhang | ad47e1a | 2018-03-07 15:42:53 -0800 | [diff] [blame] | 33 | import com.android.settings.users.AutoSyncDataPreferenceController; |
| 34 | import com.android.settings.users.AutoSyncPersonalDataPreferenceController; |
| 35 | import com.android.settings.users.AutoSyncWorkDataPreferenceController; |
Tony Mantler | 1d583e1 | 2017-06-13 13:09:25 -0700 | [diff] [blame] | 36 | import com.android.settingslib.core.AbstractPreferenceController; |
Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 37 | import com.android.settingslib.search.SearchIndexable; |
Stanley Wang | 8015cba | 2019-11-27 10:39:59 +0800 | [diff] [blame] | 38 | import com.android.settingslib.search.SearchIndexableRaw; |
Fan Zhang | 6e88635 | 2016-12-05 14:42:49 -0800 | [diff] [blame] | 39 | |
Doris Ling | c7e2ed8 | 2016-10-27 13:09:16 -0700 | [diff] [blame] | 40 | import java.util.ArrayList; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 41 | import java.util.List; |
| 42 | |
Tony Mantler | 0fcd6cb | 2018-03-26 15:17:25 -0700 | [diff] [blame] | 43 | @SearchIndexable |
Fan Zhang | 881d579 | 2018-01-26 10:15:56 -0800 | [diff] [blame] | 44 | public class AccountDashboardFragment extends DashboardFragment { |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 45 | |
Fan Zhang | 881d579 | 2018-01-26 10:15:56 -0800 | [diff] [blame] | 46 | private static final String TAG = "AccountDashboardFrag"; |
| 47 | |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 48 | |
| 49 | @Override |
| 50 | public int getMetricsCategory() { |
Fan Zhang | 31b2100 | 2019-01-16 13:49:47 -0800 | [diff] [blame] | 51 | return SettingsEnums.ACCOUNT; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 55 | protected String getLogTag() { |
| 56 | return TAG; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected int getPreferenceScreenResId() { |
Raff Tsai | 966fa01 | 2019-09-25 11:19:06 +0800 | [diff] [blame] | 61 | return R.xml.accounts_dashboard_settings; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
Fan Zhang | e0b0e9f | 2017-11-29 14:55:59 -0800 | [diff] [blame] | 65 | public int getHelpResource() { |
Fan Zhang | 179645e | 2017-06-05 13:13:42 -0700 | [diff] [blame] | 66 | return R.string.help_url_user_and_account_dashboard; |
| 67 | } |
| 68 | |
| 69 | @Override |
Fan Zhang | f7843ad | 2018-02-22 13:51:41 -0800 | [diff] [blame] | 70 | protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { |
Fan Zhang | 881d579 | 2018-01-26 10:15:56 -0800 | [diff] [blame] | 71 | final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES); |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 72 | return buildPreferenceControllers(context, this /* parent */, authorities); |
| 73 | } |
| 74 | |
| 75 | private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, |
| 76 | SettingsPreferenceFragment parent, String[] authorities) { |
| 77 | final List<AbstractPreferenceController> controllers = new ArrayList<>(); |
| 78 | |
Doris Ling | bfac31b | 2016-11-10 15:12:52 -0800 | [diff] [blame] | 79 | final AccountPreferenceController accountPrefController = |
Raff Tsai | 6586629 | 2019-10-05 09:32:19 +0800 | [diff] [blame] | 80 | new AccountPreferenceController(context, parent, authorities, |
Raff Tsai | 1e5d814 | 2019-12-12 11:45:41 +0800 | [diff] [blame] | 81 | ProfileSelectFragment.ProfileType.ALL); |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 82 | if (parent != null) { |
tmfang | 27c84de | 2018-06-28 11:39:05 +0800 | [diff] [blame] | 83 | parent.getSettingsLifecycle().addObserver(accountPrefController); |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 84 | } |
Doris Ling | bfac31b | 2016-11-10 15:12:52 -0800 | [diff] [blame] | 85 | controllers.add(accountPrefController); |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 86 | controllers.add(new AutoSyncDataPreferenceController(context, parent)); |
| 87 | controllers.add(new AutoSyncPersonalDataPreferenceController(context, parent)); |
| 88 | controllers.add(new AutoSyncWorkDataPreferenceController(context, parent)); |
Doris Ling | c7e2ed8 | 2016-10-27 13:09:16 -0700 | [diff] [blame] | 89 | return controllers; |
Doris Ling | d7aae18 | 2016-10-21 11:33:54 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Raff Tsai | ac3e0d0 | 2019-09-19 17:06:45 +0800 | [diff] [blame] | 92 | public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 93 | new BaseSearchIndexProvider(R.xml.accounts_dashboard_settings) { |
Fan Zhang | 3f34335 | 2018-06-04 14:27:14 -0700 | [diff] [blame] | 94 | |
| 95 | @Override |
| 96 | public List<AbstractPreferenceController> createPreferenceControllers( |
| 97 | Context context) { |
| 98 | return buildPreferenceControllers( |
| 99 | context, null /* parent */, null /* authorities*/); |
| 100 | } |
Stanley Wang | 8015cba | 2019-11-27 10:39:59 +0800 | [diff] [blame] | 101 | |
| 102 | @Override |
| 103 | public List<SearchIndexableRaw> getDynamicRawDataToIndex(Context context, |
| 104 | boolean enabled) { |
Stanley Wang | 3b02810 | 2019-12-18 18:29:56 +0800 | [diff] [blame] | 105 | final List<SearchIndexableRaw> indexRaws = new ArrayList<>(); |
| 106 | final UserManager userManager = (UserManager) context.getSystemService( |
| 107 | Context.USER_SERVICE); |
| 108 | final List<UserInfo> profiles = userManager.getProfiles(UserHandle.myUserId()); |
| 109 | for (final UserInfo userInfo : profiles) { |
| 110 | if (userInfo.isManagedProfile()) { |
| 111 | return indexRaws; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | final AccountManager accountManager = AccountManager.get(context); |
| 116 | final Account[] accounts = accountManager.getAccounts(); |
| 117 | for (Account account : accounts) { |
| 118 | final SearchIndexableRaw raw = new SearchIndexableRaw(context); |
| 119 | raw.key = AccountTypePreference.buildKey(account); |
| 120 | raw.title = account.name; |
| 121 | indexRaws.add(raw); |
| 122 | } |
| 123 | |
| 124 | return indexRaws; |
Stanley Wang | 8015cba | 2019-11-27 10:39:59 +0800 | [diff] [blame] | 125 | } |
Fan Zhang | 6e88635 | 2016-12-05 14:42:49 -0800 | [diff] [blame] | 126 | }; |
Stanley Wang | 8015cba | 2019-11-27 10:39:59 +0800 | [diff] [blame] | 127 | } |