Merge "Fix memory leaks in Settings" into pi-dev
am: be13e74deb
Change-Id: I51e9c6682a0589afbdfcc8799b10598eac496396
This commit is contained in:
@@ -24,8 +24,8 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
@@ -35,7 +35,6 @@ import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseLongArray;
|
||||
@@ -48,7 +47,6 @@ import com.android.settings.fuelgauge.anomaly.Anomaly;
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.StatsManagerConfig;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
|
||||
import com.android.settingslib.fuelgauge.PowerWhitelistBackend;
|
||||
import com.android.settingslib.utils.PowerUtil;
|
||||
|
||||
@@ -93,14 +91,14 @@ public class BatteryUtils {
|
||||
|
||||
public static BatteryUtils getInstance(Context context) {
|
||||
if (sInstance == null || sInstance.isDataCorrupted()) {
|
||||
sInstance = new BatteryUtils(context);
|
||||
sInstance = new BatteryUtils(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryUtils(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
mContext = context;
|
||||
mPackageManager = context.getPackageManager();
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(
|
||||
|
@@ -94,7 +94,8 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public PowerUsageFeatureProvider getPowerUsageFeatureProvider(Context context) {
|
||||
if (mPowerUsageFeatureProvider == null) {
|
||||
mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl(context);
|
||||
mPowerUsageFeatureProvider = new PowerUsageFeatureProviderImpl(
|
||||
context.getApplicationContext());
|
||||
}
|
||||
return mPowerUsageFeatureProvider;
|
||||
}
|
||||
@@ -102,7 +103,8 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public DashboardFeatureProvider getDashboardFeatureProvider(Context context) {
|
||||
if (mDashboardFeatureProvider == null) {
|
||||
mDashboardFeatureProvider = new DashboardFeatureProviderImpl(context);
|
||||
mDashboardFeatureProvider = new DashboardFeatureProviderImpl(
|
||||
context.getApplicationContext());
|
||||
}
|
||||
return mDashboardFeatureProvider;
|
||||
}
|
||||
@@ -118,10 +120,11 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public ApplicationFeatureProvider getApplicationFeatureProvider(Context context) {
|
||||
if (mApplicationFeatureProvider == null) {
|
||||
mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(context,
|
||||
new PackageManagerWrapper(context.getPackageManager()),
|
||||
final Context appContext = context.getApplicationContext();
|
||||
mApplicationFeatureProvider = new ApplicationFeatureProviderImpl(appContext,
|
||||
new PackageManagerWrapper(appContext.getPackageManager()),
|
||||
AppGlobals.getPackageManager(),
|
||||
(DevicePolicyManager) context
|
||||
(DevicePolicyManager) appContext
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE));
|
||||
}
|
||||
return mApplicationFeatureProvider;
|
||||
@@ -138,12 +141,14 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public EnterprisePrivacyFeatureProvider getEnterprisePrivacyFeatureProvider(Context context) {
|
||||
if (mEnterprisePrivacyFeatureProvider == null) {
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(context,
|
||||
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE),
|
||||
new PackageManagerWrapper(context.getPackageManager()),
|
||||
UserManager.get(context),
|
||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE),
|
||||
context.getResources());
|
||||
final Context appContext = context.getApplicationContext();
|
||||
mEnterprisePrivacyFeatureProvider = new EnterprisePrivacyFeatureProviderImpl(appContext,
|
||||
(DevicePolicyManager) appContext
|
||||
.getSystemService(Context.DEVICE_POLICY_SERVICE),
|
||||
new PackageManagerWrapper(appContext.getPackageManager()),
|
||||
UserManager.get(appContext),
|
||||
(ConnectivityManager) appContext.getSystemService(Context.CONNECTIVITY_SERVICE),
|
||||
appContext.getResources());
|
||||
}
|
||||
return mEnterprisePrivacyFeatureProvider;
|
||||
}
|
||||
@@ -172,7 +177,8 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public SuggestionFeatureProvider getSuggestionFeatureProvider(Context context) {
|
||||
if (mSuggestionFeatureProvider == null) {
|
||||
mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl(context);
|
||||
mSuggestionFeatureProvider = new SuggestionFeatureProviderImpl(
|
||||
context.getApplicationContext());
|
||||
}
|
||||
return mSuggestionFeatureProvider;
|
||||
}
|
||||
@@ -180,7 +186,7 @@ public class FeatureFactoryImpl extends FeatureFactory {
|
||||
@Override
|
||||
public UserFeatureProvider getUserFeatureProvider(Context context) {
|
||||
if (mUserFeatureProvider == null) {
|
||||
mUserFeatureProvider = new UserFeatureProviderImpl(context);
|
||||
mUserFeatureProvider = new UserFeatureProviderImpl(context.getApplicationContext());
|
||||
}
|
||||
return mUserFeatureProvider;
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
@@ -89,6 +90,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
|
||||
mShadowContext = RuntimeEnvironment.application;
|
||||
FakeFeatureFactory.setupForTest();
|
||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
|
||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||
@@ -118,7 +120,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_restrictApp_showDialog() {
|
||||
doReturn(AppOpsManager.MODE_ALLOWED).when(mAppOpsManager)
|
||||
.checkOpNoThrow(anyInt(), anyInt(), anyString());
|
||||
.checkOpNoThrow(anyInt(), anyInt(), anyString());
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
@@ -128,7 +130,7 @@ public class BackgroundActivityPreferenceControllerTest {
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_unRestrictApp_showDialog() {
|
||||
doReturn(AppOpsManager.MODE_IGNORED).when(mAppOpsManager)
|
||||
.checkOpNoThrow(anyInt(), anyInt(), anyString());
|
||||
.checkOpNoThrow(anyInt(), anyInt(), anyString());
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
|
Reference in New Issue
Block a user