• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.settings.nfc;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.content.pm.UserInfo;
23 import android.os.Bundle;
24 import android.os.UserHandle;
25 import android.os.UserManager;
26 import android.view.View;
27 import android.view.ViewGroup;
28 
29 import androidx.annotation.VisibleForTesting;
30 import androidx.preference.Preference;
31 import androidx.preference.PreferenceScreen;
32 
33 import com.android.internal.hidden_from_bootclasspath.android.permission.flags.Flags;
34 import com.android.settings.R;
35 import com.android.settings.dashboard.DashboardFragment;
36 import com.android.settings.search.BaseSearchIndexProvider;
37 import com.android.settingslib.core.AbstractPreferenceController;
38 import com.android.settingslib.core.lifecycle.Lifecycle;
39 import com.android.settingslib.search.SearchIndexable;
40 
41 import java.util.ArrayList;
42 import java.util.List;
43 
44 @SearchIndexable
45 public class PaymentSettings extends DashboardFragment {
46     public static final String TAG = "PaymentSettings";
47 
48     private PaymentBackend mPaymentBackend;
49 
50     @Override
getLogTag()51     protected String getLogTag() {
52         return TAG;
53     }
54 
55     @Override
getMetricsCategory()56     public int getMetricsCategory() {
57         return SettingsEnums.NFC_PAYMENT;
58     }
59 
60     @Override
getPreferenceScreenResId()61     protected int getPreferenceScreenResId() {
62         return R.xml.nfc_payment_settings;
63     }
64 
65     @Override
createPreferenceControllers(Context context)66     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
67         return buildPreferenceControllers(context, getSettingsLifecycle());
68     }
69 
buildPreferenceControllers(Context context, Lifecycle lifecycle)70     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
71             Lifecycle lifecycle) {
72         final List<AbstractPreferenceController> controllers = new ArrayList<>();
73         controllers.add(new NfcDefaultPaymentPreferenceController(context, lifecycle));
74 
75         return controllers;
76     }
77 
78     @Override
onAttach(Context context)79     public void onAttach(Context context) {
80         super.onAttach(context);
81         mPaymentBackend = new PaymentBackend(getActivity());
82 
83         use(NfcForegroundPreferenceController.class).setPaymentBackend(mPaymentBackend);
84     }
85 
86     @Override
onViewCreated(View view, Bundle savedInstanceState)87     public void onViewCreated(View view, Bundle savedInstanceState) {
88         super.onViewCreated(view, savedInstanceState);
89         if (isShowEmptyImage(getPreferenceScreen())) {
90             View emptyView = getActivity().getLayoutInflater().inflate(
91                     R.layout.nfc_payment_empty, null, false);
92             ((ViewGroup) view.findViewById(android.R.id.list_container)).addView(emptyView);
93         }
94     }
95 
96     @Override
onResume()97     public void onResume() {
98         super.onResume();
99         mPaymentBackend.onResume();
100     }
101 
102     @Override
onPause()103     public void onPause() {
104         super.onPause();
105         mPaymentBackend.onPause();
106     }
107 
108     @VisibleForTesting
isShowEmptyImage(PreferenceScreen screen)109     boolean isShowEmptyImage(PreferenceScreen screen) {
110         for (int i = 0; i < screen.getPreferenceCount(); i++) {
111             final Preference preference = screen.getPreference(i);
112             if(preference.isVisible()) {
113                 return false;
114             }
115         }
116         return true;
117     }
118 
119     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
120             new BaseSearchIndexProvider(R.xml.nfc_payment_settings) {
121 
122                 @Override
123                 protected boolean isPageSearchEnabled(Context context) {
124                     if (Flags.walletRoleEnabled()) {
125                         return false;
126                     }
127                     final UserManager userManager = context.getSystemService(UserManager.class);
128                     final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
129                     if (myUserInfo.isGuest()) {
130                         return false;
131                     }
132                     final PackageManager pm = context.getPackageManager();
133                     return pm.hasSystemFeature(PackageManager.FEATURE_NFC);
134                 }
135             };
136 }
137