Settings: add back selinux status in about

Change-Id: I7c2bf7a5ede1f64160d9c8180c07072cc7ba32f3
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
new file mode 100644
index 0000000..36dafcf
--- /dev/null
+++ b/res/values/custom_strings.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2017-2018 The OmniROM Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+    <string name="selinux_status">SELinux status</string>
+    <string name="selinux_status_disabled">Disabled</string>
+    <string name="selinux_status_permissive">Permissive</string>
+    <string name="selinux_status_enforcing">Enforcing</string>
+
+</resources>
diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml
index 1f402a8..3dc6b98 100644
--- a/res/xml/my_device_info.xml
+++ b/res/xml/my_device_info.xml
@@ -236,4 +236,11 @@
             settings:controller="com.android.settings.deviceinfo.BuildNumberPreferenceController"/>
     </PreferenceCategory>
 
+    <!-- SELinux status information -->
+    <Preference
+        android:key="selinux_status"
+        android:order="54"
+        android:title="@string/selinux_status"
+        android:summary="@string/selinux_status_enforcing"/>
+
 </PreferenceScreen>
diff --git a/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java b/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java
new file mode 100644
index 0000000..d0bf806
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/SELinuxStatusPreferenceController.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.deviceinfo;
+
+import android.content.Context;
+import android.os.SELinux;
+import android.os.SystemProperties;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class SELinuxStatusPreferenceController extends AbstractPreferenceController implements
+        PreferenceControllerMixin {
+
+    private static final String PROPERTY_SELINUX_STATUS = "ro.build.selinux";
+    private static final String KEY_SELINUX_STATUS = "selinux_status";
+
+    public SELinuxStatusPreferenceController(Context context) {
+        super(context);
+    }
+
+    @Override
+    public boolean isAvailable() {
+        return !TextUtils.isEmpty(SystemProperties.get(PROPERTY_SELINUX_STATUS));
+    }
+
+    @Override
+    public String getPreferenceKey() {
+        return KEY_SELINUX_STATUS;
+    }
+
+    @Override
+    public void displayPreference(PreferenceScreen screen) {
+        super.displayPreference(screen);
+        final Preference pref = screen.findPreference(KEY_SELINUX_STATUS);
+        if (pref == null) {
+            return;
+        }
+        if (!SELinux.isSELinuxEnabled()) {
+            String status = mContext.getResources().getString(R.string.selinux_status_disabled);
+            pref.setSummary(status);
+        } else if (!SELinux.isSELinuxEnforced()) {
+            String status = mContext.getResources().getString(R.string.selinux_status_permissive);
+            pref.setSummary(status);
+        }
+    }
+}
+
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index 50b6097..e146735 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -37,6 +37,7 @@
 import com.android.settings.deviceinfo.ManualPreferenceController;
 import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
 import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
+import com.android.settings.deviceinfo.SELinuxStatusPreferenceController;
 import com.android.settings.deviceinfo.UptimePreferenceController;
 import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
 import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController;
@@ -125,6 +126,7 @@
         controllers.add(new FeedbackPreferenceController(fragment, context));
         controllers.add(new FccEquipmentIdPreferenceController(context));
         controllers.add(new UptimePreferenceController(context, lifecycle));
+        controllers.add(new SELinuxStatusPreferenceController(context));
 
         Consumer<String> imeiInfoList = imeiKey -> {
             ImeiInfoPreferenceController imeiRecord =
@@ -157,6 +159,7 @@
         if (executor != null) {
             executor.shutdown();
         }
+
         return controllers;
     }