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.handheld; 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.annotation.StringRes; 26 import androidx.preference.PreferenceFragmentCompat; 27 28 import com.android.permissioncontroller.R; 29 30 /** 31 * Handheld fragment for a default app. 32 */ 33 public class HandheldDefaultAppFragment extends SettingsFragment 34 implements HandheldDefaultAppPreferenceFragment.Parent { 35 36 @NonNull 37 private String mRoleName; 38 @NonNull 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 * 47 * @return a new instance of this fragment 48 */ 49 @NonNull newInstance(@onNull String roleName, @NonNull UserHandle user)50 public static HandheldDefaultAppFragment newInstance(@NonNull String roleName, 51 @NonNull UserHandle user) { 52 HandheldDefaultAppFragment fragment = new HandheldDefaultAppFragment(); 53 Bundle arguments = new Bundle(); 54 arguments.putString(Intent.EXTRA_ROLE_NAME, roleName); 55 arguments.putParcelable(Intent.EXTRA_USER, user); 56 fragment.setArguments(arguments); 57 return fragment; 58 } 59 60 @Override onCreate(@ullable Bundle savedInstanceState)61 public void onCreate(@Nullable Bundle savedInstanceState) { 62 super.onCreate(savedInstanceState); 63 64 Bundle arguments = getArguments(); 65 mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME); 66 mUser = arguments.getParcelable(Intent.EXTRA_USER); 67 } 68 69 @NonNull 70 @Override onCreatePreferenceFragment()71 protected PreferenceFragmentCompat onCreatePreferenceFragment() { 72 return HandheldDefaultAppPreferenceFragment.newInstance(mRoleName, mUser); 73 } 74 75 @Override 76 @StringRes getEmptyTextResource()77 protected int getEmptyTextResource() { 78 return R.string.default_app_no_apps; 79 } 80 } 81