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