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

Commit 2c7ca9f2 authored by mxyyiyi's avatar mxyyiyi
Browse files

Fix crash while dumpping database.

Bug: 319905857
Test: manual
Change-Id: If531f1d7416b21d481fc19834e7538567dec7c0c
parent 4130a95c
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -767,7 +767,8 @@ public final class DatabaseUtils {
                BatteryUsageBroadcastReceiver.ACTION_CLEAR_BATTERY_CACHE_DATA);
        writeString(context, writer, "LastLoadFullChargeTime", KEY_LAST_LOAD_FULL_CHARGE_TIME);
        writeString(context, writer, "LastUploadFullChargeTime", KEY_LAST_UPLOAD_FULL_CHARGE_TIME);
        writeString(context, writer, "DismissedPowerAnomalyKeys", KEY_DISMISSED_POWER_ANOMALY_KEYS);
        writeStringSet(
                context, writer, "DismissedPowerAnomalyKeys", KEY_DISMISSED_POWER_ANOMALY_KEYS);
    }

    static SharedPreferences getSharedPreferences(Context context) {
@@ -921,10 +922,23 @@ public final class DatabaseUtils {
    private static void writeString(
            Context context, PrintWriter writer, String prefix, String key) {
        final SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences != null) {
        if (sharedPreferences == null) {
            return;
        }
        final String content = sharedPreferences.getString(key, "");
        writer.println(String.format("\t\t%s: %s", prefix, content));
    }

    private static void writeStringSet(
            Context context, PrintWriter writer, String prefix, String key) {
        final SharedPreferences sharedPreferences = getSharedPreferences(context);
        if (sharedPreferences == null) {
            return;
        }
        final Set<String> results = sharedPreferences.getStringSet(key, new ArraySet<>());
        if (results != null) {
            writer.println(String.format("\t\t%s: %s", prefix, results.toString()));
        }
    }

    private static void clearMemory() {