• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.applications.managedomainurls;
18 
19 import static android.content.pm.verify.domain.DomainVerificationUserState.DOMAIN_STATE_VERIFIED;
20 
21 import android.car.drivingstate.CarUxRestrictions;
22 import android.content.Context;
23 
24 import com.android.car.settings.R;
25 import com.android.car.settings.common.FragmentController;
26 import com.android.car.settings.common.Logger;
27 import com.android.car.ui.preference.CarUiPreference;
28 import com.android.settingslib.utils.StringUtil;
29 
30 /**
31  * Controls for the verified links preference.
32  */
33 public class VerifiedLinksPreferenceController extends
34         AppLaunchSettingsBasePreferenceController<CarUiPreference> {
35     private static final Logger LOG = new Logger(VerifiedLinksPreferenceController.class);
36 
VerifiedLinksPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)37     public VerifiedLinksPreferenceController(Context context, String preferenceKey,
38             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
39         super(context, preferenceKey, fragmentController, uxRestrictions);
40     }
41 
42     @Override
getPreferenceType()43     protected Class<CarUiPreference> getPreferenceType() {
44         return CarUiPreference.class;
45     }
46 
47     @Override
getDefaultAvailabilityStatus()48     protected int getDefaultAvailabilityStatus() {
49         if (isLinkHandlingEnabled() && getLinksNumber(DOMAIN_STATE_VERIFIED) > 0) {
50             return AVAILABLE;
51         }
52         return CONDITIONALLY_UNAVAILABLE;
53     }
54 
55     @Override
updateState(CarUiPreference preference)56     protected void updateState(CarUiPreference preference) {
57         super.updateState(preference);
58         preference.setSummary(
59                 StringUtil.getIcuPluralsString(getContext(), getLinksNumber(DOMAIN_STATE_VERIFIED),
60                         R.string.opening_links_verified_links_summary));
61     }
62 
63     @Override
handlePreferenceClicked(CarUiPreference preference)64     protected boolean handlePreferenceClicked(CarUiPreference preference) {
65         getFragmentController().launchFragment(
66                 VerifiedLinksFragment.newInstance(getPackageName()));
67         return true;
68     }
69 }
70