Search in sources :

Example 1 with EXTRA_SHOW_FRAGMENT_ARGUMENTS

use of com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AdvancedPowerUsageDetailTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    FakeFeatureFactory.setupForTest();
    mFragment = spy(new AdvancedPowerUsageDetail());
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mActivity).when(mFragment).getActivity();
    doReturn(SUMMARY).when(mFragment).getString(anyInt());
    doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
    when(mFragment.getArguments()).thenReturn(mBundle);
    doReturn(mLoaderManager).when(mFragment).getLoaderManager();
    ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
    doReturn(UID).when(mBatterySipper).getUid();
    when(mBatteryEntry.getLabel()).thenReturn(APP_LABEL);
    doReturn(BACKGROUND_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_BACKGROUND), anyLong(), anyInt());
    doReturn(PROCSTATE_TOP_TIME_US).when(mUid).getProcessStateTime(eq(BatteryStats.Uid.PROCESS_STATE_TOP), anyLong(), anyInt());
    doReturn(mForegroundActivityTimer).when(mUid).getForegroundActivityTimer();
    doReturn(FOREGROUND_ACTIVITY_TIME_US).when(mForegroundActivityTimer).getTotalTimeLocked(anyLong(), anyInt());
    ReflectionHelpers.setField(mBatteryEntry, "sipper", mBatterySipper);
    mBatteryEntry.iconId = ICON_ID;
    mBatterySipper.uidObj = mUid;
    mBatterySipper.drainType = BatterySipper.DrainType.APP;
    mFragment.mHeaderPreference = mHeaderPreference;
    mFragment.mState = mState;
    mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
    mAppEntry.info = mock(ApplicationInfo.class);
    mTestActivity = spy(new SettingsActivity());
    doReturn(mPackageManager).when(mTestActivity).getPackageManager();
    doReturn(mPackageManager).when(mActivity).getPackageManager();
    doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
    mBatteryUtils = spy(new BatteryUtils(mContext));
    doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
    final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    Answer<Void> callable = invocation -> {
        mBundle = captor.getValue().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        return null;
    };
    doAnswer(callable).when(mActivity).startActivityAsUser(captor.capture(), nullable(UserHandle.class));
    doAnswer(callable).when(mActivity).startActivity(captor.capture());
    mForegroundPreference = new Preference(mContext);
    mBackgroundPreference = new Preference(mContext);
    mFragment.mForegroundPreference = mForegroundPreference;
    mFragment.mBackgroundPreference = mBackgroundPreference;
}
Also used : AppOpsManager(android.app.AppOpsManager) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Drawable(android.graphics.drawable.Drawable) ShadowActivityManager(com.android.settings.testutils.shadow.ShadowActivityManager) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) AppUtils(com.android.settingslib.applications.AppUtils) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) RecyclerView(androidx.recyclerview.widget.RecyclerView) Mockito.doReturn(org.mockito.Mockito.doReturn) R(com.android.settings.R) EXTRA_SHOW_FRAGMENT_ARGUMENTS(com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) SettingsActivity(com.android.settings.SettingsActivity) EntityHeaderController(com.android.settings.widget.EntityHeaderController) ApplicationInfo(android.content.pm.ApplicationInfo) ShadowEntityHeaderController(com.android.settings.testutils.shadow.ShadowEntityHeaderController) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) Mockito.spy(org.mockito.Mockito.spy) LoaderManager(androidx.loader.app.LoaderManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) UserHandle(android.os.UserHandle) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) Answers(org.mockito.Answers) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Truth.assertThat(com.google.common.truth.Truth.assertThat) InstantAppDataProvider(com.android.settingslib.applications.instantapps.InstantAppDataProvider) Preference(androidx.preference.Preference) Mockito.verify(org.mockito.Mockito.verify) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) BatterySipper(com.android.internal.os.BatterySipper) BatteryStats(android.os.BatteryStats) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) RecyclerView(androidx.recyclerview.widget.RecyclerView) SettingsActivity(com.android.settings.SettingsActivity) Before(org.junit.Before)

Example 2 with EXTRA_SHOW_FRAGMENT_ARGUMENTS

use of com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS in project android_packages_apps_Settings by omnirom.

the class AdvancedPowerUsageDetailTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mContext.getPackageName()).thenReturn("foo");
    mFeatureFactory = FakeFeatureFactory.setupForTest();
    mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
    mFragment = spy(new AdvancedPowerUsageDetail());
    doReturn(mContext).when(mFragment).getContext();
    doReturn(mActivity).when(mFragment).getActivity();
    doReturn(SUMMARY).when(mFragment).getString(anyInt());
    doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
    when(mFragment.getArguments()).thenReturn(mBundle);
    doReturn(mLoaderManager).when(mFragment).getLoaderManager();
    when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mContext)).thenReturn(true);
    ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
    doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
    when(mBatteryEntry.getUid()).thenReturn(UID);
    when(mBatteryEntry.getLabel()).thenReturn(APP_LABEL);
    when(mBatteryEntry.getTimeInBackgroundMs()).thenReturn(BACKGROUND_TIME_MS);
    when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(FOREGROUND_TIME_MS);
    mBatteryEntry.iconId = ICON_ID;
    mFragment.mHeaderPreference = mHeaderPreference;
    mFragment.mState = mState;
    mFragment.enableTriState = true;
    mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
    mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
    mAppEntry.info = mock(ApplicationInfo.class);
    mTestActivity = spy(new SettingsActivity());
    doReturn(mPackageManager).when(mTestActivity).getPackageManager();
    doReturn(mPackageManager).when(mActivity).getPackageManager();
    doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
    mBatteryUtils = spy(new BatteryUtils(mContext));
    doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
    final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    Answer<Void> callable = invocation -> {
        mBundle = captor.getValue().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        System.out.println("mBundle = " + mBundle);
        return null;
    };
    doAnswer(callable).when(mActivity).startActivityAsUser(captor.capture(), nullable(UserHandle.class));
    doAnswer(callable).when(mActivity).startActivity(captor.capture());
    mForegroundPreference = new Preference(mContext);
    mBackgroundPreference = new Preference(mContext);
    mFooterPreference = new FooterPreference(mContext);
    mRestrictedPreference = new RadioButtonPreference(mContext);
    mOptimizePreference = new RadioButtonPreference(mContext);
    mUnrestrictedPreference = new RadioButtonPreference(mContext);
    mFragment.mForegroundPreference = mForegroundPreference;
    mFragment.mBackgroundPreference = mBackgroundPreference;
    mFragment.mFooterPreference = mFooterPreference;
    mFragment.mRestrictedPreference = mRestrictedPreference;
    mFragment.mOptimizePreference = mOptimizePreference;
    mFragment.mUnrestrictedPreference = mUnrestrictedPreference;
}
Also used : AppOpsManager(android.app.AppOpsManager) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) Drawable(android.graphics.drawable.Drawable) ShadowActivityManager(com.android.settings.testutils.shadow.ShadowActivityManager) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) AppUtils(com.android.settingslib.applications.AppUtils) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) RecyclerView(androidx.recyclerview.widget.RecyclerView) Mockito.doReturn(org.mockito.Mockito.doReturn) R(com.android.settings.R) EXTRA_SHOW_FRAGMENT_ARGUMENTS(com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) FooterPreference(com.android.settingslib.widget.FooterPreference) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) SettingsActivity(com.android.settings.SettingsActivity) EntityHeaderController(com.android.settings.widget.EntityHeaderController) ApplicationInfo(android.content.pm.ApplicationInfo) ShadowEntityHeaderController(com.android.settings.testutils.shadow.ShadowEntityHeaderController) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Mock(org.mockito.Mock) Pair(android.util.Pair) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) Mockito.spy(org.mockito.Mockito.spy) LoaderManager(androidx.loader.app.LoaderManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) UserHandle(android.os.UserHandle) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) Answers(org.mockito.Answers) SettingsEnums(android.app.settings.SettingsEnums) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Truth.assertThat(com.google.common.truth.Truth.assertThat) InstantAppDataProvider(com.android.settingslib.applications.instantapps.InstantAppDataProvider) Preference(androidx.preference.Preference) Mockito.verify(org.mockito.Mockito.verify) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) BatteryStats(android.os.BatteryStats) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) FooterPreference(com.android.settingslib.widget.FooterPreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) UserHandle(android.os.UserHandle) RecyclerView(androidx.recyclerview.widget.RecyclerView) FooterPreference(com.android.settingslib.widget.FooterPreference) SettingsActivity(com.android.settings.SettingsActivity) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Before(org.junit.Before)

Aggregations

AppOpsManager (android.app.AppOpsManager)2 Context (android.content.Context)2 Intent (android.content.Intent)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 Drawable (android.graphics.drawable.Drawable)2 BatteryStats (android.os.BatteryStats)2 Bundle (android.os.Bundle)2 UserHandle (android.os.UserHandle)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 LoaderManager (androidx.loader.app.LoaderManager)2 Preference (androidx.preference.Preference)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 R (com.android.settings.R)2 SettingsActivity (com.android.settings.SettingsActivity)2 EXTRA_SHOW_FRAGMENT_ARGUMENTS (com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS)2 FakeFeatureFactory (com.android.settings.testutils.FakeFeatureFactory)2 ShadowActivityManager (com.android.settings.testutils.shadow.ShadowActivityManager)2 ShadowEntityHeaderController (com.android.settings.testutils.shadow.ShadowEntityHeaderController)2 EntityHeaderController (com.android.settings.widget.EntityHeaderController)2