1 /*
2  * Copyright (C) 2020 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 package com.android.settings.development;
17 
18 import android.content.Context;
19 import android.debug.PairDevice;
20 
21 import androidx.annotation.VisibleForTesting;
22 import androidx.fragment.app.Fragment;
23 import androidx.preference.PreferenceCategory;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settingslib.core.AbstractPreferenceController;
27 import com.android.settingslib.widget.FooterPreference;
28 
29 /**
30  * Controller for logic pertaining to displaying adb device information for the
31  * {@link AdbDeviceDetailsFragment}.
32  */
33 public class AdbDeviceDetailsFingerprintController extends AbstractPreferenceController {
34 
35     private static final String TAG = "AdbDeviceDetailsFinger";
36 
37     @VisibleForTesting
38     static final String KEY_FINGERPRINT_CATEGORY = "fingerprint_category";
39 
40     private PairDevice mPairedDevice;
41     private final Fragment mFragment;
42 
43     private PreferenceCategory mFingerprintCategory;
44     private FooterPreference mFingerprintPref;
45 
AdbDeviceDetailsFingerprintController( PairDevice pairedDevice, Context context, Fragment fragment)46     public AdbDeviceDetailsFingerprintController(
47             PairDevice pairedDevice,
48             Context context,
49             Fragment fragment) {
50         super(context);
51 
52         mPairedDevice = pairedDevice;
53         mFragment = fragment;
54     }
55 
56     @Override
isAvailable()57     public boolean isAvailable() {
58         return true;
59     }
60 
61     @Override
getPreferenceKey()62     public String getPreferenceKey() {
63         return KEY_FINGERPRINT_CATEGORY;
64     }
65 
66     @Override
displayPreference(PreferenceScreen screen)67     public void displayPreference(PreferenceScreen screen) {
68         super.displayPreference(screen);
69 
70         mFingerprintCategory = (PreferenceCategory) screen.findPreference(getPreferenceKey());
71         mFingerprintPref = new FooterPreference(mFingerprintCategory.getContext());
72         final CharSequence titleFormat = mContext.getText(
73                 com.android.settingslib.R.string.adb_device_fingerprint_title_format);
74         mFingerprintPref.setTitle(String.format(
75                 titleFormat.toString(), mPairedDevice.guid));
76         mFingerprintCategory.addPreference(mFingerprintPref);
77     }
78 }
79 
80