Search in sources :

Example 11 with ShadowPackageManager

use of org.robolectric.shadows.ShadowPackageManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SimStatusDialogControllerTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    when(mDialog.getContext()).thenReturn(mContext);
    mLifecycleOwner = () -> mLifecycle;
    mLifecycle = new Lifecycle(mLifecycleOwner);
    mController = spy(new SimStatusDialogController(mDialog, mLifecycle, 0));
    doReturn(mServiceState).when(mController).getCurrentServiceState();
    doReturn(0).when(mSignalStrength).getDbm();
    doReturn(0).when(mSignalStrength).getAsuLevel();
    doReturn(mPhoneStateListener).when(mController).getPhoneStateListener();
    doReturn("").when(mController).getPhoneNumber();
    doReturn(mSignalStrength).when(mController).getSignalStrength();
    doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
    when(mEuiccManager.isEnabled()).thenReturn(true);
    when(mEuiccManager.getEid()).thenReturn("");
    ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
    ReflectionHelpers.setField(mController, "mCarrierConfigManager", mCarrierConfigManager);
    ReflectionHelpers.setField(mController, "mSubscriptionInfo", mSubscriptionInfo);
    ReflectionHelpers.setField(mController, "mEuiccManager", mEuiccManager);
    ReflectionHelpers.setField(mController, "mSubscriptionManager", mSubscriptionManager);
    when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(mPersistableBundle);
    when(mPersistableBundle.getBoolean(CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL)).thenReturn(true);
    final ShadowPackageManager shadowPackageManager = Shadows.shadowOf(RuntimeEnvironment.application.getPackageManager());
    final PackageInfo sysUIPackageInfo = new PackageInfo();
    sysUIPackageInfo.packageName = "com.android.systemui";
    shadowPackageManager.addPackage(sysUIPackageInfo);
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) PackageInfo(android.content.pm.PackageInfo) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Before(org.junit.Before)

Example 12 with ShadowPackageManager

use of org.robolectric.shadows.ShadowPackageManager in project materialistic by hidroh.

the class TestApplication method addResolver.

public static void addResolver(Intent intent) {
    ShadowPackageManager packageManager = shadowOf(RuntimeEnvironment.application.getPackageManager());
    packageManager.addResolveInfoForIntent(intent, ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager)

Example 13 with ShadowPackageManager

use of org.robolectric.shadows.ShadowPackageManager in project android_packages_apps_Settings by omnirom.

the class GestureNavigationSettingsAssistControllerTest method setUp.

@Before
public void setUp() {
    mContext = ApplicationProvider.getApplicationContext();
    // This sets up SystemNavigationPreferenceController.isGestureAvailable() so it returns true
    SettingsShadowResources.overrideResource(R.bool.config_swipe_up_gesture_setting_available, true);
    final String recentsComponentPackageName = "recents.component";
    SettingsShadowResources.overrideResource(R.string.config_recentsComponentName, recentsComponentPackageName + "/.ComponentName");
    final Intent quickStepIntent = new Intent(ACTION_QUICKSTEP).setPackage(recentsComponentPackageName);
    final ResolveInfo info = new ResolveInfo();
    info.serviceInfo = new ServiceInfo();
    info.resolvePackageName = recentsComponentPackageName;
    info.serviceInfo.packageName = info.resolvePackageName;
    info.serviceInfo.name = recentsComponentPackageName;
    info.serviceInfo.applicationInfo = new ApplicationInfo();
    info.serviceInfo.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
    ShadowPackageManager shadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
    shadowPackageManager.addResolveInfoForIntent(quickStepIntent, info);
    mController = new GestureNavigationSettingsAssistController(mContext, KEY_SWIPE_FOR_ASSIST);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) Before(org.junit.Before)

Example 14 with ShadowPackageManager

use of org.robolectric.shadows.ShadowPackageManager in project android_packages_apps_Settings by omnirom.

the class DataUsageUtilsTest method hasEthernet_shouldQueryEthernetSummaryForUser.

@Test
public void hasEthernet_shouldQueryEthernetSummaryForUser() throws Exception {
    ShadowPackageManager pm = shadowOf(RuntimeEnvironment.application.getPackageManager());
    pm.setSystemFeature(PackageManager.FEATURE_ETHERNET, true);
    final String subscriber = "TestSub";
    when(mTelephonyManager.getSubscriberId()).thenReturn(subscriber);
    DataUsageUtils.hasEthernet(mContext);
    verify(mNetworkStatsManager).querySummaryForUser(eq(ConnectivityManager.TYPE_ETHERNET), eq(subscriber), anyLong(), /* startTime */
    anyLong());
}
Also used : ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) Test(org.junit.Test)

Example 15 with ShadowPackageManager

use of org.robolectric.shadows.ShadowPackageManager in project android_packages_apps_Settings by omnirom.

the class AvatarViewMixinTest method queryProviderAuthority_useNewShadowPackagteManager_returnAuthority.

@Test
public void queryProviderAuthority_useNewShadowPackagteManager_returnAuthority() {
    final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(mActivity, mImageView);
    ShadowPackageManager shadowPackageManager = Shadow.extract(mContext.getPackageManager());
    final PackageInfo accountProvider = new PackageInfo();
    accountProvider.packageName = "test.pkg";
    accountProvider.applicationInfo = new ApplicationInfo();
    accountProvider.applicationInfo.flags = ApplicationInfo.FLAG_SYSTEM;
    accountProvider.applicationInfo.packageName = accountProvider.packageName;
    accountProvider.providers = new ProviderInfo[1];
    accountProvider.providers[0] = new ProviderInfo();
    accountProvider.providers[0].authority = FAKE_AUTHORITY;
    accountProvider.providers[0].packageName = accountProvider.packageName;
    accountProvider.providers[0].name = "test.class";
    accountProvider.providers[0].applicationInfo = accountProvider.applicationInfo;
    final ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.providerInfo = accountProvider.providers[0];
    shadowPackageManager.addResolveInfoForIntent(AvatarViewMixin.INTENT_GET_ACCOUNT_DATA, resolveInfo);
    assertThat(avatarViewMixin.queryProviderAuthority()).isEqualTo(FAKE_AUTHORITY);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ProviderInfo(android.content.pm.ProviderInfo) ShadowPackageManager(org.robolectric.shadows.ShadowPackageManager) PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) BatteryFixSliceTest(com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest) Test(org.junit.Test)

Aggregations

ShadowPackageManager (org.robolectric.shadows.ShadowPackageManager)17 Test (org.junit.Test)9 ResolveInfo (android.content.pm.ResolveInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)5 ComponentName (android.content.ComponentName)4 Before (org.junit.Before)4 Intent (android.content.Intent)3 PackageInfo (android.content.pm.PackageInfo)3 PackageManager (android.content.pm.PackageManager)3 ServiceInfo (android.content.pm.ServiceInfo)3 Context (android.content.Context)2 ProviderInfo (android.content.pm.ProviderInfo)2 BatteryFixSliceTest (com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest)2 ActivityThread (android.app.ActivityThread)1 Application (android.app.Application)1 LoadedApk (android.app.LoadedApk)1 Package (android.content.pm.PackageParser.Package)1 Resources (android.content.res.Resources)1 Bundle (android.os.Bundle)1 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)1