Loading src/com/android/settings/fuelgauge/BatteryUtils.java +3 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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( Loading src/com/android/settings/overlay/FeatureFactoryImpl.java +19 −13 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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; } Loading tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading
src/com/android/settings/fuelgauge/BatteryUtils.java +3 −5 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading @@ -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; Loading Loading @@ -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( Loading
src/com/android/settings/overlay/FeatureFactoryImpl.java +19 −13 Original line number Diff line number Diff line Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading @@ -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; } Loading Loading @@ -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; } Loading @@ -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; } Loading
tests/robotests/src/com/android/settings/fuelgauge/BackgroundActivityPreferenceControllerTest.java +4 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading