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

Commit 032b0454 authored by Wenhung Teng's avatar Wenhung Teng Committed by Android (Google) Code Review
Browse files

Merge "Fix issue "open battery settings, switch locale, apps are still in old...

Merge "Fix issue "open battery settings, switch locale, apps are still in old locale" into pi-dev" into pi-dev
parents d2fb46ea 8e14da1d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.settingslib.Utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

/**
 * Wraps the power usage data of a BatterySipper with information about package name
@@ -55,6 +56,8 @@ public class BatteryEntry {
    static final ArrayList<BatteryEntry> mRequestQueue = new ArrayList<BatteryEntry>();
    static Handler sHandler;

    static Locale sCurrentLocale = null;

    static private class NameAndIconLoader extends Thread {
        private boolean mAbort = false;

@@ -227,6 +230,13 @@ public class BatteryEntry {
    }

    void getQuickNameIconForUid(final int uid) {
        // Locale sync to system config in Settings
        final Locale locale = Locale.getDefault();
        if (sCurrentLocale != locale) {
            clearUidCache();
            sCurrentLocale = locale;
        }

        final String uidString = Integer.toString(uid);
        if (sUidCache.containsKey(uidString)) {
            UidToDetail utd = sUidCache.get(uidString);
+15 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;

import java.util.Locale;

@RunWith(RobolectricTestRunner.class)
public class BatteryEntryTest {

@@ -148,4 +150,17 @@ public class BatteryEntryTest {

        assertThat(entry.extractPackagesFromSipper(entry.sipper)).isEqualTo(entry.sipper.mPackages);
    }

    @Test
    public void testUidCache_switchLocale_shouldCleanCache() {
        BatteryEntry.stopRequestQueue();

        Locale.setDefault(new Locale("en_US"));
        BatteryEntry.sUidCache.put(Integer.toString(APP_UID), null);
        assertThat(BatteryEntry.sUidCache).isNotEmpty();

        Locale.setDefault(new Locale("zh_TW"));
        createBatteryEntryForApp();
        assertThat(BatteryEntry.sUidCache).isEmpty(); // check if cache is clear
    }
}