(SHIFT) implement ShiftOS branding

Change-Id: I5a1ef624fc47acd13f844b40d07e2158dab5d983
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/res/values/shiftos_strings.xml b/res/values/shiftos_strings.xml
new file mode 100644
index 0000000..2b047ea
--- /dev/null
+++ b/res/values/shiftos_strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2022 SHIFT GmbH
+
+     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="shiftos_version">ShiftOS version</string>
+</resources>
diff --git a/res/xml/firmware_version.xml b/res/xml/firmware_version.xml
index 99243a6..9dcf0ae 100644
--- a/res/xml/firmware_version.xml
+++ b/res/xml/firmware_version.xml
@@ -30,13 +30,14 @@
         settings:searchable="false"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDetailPreferenceController"/>
 
-    <!-- Lineage version -->
+    <!-- ShiftOS version -->
     <Preference
-        android:key="lineage_version"
-        android:title="@*lineageos.platform:string/lineage_version"
+        android:key="shiftos_version"
+        android:title="@string/shiftos_version"
         android:summary="@string/summary_placeholder"
+        android:selectable="false"
         settings:enableCopying="true"
-        settings:controller="com.android.settings.deviceinfo.firmwareversion.LineageVersionDetailPreferenceController"/>
+        settings:controller="com.android.settings.deviceinfo.firmwareversion.ShiftOsVersionDetailPreferenceController"/>
 
     <!-- Security patch -->
     <Preference
@@ -46,12 +47,14 @@
         settings:controller="com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelPreferenceController"/>
 
     <!-- Vendor security patch -->
+    <!--
     <Preference
         android:key="vendor_security_key"
         android:title="@*lineageos.platform:string/lineage_vendor_security_patch"
         android:selectable="false"
         settings:enableCopying="true"
         settings:controller="com.android.settings.deviceinfo.firmwareversion.LineageVendorSecurityPatchLevelPreferenceController"/>
+    -->
 
     <!-- Mainline module version -->
     <Preference
diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml
index 7eeffee..7a615b8 100644
--- a/res/xml/my_device_info.xml
+++ b/res/xml/my_device_info.xml
@@ -132,14 +132,15 @@
             android:fragment="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings"
             settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController"/>
 
-        <!-- Lineage version -->
+        <!-- ShiftOS version -->
         <Preference
-            android:key="lineage_os_version"
+            android:key="shiftos_version"
             android:order="43"
-            android:title="@*lineageos.platform:string/lineage_version"
+            android:title="@string/shiftos_version"
             android:summary="@string/summary_placeholder"
+            android:selectable="false"
             settings:enableCopying="true"
-            settings:controller="com.android.settings.deviceinfo.firmwareversion.LineageVersionDetailPreferenceController"/>
+            settings:controller="com.android.settings.deviceinfo.firmwareversion.ShiftOsVersionDetailPreferenceController"/>
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index a40caf8..f65a43e 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -40,6 +40,7 @@
 import com.android.settings.core.InstrumentedPreferenceFragment;
 import com.android.settings.overlay.FeatureFactory;
 import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settings.utils.ShiftOsUtils;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedLockUtilsInternal;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -79,7 +80,8 @@
 
     @Override
     public CharSequence getSummary() {
-        return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY);
+        return BidiFormatter.getInstance().unicodeWrap(
+                ShiftOsUtils.getShiftOsDisplayVersion(mContext));
     }
 
     @Override
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/ShiftOsVersionDetailPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/ShiftOsVersionDetailPreferenceController.java
new file mode 100644
index 0000000..74d082c
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/ShiftOsVersionDetailPreferenceController.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2022 SHIFT GmbH
+ *
+ * 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.firmwareversion;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.utils.ShiftOsUtils;
+
+public class ShiftOsVersionDetailPreferenceController extends BasePreferenceController {
+
+    public ShiftOsVersionDetailPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return AVAILABLE;
+    }
+
+    @Override
+    public boolean useDynamicSliceSummary() {
+        return true;
+    }
+
+    @Override
+    public boolean isSliceable() {
+        return true;
+    }
+
+    @Override
+    public CharSequence getSummary() {
+        return ShiftOsUtils.getShiftOsVersion(mContext);
+    }
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java
index 53f5ff9..f4a6094 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java
@@ -17,10 +17,10 @@
 package com.android.settings.deviceinfo.firmwareversion;
 
 import android.content.Context;
-import android.os.Build;
 import android.text.BidiFormatter;
 
 import com.android.settings.core.BasePreferenceController;
+import com.android.settings.utils.ShiftOsUtils;
 
 public class SimpleBuildNumberPreferenceController extends BasePreferenceController {
 
@@ -36,6 +36,7 @@
 
     @Override
     public CharSequence getSummary() {
-        return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY);
+        return BidiFormatter.getInstance().unicodeWrap(
+                ShiftOsUtils.getShiftOsDisplayVersion(mContext));
     }
 }
diff --git a/src/com/android/settings/utils/ShiftOsUtils.java b/src/com/android/settings/utils/ShiftOsUtils.java
new file mode 100644
index 0000000..47752d0
--- /dev/null
+++ b/src/com/android/settings/utils/ShiftOsUtils.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 SHIFT GmbH
+ *
+ * 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.utils;
+
+import android.content.Context;
+import android.os.Build;
+import android.os.SystemProperties;
+
+import com.android.settings.R;
+
+public class ShiftOsUtils {
+
+    private static final String KEY_SHIFTOS_VERSION_EXTRA_PROP = "ro.shift.sos.version.extra";
+    private static final String KEY_SHIFTOS_VERSION_DATE_PROP = "ro.shift.version.date";
+    private static final String KEY_SHIFTOS_VERSION_DISPLAY = "ro.shift.version.display";
+    private static final String KEY_SHIFTOS_VERSION_NUMBER_PROP = "ro.shift.sos.version.number";
+
+    public static String getShiftOsDisplayVersion(final Context context) {
+        final String displayVersion = SystemProperties.get(KEY_SHIFTOS_VERSION_DISPLAY, "");
+        if (displayVersion.isEmpty()) {
+            return context.getString(R.string.unknown);
+        }
+        return displayVersion;
+    }
+
+    public static String getShiftOsVersion(final Context context) {
+        final String versionNumber = SystemProperties.get(KEY_SHIFTOS_VERSION_NUMBER_PROP, "");
+        final String versionExtra = SystemProperties.get(KEY_SHIFTOS_VERSION_EXTRA_PROP, "");
+        final String versionDate = SystemProperties.get(KEY_SHIFTOS_VERSION_DATE_PROP, "");
+        final String summary;
+        if (versionNumber.isEmpty() || versionExtra.isEmpty()) {
+            summary = context.getString(R.string.unknown);
+        } else {
+            summary = String.format("%s %s (%s.%s)",
+                    versionNumber, versionExtra, versionDate, Build.PRODUCT);
+        }
+        return summary;
+    }
+}