• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.settings.applications.managedomainurls;
18 
19 import android.car.drivingstate.CarUxRestrictions;
20 import android.content.Context;
21 import android.util.ArraySet;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.ConfirmationDialogFragment;
27 import com.android.car.settings.common.FragmentController;
28 
29 /** Business logic to generate and see the list of supported domain urls. */
30 public class DomainUrlsPreferenceController extends
31         AppLaunchSettingsBasePreferenceController<Preference> {
32 
33     private ArraySet<String> mDomains;
34 
DomainUrlsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)35     public DomainUrlsPreferenceController(Context context, String preferenceKey,
36             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
37         super(context, preferenceKey, fragmentController, uxRestrictions);
38     }
39 
40     @Override
getPreferenceType()41     protected Class<Preference> getPreferenceType() {
42         return Preference.class;
43     }
44 
45     @Override
onCreateInternal()46     protected void onCreateInternal() {
47         mDomains = DomainUrlsUtils.getHandledDomains(getContext().getPackageManager(),
48                 getPackageName());
49     }
50 
51     @Override
updateState(Preference preference)52     protected void updateState(Preference preference) {
53         boolean hasDomains = mDomains != null && mDomains.size() > 0;
54         preference.setEnabled(!isBrowserApp() && hasDomains);
55         preference.setSummary(
56                 DomainUrlsUtils.getDomainsSummary(getContext(), getPackageName(),
57                         getCurrentUserId(), mDomains));
58     }
59 
60     @Override
handlePreferenceClicked(Preference preference)61     protected boolean handlePreferenceClicked(Preference preference) {
62         String newLines = System.lineSeparator() + System.lineSeparator();
63         String message = String.join(newLines, mDomains);
64 
65         // Not exactly a "confirmation" dialog, but reusing to remove the need for a custom
66         // dialog fragment.
67         ConfirmationDialogFragment dialogFragment = new ConfirmationDialogFragment.Builder(
68                 getContext())
69                 .setTitle(R.string.app_launch_supported_domain_urls_title)
70                 .setMessage(message)
71                 .setNegativeButton(android.R.string.cancel, /* rejectListener= */ null)
72                 .build();
73         getFragmentController().showDialog(dialogFragment, ConfirmationDialogFragment.TAG);
74         return true;
75     }
76 }
77