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.users; 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 import android.view.View; 26 import android.widget.Button; 27 28 import androidx.annotation.LayoutRes; 29 import androidx.annotation.XmlRes; 30 31 import com.android.car.settings.R; 32 import com.android.car.settings.common.SettingsFragment; 33 34 /** 35 * This screen appears after the last admin on the device tries to delete themselves. (but only if 36 * there are other users on the device) 37 * 38 * <p> It lets the Admin see a list of non-Admins on the device and choose a user from the list to 39 * upgrade to Admin. 40 * 41 * <p> After new admin has been selected and upgraded, the old Admin is removed. 42 */ 43 public class ChooseNewAdminFragment extends SettingsFragment { 44 45 /** 46 * Creates a new instance of {@link ChooseNewAdminFragment} that enables the last remaining 47 * admin to choose a new Admin from a list of Non-Admins. 48 * 49 * @param adminInfo Admin that will get removed after new admin has been designated. 50 */ newInstance(UserInfo adminInfo)51 public static ChooseNewAdminFragment newInstance(UserInfo adminInfo) { 52 ChooseNewAdminFragment usersListFragment = new ChooseNewAdminFragment(); 53 Bundle bundle = new Bundle(); 54 bundle.putParcelable(Intent.EXTRA_USER, adminInfo); 55 usersListFragment.setArguments(bundle); 56 return usersListFragment; 57 } 58 59 @Override 60 @XmlRes getPreferenceScreenResId()61 protected int getPreferenceScreenResId() { 62 return R.xml.choose_new_admin_fragment; 63 } 64 65 @Override 66 @LayoutRes getActionBarLayoutId()67 protected int getActionBarLayoutId() { 68 return R.layout.action_bar_with_button; 69 } 70 71 @Override onAttach(Context context)72 public void onAttach(Context context) { 73 super.onAttach(context); 74 UserInfo adminInfo = requireNonNull(getArguments()).getParcelable( 75 Intent.EXTRA_USER); 76 use(ChooseNewAdminPreferenceController.class, R.string.pk_choose_new_admin).setAdminInfo( 77 adminInfo); 78 } 79 80 @Override onActivityCreated(Bundle savedInstanceState)81 public void onActivityCreated(Bundle savedInstanceState) { 82 super.onActivityCreated(savedInstanceState); 83 84 Button cancelBtn = getActivity().findViewById(R.id.action_button1); 85 cancelBtn.setVisibility(View.VISIBLE); 86 cancelBtn.setText(R.string.cancel); 87 cancelBtn.setOnClickListener(v -> getActivity().onBackPressed()); 88 } 89 } 90