Search in sources :

Example 1 with BroadcastInterceptingContext

use of com.android.server.BroadcastInterceptingContext in project android_frameworks_base by ResurrectionRemix.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Example 2 with BroadcastInterceptingContext

use of com.android.server.BroadcastInterceptingContext in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Example 3 with BroadcastInterceptingContext

use of com.android.server.BroadcastInterceptingContext in project android_frameworks_base by crdroidandroid.

the class NetworkStatsServiceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    mServiceContext = new BroadcastInterceptingContext(getContext());
    mStatsDir = getContext().getFilesDir();
    if (mStatsDir.exists()) {
        IoUtils.deleteContents(mStatsDir);
    }
    mNetManager = createMock(INetworkManagementService.class);
    // TODO: Mock AlarmManager when migrating this test to Mockito.
    AlarmManager alarmManager = (AlarmManager) mServiceContext.getSystemService(Context.ALARM_SERVICE);
    mTime = createMock(TrustedTime.class);
    mSettings = createMock(NetworkStatsSettings.class);
    mConnManager = createMock(IConnectivityManager.class);
    PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
    mService = new NetworkStatsService(mServiceContext, mNetManager, alarmManager, wakeLock, mTime, TelephonyManager.getDefault(), mSettings, new NetworkStatsObservers(), mStatsDir, getBaseDir(mStatsDir));
    mHandlerThread = new IdleableHandlerThread("HandlerThread");
    mHandlerThread.start();
    Handler.Callback callback = new NetworkStatsService.HandlerCallback(mService);
    mHandler = new Handler(mHandlerThread.getLooper(), callback);
    mService.setHandler(mHandler, callback);
    mService.bindConnectivityManager(mConnManager);
    mElapsedRealtime = 0L;
    expectCurrentTime();
    expectDefaultSettings();
    expectNetworkStatsUidDetail(buildEmptyStats());
    expectSystemReady();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    replay();
    mService.systemReady();
    mSession = mService.openSession();
    verifyAndReset();
    mNetworkObserver = networkObserver.getValue();
}
Also used : TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) BroadcastInterceptingContext(com.android.server.BroadcastInterceptingContext) Handler(android.os.Handler) IdleHandler(android.os.MessageQueue.IdleHandler) Capture(org.easymock.Capture) NetworkStatsSettings(com.android.server.net.NetworkStatsService.NetworkStatsSettings) PowerManager(android.os.PowerManager) NetworkStatsService(com.android.server.net.NetworkStatsService) IAlarmManager(android.app.IAlarmManager) AlarmManager(android.app.AlarmManager) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager)

Aggregations

AlarmManager (android.app.AlarmManager)3 IAlarmManager (android.app.IAlarmManager)3 IConnectivityManager (android.net.IConnectivityManager)3 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)3 Handler (android.os.Handler)3 INetworkManagementService (android.os.INetworkManagementService)3 IdleHandler (android.os.MessageQueue.IdleHandler)3 PowerManager (android.os.PowerManager)3 TrustedTime (android.util.TrustedTime)3 BroadcastInterceptingContext (com.android.server.BroadcastInterceptingContext)3 NetworkStatsService (com.android.server.net.NetworkStatsService)3 NetworkStatsSettings (com.android.server.net.NetworkStatsService.NetworkStatsSettings)3 Capture (org.easymock.Capture)3