• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.settings.profiles;
18 
19 import android.car.drivingstate.CarUxRestrictions;
20 import android.content.Context;
21 import android.content.pm.UserInfo;
22 import android.os.UserManager;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 
27 import com.android.car.settings.common.FragmentController;
28 import com.android.car.settings.common.Logger;
29 
30 /**
31  * Controller that displays the preference for letting the user delete the current profile
32  */
33 public class ProfileDetailsDeletePreferenceController
34         extends ProfileDetailsBasePreferenceController<Preference> {
35 
36     private static final Logger LOG = new Logger(ProfileDetailsDeletePreferenceController.class);
37 
38     private ProfileHelper mProfileHelper;
39 
40     private final RemoveProfileHandler mRemoveProfileHandler;
41 
ProfileDetailsDeletePreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)42     public ProfileDetailsDeletePreferenceController(Context context, String preferenceKey,
43             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
44         this(context, preferenceKey, fragmentController, uxRestrictions,
45                 ProfileHelper.getInstance(context),
46                 new RemoveProfileHandler(context, ProfileHelper.getInstance(context),
47                         UserManager.get(context), fragmentController));
48     }
49 
50     @VisibleForTesting
ProfileDetailsDeletePreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions, ProfileHelper profileHelper, RemoveProfileHandler removeProfileHandler)51     ProfileDetailsDeletePreferenceController(Context context,
52             String preferenceKey, FragmentController fragmentController,
53             CarUxRestrictions uxRestrictions, ProfileHelper profileHelper,
54             RemoveProfileHandler removeProfileHandler) {
55         super(context, preferenceKey, fragmentController, uxRestrictions);
56         mProfileHelper = profileHelper;
57         mRemoveProfileHandler = removeProfileHandler;
58     }
59 
60     @Override
getPreferenceType()61     protected Class<Preference> getPreferenceType() {
62         return Preference.class;
63     }
64 
65     @Override
onCreateInternal()66     protected void onCreateInternal() {
67         super.onCreateInternal();
68         mRemoveProfileHandler.resetListeners();
69     }
70 
71     @Override
setUserInfo(UserInfo userInfo)72     public void setUserInfo(UserInfo userInfo) {
73         super.setUserInfo(userInfo);
74         mRemoveProfileHandler.setUserInfo(userInfo);
75     }
76 
77     @Override
updateState(Preference preference)78     protected void updateState(Preference preference) {
79         preference.setVisible(mRemoveProfileHandler.canRemoveProfile(getUserInfo())
80                 && mProfileHelper.isCurrentProcessUser(getUserInfo()));
81     }
82 
83     @Override
handlePreferenceClicked(Preference preference)84     public boolean handlePreferenceClicked(Preference preference) {
85         mRemoveProfileHandler.showConfirmRemoveProfileDialog();
86         return true;
87     }
88 }
89