1 /*
2  * Copyright (C) 2017 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.backup;
18 
19 
20 import android.content.Context;
21 import android.content.Intent;
22 
23 import androidx.preference.Preference;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 
29 public class BackupSettingsPreferenceController extends AbstractPreferenceController
30         implements PreferenceControllerMixin {
31     private static final String BACKUP_SETTINGS = "backup_settings";
32     private static final  String MANUFACTURER_SETTINGS = "manufacturer_backup";
33     private Intent mBackupSettingsIntent;
34     private CharSequence mBackupSettingsTitle;
35     private String mBackupSettingsSummary;
36     private Intent mManufacturerIntent;
37     private String mManufacturerLabel;
38 
BackupSettingsPreferenceController(Context context)39     public BackupSettingsPreferenceController(Context context) {
40         super(context);
41         BackupSettingsHelper settingsHelper = new BackupSettingsHelper(context);
42         mBackupSettingsIntent = settingsHelper.getIntentForBackupSettings();
43         mBackupSettingsTitle = settingsHelper.getLabelForBackupSettings();
44         mBackupSettingsSummary = settingsHelper.getSummaryForBackupSettings();
45         mManufacturerIntent = settingsHelper.getIntentProvidedByManufacturer();
46         mManufacturerLabel = settingsHelper.getLabelProvidedByManufacturer();
47     }
48 
49     @Override
displayPreference(PreferenceScreen screen)50     public void displayPreference(PreferenceScreen screen) {
51         Preference backupSettings = screen.findPreference(BACKUP_SETTINGS);
52         Preference manufacturerSettings = screen.findPreference(MANUFACTURER_SETTINGS);
53         backupSettings.setIntent(mBackupSettingsIntent);
54         backupSettings.setTitle(mBackupSettingsTitle);
55         backupSettings.setSummary(mBackupSettingsSummary);
56         manufacturerSettings.setIntent(mManufacturerIntent);
57         manufacturerSettings.setTitle(mManufacturerLabel);
58     }
59 
60     /**
61      * Returns true if preference is available (should be displayed)
62      */
63     @Override
isAvailable()64     public boolean isAvailable() {
65         return true;
66     }
67 
68     /**
69      * Returns the key for this preference.
70      */
71     @Override
getPreferenceKey()72     public String getPreferenceKey() {
73         return null;
74     }
75 }
76