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.permissioncontroller.role.ui.auto; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.os.UserHandle; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.preference.Preference; 26 27 import com.android.permissioncontroller.R; 28 import com.android.permissioncontroller.auto.AutoSettingsFrameFragment; 29 import com.android.permissioncontroller.role.ui.DefaultAppChildFragment; 30 import com.android.permissioncontroller.role.ui.RoleApplicationPreference; 31 import com.android.role.controller.model.Role; 32 33 /** Screen to pick a default app for a particular {@link Role}. */ 34 public class AutoDefaultAppFragment extends AutoSettingsFrameFragment implements 35 DefaultAppChildFragment.Parent { 36 37 private String mRoleName; 38 39 private UserHandle mUser; 40 41 /** 42 * Create a new instance of this fragment. 43 * 44 * @param roleName the name of the role for the default app 45 * @param user the user for the default app 46 * @return a new instance of this fragment 47 */ 48 @NonNull newInstance(@onNull String roleName, @NonNull UserHandle user)49 public static AutoDefaultAppFragment newInstance(@NonNull String roleName, 50 @NonNull UserHandle user) { 51 AutoDefaultAppFragment fragment = new AutoDefaultAppFragment(); 52 Bundle arguments = new Bundle(); 53 arguments.putString(Intent.EXTRA_ROLE_NAME, roleName); 54 arguments.putParcelable(Intent.EXTRA_USER, user); 55 fragment.setArguments(arguments); 56 return fragment; 57 } 58 59 @Override onCreate(@ullable Bundle savedInstanceState)60 public void onCreate(@Nullable Bundle savedInstanceState) { 61 super.onCreate(savedInstanceState); 62 63 Bundle arguments = getArguments(); 64 mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME); 65 mUser = arguments.getParcelable(Intent.EXTRA_USER); 66 } 67 68 @Override onCreatePreferences(Bundle bundle, String s)69 public void onCreatePreferences(Bundle bundle, String s) { 70 // Preferences will be added via shared logic in {@link DefaultAppChildFragment}. 71 } 72 73 @Override onActivityCreated(@ullable Bundle savedInstanceState)74 public void onActivityCreated(@Nullable Bundle savedInstanceState) { 75 super.onActivityCreated(savedInstanceState); 76 77 if (savedInstanceState == null) { 78 DefaultAppChildFragment fragment = DefaultAppChildFragment.newInstance(mRoleName, 79 mUser); 80 getChildFragmentManager().beginTransaction() 81 .add(fragment, null) 82 .commit(); 83 } 84 } 85 86 @Override setTitle(@onNull CharSequence title)87 public void setTitle(@NonNull CharSequence title) { 88 setHeaderLabel(title); 89 } 90 91 @NonNull 92 @Override createApplicationPreference()93 public RoleApplicationPreference createApplicationPreference() { 94 return new AutoRadioPreference(requireContext()); 95 } 96 97 @NonNull 98 @Override createFooterPreference()99 public Preference createFooterPreference() { 100 Preference preference = new Preference(requireContext()); 101 preference.setIcon(R.drawable.ic_info_outline); 102 preference.setSelectable(false); 103 return preference; 104 } 105 106 @Override onPreferenceScreenChanged()107 public void onPreferenceScreenChanged() { 108 } 109 } 110