Fix a memory leak caused by dashboard freature provider.
In constructor, use app context instead of fragment context Change-Id: I24fbc457037c1d6854ecf0cb270110d73effb662 Fix: 35292764 Test: RunSettingsRoboTests
This commit is contained in:
@@ -51,13 +51,13 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
private final CategoryManager mCategoryManager;
|
||||
|
||||
public DashboardFeatureProviderImpl(Context context) {
|
||||
mContext = context;
|
||||
mContext = context.getApplicationContext();
|
||||
mCategoryManager = CategoryManager.get(context, getExtraIntentAction());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DashboardFeatureProviderImpl(Context context, CategoryManager categoryManager) {
|
||||
mContext = context;
|
||||
mContext = context.getApplicationContext();
|
||||
mCategoryManager = categoryManager;
|
||||
}
|
||||
|
||||
|
@@ -49,6 +49,8 @@ import org.robolectric.shadows.ShadowApplication;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -74,6 +76,11 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl = new DashboardFeatureProviderImpl(mActivity);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHoldAppContext() {
|
||||
assertThat(mImpl.mContext).isEqualTo(mActivity.getApplicationContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_shouldBindAllData() {
|
||||
final Preference preference = new Preference(
|
||||
@@ -191,7 +198,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
ShadowActivity shadowActivity = shadowOf(activity);
|
||||
|
||||
assertThat(shadowActivity.getNextStartedActivityForResult().intent.getAction())
|
||||
.isEqualTo("TestAction");
|
||||
.isEqualTo("TestAction");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,7 +241,8 @@ public class DashboardFeatureProviderImplTest {
|
||||
when(mSpy.isEnabled()).thenReturn(true);
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
category.tiles.add(new Tile());
|
||||
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
|
||||
when(mCategoryManager
|
||||
.getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE)))
|
||||
.thenReturn(category);
|
||||
|
||||
assertThat(mSpy.getPreferencesForCategory(mActivity,
|
||||
|
Reference in New Issue
Block a user