1 /*
2  * Copyright (C) 2017 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.system;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.Intent;
22 
23 import androidx.annotation.Nullable;
24 
25 import com.android.settings.R;
26 import com.android.settings.applications.manageapplications.ResetAppPrefPreferenceController;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.network.EraseEuiccDataController;
29 import com.android.settings.network.NetworkResetPreferenceController;
30 import com.android.settings.network.SubscriptionUtil;
31 import com.android.settings.privatespace.delete.ResetOptionsDeletePrivateSpaceController;
32 import com.android.settings.search.BaseSearchIndexProvider;
33 import com.android.settingslib.core.AbstractPreferenceController;
34 import com.android.settingslib.core.lifecycle.Lifecycle;
35 import com.android.settingslib.search.SearchIndexable;
36 
37 import java.util.ArrayList;
38 import java.util.List;
39 
40 /** Settings fragment containing reset options. */
41 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
42 public class ResetDashboardFragment extends DashboardFragment {
43 
44     private static final String TAG = "ResetDashboardFragment";
45     public static final int PRIVATE_SPACE_DELETE_CREDENTIAL_REQUEST = 1;
46 
47     @Override
getMetricsCategory()48     public int getMetricsCategory() {
49         return SettingsEnums.RESET_DASHBOARD;
50     }
51 
52     @Override
getLogTag()53     protected String getLogTag() {
54         return TAG;
55     }
56 
57     @Override
getPreferenceScreenResId()58     protected int getPreferenceScreenResId() {
59         return R.xml.reset_dashboard_fragment;
60     }
61 
62     @Override
createPreferenceControllers(Context context)63     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
64         return buildPreferenceControllers(context, getSettingsLifecycle());
65     }
66 
67     @Override
onAttach(Context context)68     public void onAttach(Context context) {
69         super.onAttach(context);
70         if (SubscriptionUtil.isSimHardwareVisible(context)) {
71             use(EraseEuiccDataController.class).setFragment(this);
72         }
73         if (android.multiuser.Flags.enablePrivateSpaceFeatures()
74                 && android.multiuser.Flags.deletePrivateSpaceFromReset()) {
75             ResetOptionsDeletePrivateSpaceController resetOptionsDeletePrivateSpaceController =
76                     use(ResetOptionsDeletePrivateSpaceController.class);
77             if (resetOptionsDeletePrivateSpaceController != null) {
78                 resetOptionsDeletePrivateSpaceController.setFragment(this);
79             }
80         }
81         FactoryResetPreferenceController factoryResetPreferenceController =
82                 use(FactoryResetPreferenceController.class);
83         if (factoryResetPreferenceController != null) {
84             factoryResetPreferenceController.setFragment(this);
85         }
86     }
87 
88     @Override
shouldSkipForInitialSUW()89     protected boolean shouldSkipForInitialSUW() {
90         return true;
91     }
92 
buildPreferenceControllers(Context context, Lifecycle lifecycle)93     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
94             Lifecycle lifecycle) {
95         final List<AbstractPreferenceController> controllers = new ArrayList<>();
96         if (SubscriptionUtil.isSimHardwareVisible(context)) {
97             controllers.add(new NetworkResetPreferenceController(context));
98         }
99         controllers.add(new ResetAppPrefPreferenceController(context, lifecycle));
100         return controllers;
101     }
102 
103     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
104             new BaseSearchIndexProvider(R.xml.reset_dashboard_fragment) {
105 
106                 @Override
107                 public List<AbstractPreferenceController> createPreferenceControllers(
108                         Context context) {
109                     return buildPreferenceControllers(context, null /* lifecycle */);
110                 }
111             };
112 
113     @Override
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)114     public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
115         if (use(ResetOptionsDeletePrivateSpaceController.class)
116                 .handleActivityResult(requestCode, resultCode, data)) {
117             return;
118         }
119         super.onActivityResult(requestCode, resultCode, data);
120     }
121 }
122