Fix potential race in Theme creation

Bug: 38190555
Test: none
Change-Id: Id627bd6088dc469baffb1abb8310cd9e992996aa
This commit is contained in:
Adam Lesinski
2017-06-12 12:22:10 -07:00
parent ba003a97f8
commit 1e87a365d6

View File

@@ -256,28 +256,34 @@ class ContextImpl extends Context {
@Override
public void setTheme(int resId) {
if (mThemeResource != resId) {
mThemeResource = resId;
initializeTheme();
synchronized (mSync) {
if (mThemeResource != resId) {
mThemeResource = resId;
initializeTheme();
}
}
}
@Override
public int getThemeResId() {
return mThemeResource;
synchronized (mSync) {
return mThemeResource;
}
}
@Override
public Resources.Theme getTheme() {
if (mTheme != null) {
synchronized (mSync) {
if (mTheme != null) {
return mTheme;
}
mThemeResource = Resources.selectDefaultTheme(mThemeResource,
getOuterContext().getApplicationInfo().targetSdkVersion);
initializeTheme();
return mTheme;
}
mThemeResource = Resources.selectDefaultTheme(mThemeResource,
getOuterContext().getApplicationInfo().targetSdkVersion);
initializeTheme();
return mTheme;
}
private void initializeTheme() {