1 /* 2 * Copyright (C) 2019 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.car.developeroptions.privacy; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.provider.SearchIndexableResource; 23 import android.view.View; 24 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.car.developeroptions.R; 28 import com.android.car.developeroptions.Utils; 29 import com.android.car.developeroptions.dashboard.DashboardFragment; 30 import com.android.car.developeroptions.notification.LockScreenNotificationPreferenceController; 31 import com.android.car.developeroptions.search.BaseSearchIndexProvider; 32 import com.android.settingslib.core.AbstractPreferenceController; 33 import com.android.settingslib.core.lifecycle.Lifecycle; 34 import com.android.settingslib.search.SearchIndexable; 35 36 import java.util.ArrayList; 37 import java.util.List; 38 39 @SearchIndexable 40 public class PrivacyDashboardFragment extends DashboardFragment { 41 private static final String TAG = "PrivacyDashboardFrag"; 42 private static final String KEY_LOCK_SCREEN_NOTIFICATIONS = "privacy_lock_screen_notifications"; 43 private static final String KEY_WORK_PROFILE_CATEGORY = 44 "privacy_work_profile_notifications_category"; 45 private static final String KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS = 46 "privacy_lock_screen_work_profile_notifications"; 47 48 @VisibleForTesting 49 View mProgressHeader; 50 @VisibleForTesting 51 View mProgressAnimation; 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return SettingsEnums.TOP_LEVEL_PRIVACY; 56 } 57 58 @Override getLogTag()59 protected String getLogTag() { 60 return TAG; 61 } 62 63 @Override getPreferenceScreenResId()64 protected int getPreferenceScreenResId() { 65 return R.xml.privacy_dashboard_settings; 66 } 67 68 @Override getHelpResource()69 public int getHelpResource() { 70 return R.string.help_url_privacy_dashboard; 71 } 72 73 @Override createPreferenceControllers(Context context)74 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 75 return buildPreferenceControllers(context, getSettingsLifecycle()); 76 } 77 78 @Override onAttach(Context context)79 public void onAttach(Context context) { 80 super.onAttach(context); 81 use(PermissionBarChartPreferenceController.class).setFragment(this /* fragment */); 82 } 83 84 @Override onViewCreated(View view, Bundle savedInstanceState)85 public void onViewCreated(View view, Bundle savedInstanceState) { 86 super.onViewCreated(view, savedInstanceState); 87 Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(), getListView()); 88 initLoadingBar(); 89 } 90 91 @VisibleForTesting initLoadingBar()92 void initLoadingBar() { 93 mProgressHeader = setPinnedHeaderView(R.layout.progress_header); 94 mProgressAnimation = mProgressHeader.findViewById(R.id.progress_bar_animation); 95 setLoadingEnabled(false); 96 } 97 98 @VisibleForTesting setLoadingEnabled(boolean enabled)99 void setLoadingEnabled(boolean enabled) { 100 if (mProgressHeader != null && mProgressAnimation != null) { 101 mProgressHeader.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 102 mProgressAnimation.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 103 } 104 } 105 buildPreferenceControllers( Context context, Lifecycle lifecycle)106 private static List<AbstractPreferenceController> buildPreferenceControllers( 107 Context context, Lifecycle lifecycle) { 108 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 109 final LockScreenNotificationPreferenceController notificationController = 110 new LockScreenNotificationPreferenceController(context, 111 KEY_LOCK_SCREEN_NOTIFICATIONS, 112 KEY_WORK_PROFILE_CATEGORY, 113 KEY_NOTIFICATION_WORK_PROFILE_NOTIFICATIONS); 114 if (lifecycle != null) { 115 lifecycle.addObserver(notificationController); 116 } 117 controllers.add(notificationController); 118 119 return controllers; 120 121 } 122 123 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 124 new BaseSearchIndexProvider() { 125 @Override 126 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 127 boolean enabled) { 128 final ArrayList<SearchIndexableResource> result = new ArrayList<>(); 129 130 final SearchIndexableResource sir = new SearchIndexableResource(context); 131 sir.xmlResId = R.xml.privacy_dashboard_settings; 132 result.add(sir); 133 return result; 134 } 135 136 @Override 137 public List<AbstractPreferenceController> createPreferenceControllers( 138 Context context) { 139 return buildPreferenceControllers(context, null); 140 } 141 }; 142 } 143