• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.Nullable;
25 import androidx.preference.Preference;
26 import androidx.preference.SwitchPreference;
27 import androidx.preference.TwoStatePreference;
28 
29 import com.android.permissioncontroller.R;
30 import com.android.permissioncontroller.auto.AutoSettingsFrameFragment;
31 import com.android.permissioncontroller.role.ui.specialappaccess.SpecialAppAccessChildFragment;
32 
33 /** Automotive fragment for displaying special app access for a role. */
34 public class AutoSpecialAppAccessFragment extends AutoSettingsFrameFragment implements
35         SpecialAppAccessChildFragment.Parent {
36 
37     private String mRoleName;
38 
39     /**
40      * Returns a new instance of {@link AutoSpecialAppAccessFragment} for the given {@code
41      * roleName}.
42      */
43     @NonNull
newInstance(@onNull String roleName)44     public static AutoSpecialAppAccessFragment newInstance(@NonNull String roleName) {
45         AutoSpecialAppAccessFragment fragment = new AutoSpecialAppAccessFragment();
46         Bundle arguments = new Bundle();
47         arguments.putString(Intent.EXTRA_ROLE_NAME, roleName);
48         fragment.setArguments(arguments);
49         return fragment;
50     }
51 
52     @Override
onCreate(@ullable Bundle savedInstanceState)53     public void onCreate(@Nullable Bundle savedInstanceState) {
54         super.onCreate(savedInstanceState);
55 
56         Bundle arguments = getArguments();
57         mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME);
58     }
59 
60     @Override
onCreatePreferences(Bundle bundle, String s)61     public void onCreatePreferences(Bundle bundle, String s) {
62         // Preferences will be added by the child fragment.
63     }
64 
65     @Override
onActivityCreated(@ullable Bundle savedInstanceState)66     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
67         super.onActivityCreated(savedInstanceState);
68 
69         if (savedInstanceState == null) {
70             SpecialAppAccessChildFragment fragment = SpecialAppAccessChildFragment.newInstance(
71                     mRoleName);
72             getChildFragmentManager().beginTransaction()
73                     .add(fragment, null)
74                     .commit();
75         }
76     }
77 
78     @Override
setTitle(@onNull CharSequence title)79     public void setTitle(@NonNull CharSequence title) {
80         setHeaderLabel(title);
81     }
82 
83     @NonNull
84     @Override
createApplicationPreference(@onNull Context context)85     public TwoStatePreference createApplicationPreference(@NonNull Context context) {
86         return new SwitchPreference(context);
87     }
88 
89     @NonNull
90     @Override
createFooterPreference(@onNull Context context)91     public Preference createFooterPreference(@NonNull Context context) {
92         Preference preference = new Preference(context);
93         preference.setIcon(R.drawable.ic_info_outline);
94         preference.setSelectable(false);
95         return preference;
96     }
97 
98     @Override
onPreferenceScreenChanged()99     public void onPreferenceScreenChanged() {
100     }
101 }
102