Merge "Make BatteryDatabaseManager singleton"
This commit is contained in:
committed by
Android (Google) Code Review
commit
feec804395
@@ -59,7 +59,7 @@ public class BatteryDatabaseManagerTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mBatteryDatabaseManager = spy(new BatteryDatabaseManager(mContext));
|
||||
mBatteryDatabaseManager = spy(BatteryDatabaseManager.getInstance(mContext));
|
||||
}
|
||||
|
||||
@After
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.testutils;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||
import com.android.settings.search.IndexDatabaseHelper;
|
||||
import com.android.settings.slices.SlicesDatabaseHelper;
|
||||
|
||||
@@ -30,6 +31,7 @@ public class DatabaseTestUtils {
|
||||
clearSearchDb(context);
|
||||
clearSlicesDb(context);
|
||||
clearAnomalyDb(context);
|
||||
clearAnomalyDbManager();
|
||||
}
|
||||
|
||||
private static void clearSlicesDb(Context context) {
|
||||
@@ -76,4 +78,16 @@ public class DatabaseTestUtils {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void clearAnomalyDbManager() {
|
||||
Field instance;
|
||||
Class clazz = BatteryDatabaseManager.class;
|
||||
try {
|
||||
instance = clazz.getDeclaredField("sSingleton");
|
||||
instance.setAccessible(true);
|
||||
instance.set(null, null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user