lineage-sdk: Add Lineage version, API and build date preferences

Adapted from the following in order to fit
into lineage-sdk (sam3000):

Settings: Add LineageOS version to device info
https://review.lineageos.org/191065
Settings: Add Lineage SDK API version to device info
https://review.lineageos.org/191086
Settings: Add build date to device info
https://review.lineageos.org/191087

Change-Id: I8f41d16733f7b0fadb47e6940c4140c039626423
diff --git a/lineage/res/res/values/strings.xml b/lineage/res/res/values/strings.xml
index dd9a0bc..6e10c5d 100644
--- a/lineage/res/res/values/strings.xml
+++ b/lineage/res/res/values/strings.xml
@@ -199,4 +199,13 @@
     <string name="permlab_manageRemotePrefs">manage remote settings</string>
     <string name="permdesc_manageRemotePrefs">Allows an app to manage remote settings</string>
 
+    <!-- About device screen, build date -->
+    <string name="build_date">Build date</string>
+    <!-- About device screen, LineageOS API Level -->
+    <string name="lineage_api_level">LineageOS API level</string>
+    <!-- About device screen, LineageOS version -->
+    <string name="lineage_version">LineageOS version</string>
+
+    <!-- General purpose use "unknown" string -->
+    <string name="unknown">Unknown</string>
 </resources>
diff --git a/lineage/res/res/values/symbols.xml b/lineage/res/res/values/symbols.xml
index 0256c23..2a7a43d 100644
--- a/lineage/res/res/values/symbols.xml
+++ b/lineage/res/res/values/symbols.xml
@@ -121,4 +121,12 @@
 
     <!-- Notification light mappings -->
     <java-symbol type="array" name="notification_light_package_mapping" />
+
+    <!-- About device info screen -->
+    <java-symbol type="string" name="build_date" />
+    <java-symbol type="string" name="lineage_api_level" />
+    <java-symbol type="string" name="lineage_version" />
+
+    <!-- General purpose use "unknown" string -->
+    <java-symbol type="string" name="unknown" />
 </resources>
diff --git a/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageAPIVersionPreference.java b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageAPIVersionPreference.java
new file mode 100644
index 0000000..c3b6cc4
--- /dev/null
+++ b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageAPIVersionPreference.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 The LineageOS 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 org.lineageos.internal.preference.deviceinfo;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.util.AttributeSet;
+
+import lineageos.preference.SelfRemovingPreference;
+
+import org.lineageos.platform.internal.R;
+
+public class LineageAPIVersionPreference extends SelfRemovingPreference {
+    private static final String TAG = "LineageAPIVersionPreference";
+
+    private static final String KEY_BUILD_DATE_PROP = "ro.build.date";
+
+    public LineageAPIVersionPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    public LineageAPIVersionPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public LineageAPIVersionPreference(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onAttached() {
+        super.onAttached();
+
+        setTitle(R.string.lineage_api_level);
+        final int sdk = lineageos.os.Build.LINEAGE_VERSION.SDK_INT;
+        StringBuilder builder = new StringBuilder();
+        builder.append(lineageos.os.Build.getNameForSDKInt(sdk))
+                .append(" (" + sdk + ")");
+        setSummary(builder.toString());
+    }
+}
diff --git a/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageBuildDatePreference.java b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageBuildDatePreference.java
new file mode 100644
index 0000000..fb7cb06
--- /dev/null
+++ b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageBuildDatePreference.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The LineageOS 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 org.lineageos.internal.preference.deviceinfo;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.util.AttributeSet;
+
+import lineageos.preference.SelfRemovingPreference;
+
+import org.lineageos.platform.internal.R;
+
+public class LineageBuildDatePreference extends SelfRemovingPreference {
+    private static final String TAG = "LineageBuildDatePreference";
+
+    private static final String KEY_BUILD_DATE_PROP = "ro.build.date";
+
+    public LineageBuildDatePreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    public LineageBuildDatePreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public LineageBuildDatePreference(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onAttached() {
+        super.onAttached();
+
+        setTitle(R.string.build_date);
+        setSummary(SystemProperties.get(KEY_BUILD_DATE_PROP,
+                getContext().getResources().getString(R.string.unknown)));
+    }
+}
diff --git a/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVersionPreference.java b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVersionPreference.java
new file mode 100644
index 0000000..7e60b18
--- /dev/null
+++ b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVersionPreference.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 The LineageOS 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 org.lineageos.internal.preference.deviceinfo;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.SystemClock;
+import android.os.SystemProperties;
+import android.support.v7.preference.Preference;
+import android.util.AttributeSet;
+import android.util.Log;
+
+import lineageos.preference.SelfRemovingPreference;
+
+import org.lineageos.platform.internal.R;
+
+public class LineageVersionPreference extends SelfRemovingPreference
+        implements Preference.OnPreferenceClickListener {
+
+    private static final String TAG = "LineageVersionPreference";
+
+    private static final String KEY_LINEAGE_VERSION_PROP = "ro.lineage.version";
+
+    private static final String PLATLOGO_PACKAGE_NAME = "org.lineageos.lineageparts";
+    private static final String PLATLOGO_ACTIVITY_CLASS =
+            PLATLOGO_PACKAGE_NAME + ".logo.PlatLogoActivity";
+
+    private long[] mHits = new long[3];
+
+    public LineageVersionPreference(Context context, AttributeSet attrs, int defStyle) {
+        super(context, attrs, defStyle);
+    }
+
+    public LineageVersionPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public LineageVersionPreference(Context context) {
+        super(context);
+    }
+
+    @Override
+    public void onAttached() {
+        super.onAttached();
+
+        setOnPreferenceClickListener(this);
+        setTitle(R.string.lineage_version);
+        setSummary(SystemProperties.get(KEY_LINEAGE_VERSION_PROP,
+                getContext().getResources().getString(R.string.unknown)));
+    }
+
+    @Override
+    public boolean onPreferenceClick(Preference preference) {
+        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
+        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
+        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
+            launchLogoActivity();
+        }
+        return true; // handled
+    }
+
+    private void launchLogoActivity() {
+        final Intent intent = new Intent(Intent.ACTION_MAIN)
+                .setClassName(PLATLOGO_PACKAGE_NAME, PLATLOGO_ACTIVITY_CLASS);
+        try {
+            getContext().startActivity(intent);
+        } catch (Exception e) {
+            Log.e(TAG, "Unable to start activity " + intent.toString());
+        }
+    }
+}