Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51d27b2d authored by Jacky Wang's avatar Jacky Wang
Browse files

Overload DeviceInfoUtils.getSecurityPatch method

Bug: 365886251
Flag: EXEMPT Code refactor
Test: N/A
Change-Id: Idaef7f9b603e531b896057c1e76b0dc4927c9b81
parent 41467060
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import java.io.BufferedReader;
@@ -153,13 +155,19 @@ public class DeviceInfoUtils {
        return null;
    }

    public static String getSecurityPatch() {
    /** Returns security patch in default locale. */
    public static @Nullable String getSecurityPatch() {
        return getSecurityPatch(Locale.getDefault());
    }

    /** Returns security patch in given locale. */
    public static @Nullable String getSecurityPatch(@NonNull Locale locale) {
        String patch = Build.VERSION.SECURITY_PATCH;
        if (!"".equals(patch)) {
            try {
                SimpleDateFormat template = new SimpleDateFormat("yyyy-MM-dd");
                Date patchDate = template.parse(patch);
                String format = DateFormat.getBestDateTimePattern(Locale.getDefault(), "dMMMMyyyy");
                String format = DateFormat.getBestDateTimePattern(locale, "dMMMMyyyy");
                patch = DateFormat.format(format, patchDate).toString();
            } catch (ParseException e) {
                // broken parse; fall through and use the raw string