• 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.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.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 
42     /** Creates a new instance of this fragment for the package specified in the arguments. */
newInstance(String pkg)43     public static ApplicationLaunchSettingsFragment newInstance(String pkg) {
44         ApplicationLaunchSettingsFragment fragment = new ApplicationLaunchSettingsFragment();
45         Bundle args = new Bundle();
46         args.putString(ARG_PACKAGE_NAME, pkg);
47         fragment.setArguments(args);
48         return fragment;
49     }
50 
51     @Override
52     @XmlRes
getPreferenceScreenResId()53     protected int getPreferenceScreenResId() {
54         return R.xml.application_launch_settings_fragment;
55     }
56 
57     @Override
onAttach(Context context)58     public void onAttach(Context context) {
59         super.onAttach(context);
60 
61         mState = ApplicationsState.getInstance(requireActivity().getApplication());
62 
63         String pkgName = getArguments().getString(ARG_PACKAGE_NAME);
64         mAppEntry = mState.getEntry(pkgName, UserHandle.myUserId());
65 
66         ApplicationWithVersionPreferenceController appController = use(
67                 ApplicationWithVersionPreferenceController.class,
68                 R.string.pk_opening_links_app_details);
69         appController.setAppState(mState);
70         appController.setAppEntry(mAppEntry);
71 
72         List<AppLaunchSettingsBasePreferenceController> preferenceControllers = Arrays.asList(
73                 use(AppLinkStatePreferenceController.class,
74                         R.string.pk_opening_links_app_details_state),
75                 use(DomainUrlsPreferenceController.class,
76                         R.string.pk_opening_links_app_details_urls),
77                 use(ClearDefaultsPreferenceController.class,
78                         R.string.pk_opening_links_app_details_reset));
79 
80         for (AppLaunchSettingsBasePreferenceController controller : preferenceControllers) {
81             controller.setAppEntry(mAppEntry);
82         }
83     }
84 }
85