• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.display;
18 
19 import android.content.Context;
20 import android.os.UserHandle;
21 import android.provider.Settings;
22 import android.service.quickaccesswallet.QuickAccessWalletClient;
23 
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 
27 import com.android.internal.widget.LockPatternUtils;
28 import com.android.settings.R;
29 import com.android.settings.core.TogglePreferenceController;
30 import com.android.settings.overlay.FeatureFactory;
31 
32 /**
33  * Preference for showing/hiding sensitive wallet content while the device is locked.
34  */
35 public class WalletPrivacyPreferenceController extends TogglePreferenceController {
36 
37     private static final String SETTING_KEY = Settings.Secure.LOCKSCREEN_SHOW_WALLET;
38     private final QuickAccessWalletClient mClient;
39 
WalletPrivacyPreferenceController(Context context, String preferenceKey)40     public WalletPrivacyPreferenceController(Context context, String preferenceKey) {
41         super(context, preferenceKey);
42         mClient = initWalletClient();
43     }
44 
45     @Override
isChecked()46     public boolean isChecked() {
47         return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 0) != 0;
48     }
49 
50     @Override
setChecked(boolean isChecked)51     public boolean setChecked(boolean isChecked) {
52         return Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY,
53                 isChecked ? 1 : 0);
54     }
55 
56     @Override
getSummary()57     public CharSequence getSummary() {
58         final int res = isSecure() ? R.string.lockscreen_privacy_wallet_summary :
59                 R.string.lockscreen_privacy_not_secure;
60         return mContext.getText(res);
61     }
62 
63     @Override
getAvailabilityStatus()64     public int getAvailabilityStatus() {
65         return isEnabled() && isSecure() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
66     }
67 
68     @Override
updateState(Preference preference)69     public void updateState(Preference preference) {
70         super.updateState(preference);
71         preference.setEnabled(getAvailabilityStatus() != DISABLED_DEPENDENT_SETTING);
72         refreshSummary(preference);
73     }
74 
isEnabled()75     private boolean isEnabled() {
76         return mClient.isWalletServiceAvailable();
77     }
78 
isSecure()79     private boolean isSecure() {
80         final LockPatternUtils utils = FeatureFactory.getFactory(mContext)
81                 .getSecurityFeatureProvider()
82                 .getLockPatternUtils(mContext);
83         int userId = UserHandle.myUserId();
84         return utils.isSecure(userId);
85     }
86 
87     @VisibleForTesting
initWalletClient()88     QuickAccessWalletClient initWalletClient() {
89         return QuickAccessWalletClient.create(mContext);
90     }
91 }
92