use of android.test.mock.MockPackageManager in project android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManagerServiceTest method _setUp.
public void _setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
use of android.test.mock.MockPackageManager in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerServiceTest method _setUp.
public void _setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
use of android.test.mock.MockPackageManager in project android_frameworks_base by crdroidandroid.
the class NetworkPolicyManagerServiceTest method _setUp.
public void _setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
use of android.test.mock.MockPackageManager in project mixpanel-android by mixpanel.
the class MixpanelBasicTest method testConfiguration.
public void testConfiguration() {
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.metaData = new Bundle();
appInfo.metaData.putInt("com.mixpanel.android.MPConfig.BulkUploadLimit", 1);
appInfo.metaData.putInt("com.mixpanel.android.MPConfig.FlushInterval", 2);
appInfo.metaData.putInt("com.mixpanel.android.MPConfig.DataExpiration", 3);
appInfo.metaData.putBoolean("com.mixpanel.android.MPConfig.AutoShowMixpanelUpdates", false);
appInfo.metaData.putBoolean("com.mixpanel.android.MPConfig.DisableGestureBindingUI", true);
appInfo.metaData.putBoolean("com.mixpanel.android.MPConfig.DisableEmulatorBindingUI", true);
appInfo.metaData.putBoolean("com.mixpanel.android.MPConfig.DisableAppOpenEvent", true);
appInfo.metaData.putString("com.mixpanel.android.MPConfig.EventsEndpoint", "EVENTS ENDPOINT");
appInfo.metaData.putString("com.mixpanel.android.MPConfig.PeopleEndpoint", "PEOPLE ENDPOINT");
appInfo.metaData.putString("com.mixpanel.android.MPConfig.DecideEndpoint", "DECIDE ENDPOINT");
final PackageManager packageManager = new MockPackageManager() {
@Override
public ApplicationInfo getApplicationInfo(String packageName, int flags) {
assertEquals(packageName, "TEST PACKAGE NAME");
assertTrue((flags & PackageManager.GET_META_DATA) == PackageManager.GET_META_DATA);
return appInfo;
}
};
final Context context = new MockContext() {
@Override
public String getPackageName() {
return "TEST PACKAGE NAME";
}
@Override
public PackageManager getPackageManager() {
return packageManager;
}
};
final MPConfig testConfig = MPConfig.readConfig(context);
assertEquals(1, testConfig.getBulkUploadLimit());
assertEquals(2, testConfig.getFlushInterval());
assertEquals(3, testConfig.getDataExpiration());
assertEquals(true, testConfig.getDisableEmulatorBindingUI());
assertEquals(true, testConfig.getDisableGestureBindingUI());
assertEquals(true, testConfig.getDisableAppOpenEvent());
assertEquals(false, testConfig.getAutoShowMixpanelUpdates());
assertEquals("EVENTS ENDPOINT", testConfig.getEventsEndpoint());
assertEquals("PEOPLE ENDPOINT", testConfig.getPeopleEndpoint());
assertEquals("DECIDE ENDPOINT", testConfig.getDecideEndpoint());
}
use of android.test.mock.MockPackageManager in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManagerServiceTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mPowerManager = createMock(IPowerManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mPowerManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
// expect to answer screen status during systemReady()
expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
Aggregations