• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.settings.deviceinfo;
17 
18 import android.content.Context;
19 import android.os.SELinux;
20 import android.os.SystemProperties;
21 import android.support.v7.preference.Preference;
22 import android.support.v7.preference.PreferenceScreen;
23 import android.text.TextUtils;
24 
25 import com.android.settings.R;
26 import com.android.settings.core.PreferenceController;
27 
28 public class SELinuxStatusPreferenceController extends PreferenceController {
29 
30     private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
31     private static final String KEY_SELINUX_STATUS = "selinux_status";
32 
SELinuxStatusPreferenceController(Context context)33     public SELinuxStatusPreferenceController(Context context) {
34         super(context);
35     }
36 
37     @Override
isAvailable()38     public boolean isAvailable() {
39         return !TextUtils.isEmpty(SystemProperties.get(PROPERTY_SELINUX_STATUS));
40     }
41 
42     @Override
getPreferenceKey()43     public String getPreferenceKey() {
44         return KEY_SELINUX_STATUS;
45     }
46 
47     @Override
displayPreference(PreferenceScreen screen)48     public void displayPreference(PreferenceScreen screen) {
49         super.displayPreference(screen);
50         final Preference pref = screen.findPreference(KEY_SELINUX_STATUS);
51         if (pref == null) {
52             return;
53         }
54         if (!SELinux.isSELinuxEnabled()) {
55             String status = mContext.getResources().getString(R.string.selinux_status_disabled);
56             pref.setSummary(status);
57         } else if (!SELinux.isSELinuxEnforced()) {
58             String status = mContext.getResources().getString(R.string.selinux_status_permissive);
59             pref.setSummary(status);
60         }
61     }
62 }
63 
64