• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.settings.applications.specialaccess.interactacrossprofiles;
18 
19 import android.content.Context;
20 import android.content.pm.CrossProfileApps;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settings.SettingsPreferenceFragment;
25 import com.android.settings.applications.appinfo.AppInfoPreferenceControllerBase;
26 
27 public class InteractAcrossProfilesDetailsPreferenceController
28         extends AppInfoPreferenceControllerBase {
29 
30     private String mPackageName;
31 
InteractAcrossProfilesDetailsPreferenceController(Context context, String key)32     public InteractAcrossProfilesDetailsPreferenceController(Context context, String key) {
33         super(context, key);
34     }
35 
36     @Override
getAvailabilityStatus()37     public int getAvailabilityStatus() {
38         return canUserAttemptToConfigureInteractAcrossProfiles() ? AVAILABLE : DISABLED_FOR_USER;
39     }
40 
41     @Override
updateState(Preference preference)42     public void updateState(Preference preference) {
43         preference.setSummary(getPreferenceSummary());
44     }
45 
46     @Override
getDetailFragmentClass()47     protected Class<? extends SettingsPreferenceFragment> getDetailFragmentClass() {
48         return InteractAcrossProfilesDetails.class;
49     }
50 
getPreferenceSummary()51     private CharSequence getPreferenceSummary() {
52         return InteractAcrossProfilesDetails.getPreferenceSummary(mContext, mPackageName);
53     }
54 
canUserAttemptToConfigureInteractAcrossProfiles()55     private boolean canUserAttemptToConfigureInteractAcrossProfiles() {
56         return mContext.getSystemService(CrossProfileApps.class)
57                 .canUserAttemptToConfigureInteractAcrossProfiles(mPackageName);
58     }
59 
setPackageName(String packageName)60     public void setPackageName(String packageName) {
61         mPackageName = packageName;
62     }
63 }
64