Search in sources :

Example 6 with IProcessObserver

use of android.app.IProcessObserver 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();
}
Also used : PackageInfo(android.content.pm.PackageInfo) TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) MockPackageManager(android.test.mock.MockPackageManager) Intent(android.content.Intent) INetworkPolicyListener(android.net.INetworkPolicyListener) Capture(org.easymock.Capture) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) PackageManager(android.content.pm.PackageManager) MockPackageManager(android.test.mock.MockPackageManager) INotificationManager(android.app.INotificationManager) Signature(android.content.pm.Signature) INetworkStatsService(android.net.INetworkStatsService) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager) IProcessObserver(android.app.IProcessObserver) IActivityManager(android.app.IActivityManager)

Example 7 with IProcessObserver

use of android.app.IProcessObserver in project cornerstone by Onskreen.

the class ActivityManagerService method dispatchProcessDied.

private void dispatchProcessDied(int pid, int uid) {
    int i = mProcessObservers.beginBroadcast();
    while (i > 0) {
        i--;
        final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
        if (observer != null) {
            try {
                observer.onProcessDied(pid, uid);
            } catch (RemoteException e) {
            }
        }
    }
    mProcessObservers.finishBroadcast();
}
Also used : IProcessObserver(android.app.IProcessObserver) RemoteException(android.os.RemoteException)

Example 8 with IProcessObserver

use of android.app.IProcessObserver 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();
}
Also used : PackageInfo(android.content.pm.PackageInfo) TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) MockPackageManager(android.test.mock.MockPackageManager) Intent(android.content.Intent) INetworkPolicyListener(android.net.INetworkPolicyListener) Capture(org.easymock.Capture) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) PackageManager(android.content.pm.PackageManager) MockPackageManager(android.test.mock.MockPackageManager) INotificationManager(android.app.INotificationManager) Signature(android.content.pm.Signature) INetworkStatsService(android.net.INetworkStatsService) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager) IProcessObserver(android.app.IProcessObserver) IActivityManager(android.app.IActivityManager)

Example 9 with IProcessObserver

use of android.app.IProcessObserver in project platform_frameworks_base by android.

the class ActivityManagerService method dispatchProcessesChanged.

private void dispatchProcessesChanged() {
    int N;
    synchronized (this) {
        N = mPendingProcessChanges.size();
        if (mActiveProcessChanges.length < N) {
            mActiveProcessChanges = new ProcessChangeItem[N];
        }
        mPendingProcessChanges.toArray(mActiveProcessChanges);
        mPendingProcessChanges.clear();
        if (DEBUG_PROCESS_OBSERVERS)
            Slog.i(TAG_PROCESS_OBSERVERS, "*** Delivering " + N + " process changes");
    }
    int i = mProcessObservers.beginBroadcast();
    while (i > 0) {
        i--;
        final IProcessObserver observer = mProcessObservers.getBroadcastItem(i);
        if (observer != null) {
            try {
                for (int j = 0; j < N; j++) {
                    ProcessChangeItem item = mActiveProcessChanges[j];
                    if ((item.changes & ProcessChangeItem.CHANGE_ACTIVITIES) != 0) {
                        if (DEBUG_PROCESS_OBSERVERS)
                            Slog.i(TAG_PROCESS_OBSERVERS, "ACTIVITIES CHANGED pid=" + item.pid + " uid=" + item.uid + ": " + item.foregroundActivities);
                        observer.onForegroundActivitiesChanged(item.pid, item.uid, item.foregroundActivities);
                    }
                    if ((item.changes & ProcessChangeItem.CHANGE_PROCESS_STATE) != 0) {
                        if (DEBUG_PROCESS_OBSERVERS)
                            Slog.i(TAG_PROCESS_OBSERVERS, "PROCSTATE CHANGED pid=" + item.pid + " uid=" + item.uid + ": " + item.processState);
                        observer.onProcessStateChanged(item.pid, item.uid, item.processState);
                    }
                }
            } catch (RemoteException e) {
            }
        }
    }
    mProcessObservers.finishBroadcast();
    synchronized (this) {
        for (int j = 0; j < N; j++) {
            mAvailProcessChanges.add(mActiveProcessChanges[j]);
        }
    }
}
Also used : IProcessObserver(android.app.IProcessObserver) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 10 with IProcessObserver

use of android.app.IProcessObserver 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();
}
Also used : IPowerManager(android.os.IPowerManager) PackageInfo(android.content.pm.PackageInfo) TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) MockPackageManager(android.test.mock.MockPackageManager) Intent(android.content.Intent) INetworkPolicyListener(android.net.INetworkPolicyListener) Capture(org.easymock.Capture) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) PackageManager(android.content.pm.PackageManager) MockPackageManager(android.test.mock.MockPackageManager) INotificationManager(android.app.INotificationManager) Signature(android.content.pm.Signature) INetworkStatsService(android.net.INetworkStatsService) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager) IProcessObserver(android.app.IProcessObserver) IActivityManager(android.app.IActivityManager)

Aggregations

IProcessObserver (android.app.IProcessObserver)13 RemoteException (android.os.RemoteException)9 IActivityManager (android.app.IActivityManager)4 INotificationManager (android.app.INotificationManager)4 Intent (android.content.Intent)4 PackageInfo (android.content.pm.PackageInfo)4 PackageManager (android.content.pm.PackageManager)4 Signature (android.content.pm.Signature)4 Point (android.graphics.Point)4 IConnectivityManager (android.net.IConnectivityManager)4 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)4 INetworkPolicyListener (android.net.INetworkPolicyListener)4 INetworkStatsService (android.net.INetworkStatsService)4 INetworkManagementService (android.os.INetworkManagementService)4 MockPackageManager (android.test.mock.MockPackageManager)4 TrustedTime (android.util.TrustedTime)4 NetworkPolicyManagerService (com.android.server.net.NetworkPolicyManagerService)4 Capture (org.easymock.Capture)4 IPowerManager (android.os.IPowerManager)1