• 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.car.settings.profiles;
18 
19 import static java.util.Objects.requireNonNull;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.content.pm.UserInfo;
24 import android.os.Bundle;
25 
26 import androidx.annotation.XmlRes;
27 
28 import com.android.car.settings.R;
29 import com.android.car.settings.common.SettingsFragment;
30 
31 /**
32  * This screen appears after the last admin on the device tries to delete themselves. (but only if
33  * there are other profiles on the device)
34  *
35  * <p> It lets the Admin see a list of non-Admins on the device and choose a profile from the list
36  * to upgrade to Admin.
37  *
38  * <p> After new admin has been selected and upgraded, the old Admin is removed.
39  */
40 public class ChooseNewAdminFragment extends SettingsFragment {
41 
42     /**
43      * Creates a new instance of {@link ChooseNewAdminFragment} that enables the last remaining
44      * admin to choose a new Admin from a list of Non-Admins.
45      *
46      * @param adminInfo Admin that will get removed after new admin has been designated.
47      */
newInstance(UserInfo adminInfo)48     public static ChooseNewAdminFragment newInstance(UserInfo adminInfo) {
49         ChooseNewAdminFragment profilesListFragment = new ChooseNewAdminFragment();
50         Bundle bundle = new Bundle();
51         bundle.putParcelable(Intent.EXTRA_USER, adminInfo);
52         profilesListFragment.setArguments(bundle);
53         return profilesListFragment;
54     }
55 
56     @Override
57     @XmlRes
getPreferenceScreenResId()58     protected int getPreferenceScreenResId() {
59         return R.xml.choose_new_admin_fragment;
60     }
61 
62     @Override
onAttach(Context context)63     public void onAttach(Context context) {
64         super.onAttach(context);
65         UserInfo adminInfo = requireNonNull(getArguments()).getParcelable(
66                 Intent.EXTRA_USER);
67         use(ChooseNewAdminPreferenceController.class, R.string.pk_choose_new_admin).setAdminInfo(
68                 adminInfo);
69     }
70 }
71