1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.settings.enterprise;
16 
17 import static android.app.admin.DevicePolicyResources.Strings.Settings.ADMIN_ACTION_SET_INPUT_METHOD_NAME;
18 
19 import android.app.admin.DevicePolicyManager;
20 import android.content.Context;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settings.R;
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settings.overlay.FeatureFactory;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 
29 public class ImePreferenceController extends AbstractPreferenceController implements
30         PreferenceControllerMixin {
31 
32     private static final String KEY_INPUT_METHOD = "input_method";
33     private final EnterprisePrivacyFeatureProvider mFeatureProvider;
34 
ImePreferenceController(Context context)35     public ImePreferenceController(Context context) {
36         super(context);
37         mFeatureProvider = FeatureFactory.getFeatureFactory()
38                 .getEnterprisePrivacyFeatureProvider();
39     }
40 
41     @Override
updateState(Preference preference)42     public void updateState(Preference preference) {
43         preference.setSummary(
44                 mContext.getSystemService(DevicePolicyManager.class).getResources()
45                         .getString(ADMIN_ACTION_SET_INPUT_METHOD_NAME, () ->
46                                 mContext.getResources().getString(
47                                         R.string.enterprise_privacy_input_method_name,
48                                         mFeatureProvider.getImeLabelIfOwnerSet()),
49                                 mFeatureProvider.getImeLabelIfOwnerSet()));
50     }
51 
52     @Override
isAvailable()53     public boolean isAvailable() {
54         return mFeatureProvider.getImeLabelIfOwnerSet() != null;
55     }
56 
57     @Override
getPreferenceKey()58     public String getPreferenceKey() {
59         return KEY_INPUT_METHOD;
60     }
61 }
62