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.userlib.CarUserManagerHelper;
20 import android.content.Context;
21 import android.os.Bundle;
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.common.SettingsFragment;
28 import com.android.settingslib.applications.ApplicationsState;
29 
30 import java.util.Arrays;
31 import java.util.List;
32 
33 /** Settings screen to show details about launching a specific app. */
34 public class ApplicationLaunchSettingsFragment extends SettingsFragment {
35 
36     @VisibleForTesting
37     static final String ARG_PACKAGE_NAME = "arg_package_name";
38 
39     private ApplicationsState mState;
40     private ApplicationsState.AppEntry mAppEntry;
41     private CarUserManagerHelper mCarUserManagerHelper;
42 
43     /** Creates a new instance of this fragment for the package specified in the arguments. */
newInstance(String pkg)44     public static ApplicationLaunchSettingsFragment newInstance(String pkg) {
45         ApplicationLaunchSettingsFragment fragment = new ApplicationLaunchSettingsFragment();
46         Bundle args = new Bundle();
47         args.putString(ARG_PACKAGE_NAME, pkg);
48         fragment.setArguments(args);
49         return fragment;
50     }
51 
52     @Override
53     @XmlRes
getPreferenceScreenResId()54     protected int getPreferenceScreenResId() {
55         return R.xml.application_launch_settings_fragment;
56     }
57 
58     @Override
onAttach(Context context)59     public void onAttach(Context context) {
60         super.onAttach(context);
61 
62         mCarUserManagerHelper = new CarUserManagerHelper(context);
63         mState = ApplicationsState.getInstance(requireActivity().getApplication());
64 
65         String pkgName = getArguments().getString(ARG_PACKAGE_NAME);
66         mAppEntry = mState.getEntry(pkgName, mCarUserManagerHelper.getCurrentProcessUserId());
67 
68         ApplicationWithVersionPreferenceController appController = use(
69                 ApplicationWithVersionPreferenceController.class,
70                 R.string.pk_opening_links_app_details);
71         appController.setAppState(mState);
72         appController.setAppEntry(mAppEntry);
73 
74         List<AppLaunchSettingsBasePreferenceController> preferenceControllers = Arrays.asList(
75                 use(AppLinkStatePreferenceController.class,
76                         R.string.pk_opening_links_app_details_state),
77                 use(DomainUrlsPreferenceController.class,
78                         R.string.pk_opening_links_app_details_urls),
79                 use(ClearDefaultsPreferenceController.class,
80                         R.string.pk_opening_links_app_details_reset));
81 
82         for (AppLaunchSettingsBasePreferenceController controller : preferenceControllers) {
83             controller.setAppEntry(mAppEntry);
84         }
85     }
86 }
87