aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/src/java/org
diff options
context:
space:
mode:
authorTobias Tefke <tobias.tefke@tutanota.com>2018-06-13 11:29:33 +0200
committerBruno Martins <bgcngm@gmail.com>2018-07-20 13:00:25 +0200
commit5e5f905802f08ffb90ad0270edd2711e8f138a4b (patch)
tree4ddcd14e527284d6aaa431045f682cec29ca2a12 /sdk/src/java/org
parentc6701404927dae3353ff90cdd6de36fc47269cab (diff)
downloadlineage-sdk-5e5f905802f08ffb90ad0270edd2711e8f138a4b.tar.gz
lineage-sdk-5e5f905802f08ffb90ad0270edd2711e8f138a4b.tar.bz2
lineage-sdk-5e5f905802f08ffb90ad0270edd2711e8f138a4b.zip
[2/2] Add vendor security patch level to device info
Change-Id: Ic65290aa2c5fa159512e16a3781bc407876b9e5a
Diffstat (limited to 'sdk/src/java/org')
-rw-r--r--sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVendorSecurityPatchPreference.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVendorSecurityPatchPreference.java b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVendorSecurityPatchPreference.java
new file mode 100644
index 00000000..c7ae134c
--- /dev/null
+++ b/sdk/src/java/org/lineageos/internal/preference/deviceinfo/LineageVendorSecurityPatchPreference.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2017-2018 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.text.format.DateFormat;
+import android.util.AttributeSet;
+
+import lineageos.preference.SelfRemovingPreference;
+
+import org.lineageos.platform.internal.R;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Locale;
+
+public class LineageVendorSecurityPatchPreference extends SelfRemovingPreference {
+ private static final String KEY_AOSP_VENDOR_SECURITY_PATCH =
+ "ro.vendor.build.security_patch";
+
+ private static final String KEY_LINEAGE_VENDOR_SECURITY_PATCH =
+ "ro.lineage.build.vendor_security_patch";
+
+ public LineageVendorSecurityPatchPreference(Context context, AttributeSet attrs,
+ int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ public LineageVendorSecurityPatchPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LineageVendorSecurityPatchPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void onAttached() {
+ super.onAttached();
+
+ setTitle(R.string.lineage_vendor_security_patch);
+ setSummary(getVendorSecurityPatchLevel());
+ }
+
+ @Override
+ public void setSummary(CharSequence summary) {
+ if (summary.length() > 0) {
+ super.setSummary(summary);
+ } else {
+ setAvailable(false);
+ }
+ }
+
+ private String getVendorSecurityPatchLevel() {
+ String patchLevel = SystemProperties.get(KEY_AOSP_VENDOR_SECURITY_PATCH);
+
+ if (patchLevel.isEmpty()) {
+ patchLevel = SystemProperties.get(KEY_LINEAGE_VENDOR_SECURITY_PATCH);
+ }
+
+ if (!patchLevel.isEmpty()) {
+ try {
+ SimpleDateFormat template = new SimpleDateFormat("yyyy-MM-dd");
+ Date patchLevelDate = template.parse(patchLevel);
+ String format = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dMMMMyyyy");
+ patchLevel = DateFormat.format(format, patchLevelDate).toString();
+ } catch (ParseException e) {
+ // parsing failed, use raw string
+ }
+ }
+ return patchLevel;
+ }
+}