• 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 android.content.Context;
20 import android.os.Bundle;
21 import android.os.UserHandle;
22 
23 import androidx.annotation.VisibleForTesting;
24 import androidx.annotation.XmlRes;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.applications.ApplicationPreferenceController;
28 import com.android.car.settings.common.PreferenceController;
29 import com.android.car.settings.common.SettingsFragment;
30 import com.android.settingslib.applications.ApplicationsState;
31 
32 import java.util.ArrayList;
33 import java.util.List;
34 
35 /** Settings screen to show details about launching a specific app. */
36 public class ApplicationLaunchSettingsFragmentUpdated extends SettingsFragment implements
37         CarDomainVerificationManager.DomainVerificationStateChangeListener {
38 
39     @VisibleForTesting
40     static final String ARG_PACKAGE_NAME = "arg_package_name";
41 
42     private ApplicationsState mState;
43     private ApplicationsState.AppEntry mAppEntry;
44     private List<PreferenceController> mLinksListControllers = new ArrayList<>();
45 
46     /** Creates a new instance of this fragment for the package specified in the arguments. */
newInstance(String pkg)47     public static ApplicationLaunchSettingsFragmentUpdated newInstance(String pkg) {
48         ApplicationLaunchSettingsFragmentUpdated fragment =
49                 new ApplicationLaunchSettingsFragmentUpdated();
50         Bundle args = new Bundle();
51         args.putString(ARG_PACKAGE_NAME, pkg);
52         fragment.setArguments(args);
53         return fragment;
54     }
55 
56     @Override
57     @XmlRes
getPreferenceScreenResId()58     protected int getPreferenceScreenResId() {
59         return R.xml.application_launch_settings_fragment_updated;
60     }
61 
62     @Override
onAttach(Context context)63     public void onAttach(Context context) {
64         super.onAttach(context);
65 
66         mState = ApplicationsState.getInstance(requireActivity().getApplication());
67 
68         String pkgName = getArguments().getString(ARG_PACKAGE_NAME);
69         mAppEntry = mState.getEntry(pkgName, UserHandle.myUserId());
70 
71         use(ApplicationPreferenceController.class,
72                 R.string.pk_opening_links_app_details)
73                 .setAppEntry(mAppEntry).setAppState(mState);
74 
75         OpenLinksSwitchPreferenceController openLinksSwitchPreferenceController =
76                 use(OpenLinksSwitchPreferenceController.class,
77                         R.string.pk_opening_links_app_toggle);
78         openLinksSwitchPreferenceController.setAppEntry(mAppEntry);
79         openLinksSwitchPreferenceController.setDomainVerificationStateListener(this);
80 
81         VerifiedLinksPreferenceController verifiedLinksPreferenceController =
82                 use(VerifiedLinksPreferenceController.class,
83                         R.string.pk_opening_links_verified_links);
84         verifiedLinksPreferenceController.setAppEntry(mAppEntry);
85         mLinksListControllers.add(verifiedLinksPreferenceController);
86 
87         SelectedLinksListPreferenceController selectedLinksListPreferenceController =
88                 use(SelectedLinksListPreferenceController.class,
89                         R.string.pk_opening_links_supported_links);
90         selectedLinksListPreferenceController.setAppEntry(mAppEntry);
91         mLinksListControllers.add(selectedLinksListPreferenceController);
92 
93         AddLinksListPreferenceController addLinksListPreferenceController =
94                 use(AddLinksListPreferenceController.class,
95                         R.string.pk_opening_links_add_links);
96         addLinksListPreferenceController.setAppEntry(mAppEntry);
97         mLinksListControllers.add(addLinksListPreferenceController);
98     }
99 
100     @Override
onDomainVerificationStateChanged()101     public void onDomainVerificationStateChanged() {
102         for (PreferenceController controller : mLinksListControllers) {
103             controller.refreshUi();
104         }
105     }
106 }
107