Example usage for android.content.pm PackageManager getServiceInfo

List of usage examples for android.content.pm PackageManager getServiceInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getServiceInfo.

Prototype

public abstract ServiceInfo getServiceInfo(ComponentName component, @ComponentInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve all of the information we know about a particular service class.

Usage

From source file:edu.umich.flowfence.service.Sandbox.java

private Sandbox(int id) {
    mID = id;// w w  w .j a va2 s .  co  m
    mApplication = FlowfenceApplication.getInstance();
    try {
        Class<?> clazz = Class.forName(String.format(SandboxService.SERVICE_FORMAT, id));
        PackageManager pm = mApplication.getPackageManager();
        mComponent = new ComponentName(mApplication, clazz);
        ServiceInfo svcInfo = pm.getServiceInfo(mComponent, 0);
        if ((svcInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) {
            throw new RuntimeException("Sandbox " + id + " is not isolated!");
        }
    } catch (ClassNotFoundException cnfe) {
        Log.e(TAG, "Could not load sandbox class", cnfe);
        throw new RuntimeException(cnfe);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, "Service class not declared in manifest", nnfe);
        throw new RuntimeException(nnfe);
    }

    mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            handleConnected(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            handleDisconnected();
        }
    };

    mSandboxService = null;
    mTaintSet = null;
    mIsRestarting = false;

    g_onCreated.fire(this, null);
}

From source file:edu.umich.oasis.service.Sandbox.java

private Sandbox(int id) {
    mID = id;/*from   ww  w .j  ava 2 s .c  o  m*/
    mApplication = OASISApplication.getInstance();
    try {
        Class<?> clazz = Class.forName(String.format(SandboxService.SERVICE_FORMAT, id));
        PackageManager pm = mApplication.getPackageManager();
        mComponent = new ComponentName(mApplication, clazz);
        ServiceInfo svcInfo = pm.getServiceInfo(mComponent, 0);
        if ((svcInfo.flags & ServiceInfo.FLAG_ISOLATED_PROCESS) == 0) {
            throw new RuntimeException("Sandbox " + id + " is not isolated!");
        }
    } catch (ClassNotFoundException cnfe) {
        Log.e(TAG, "Could not load sandbox class", cnfe);
        throw new RuntimeException(cnfe);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, "Service class not declared in manifest", nnfe);
        throw new RuntimeException(nnfe);
    }

    mConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            handleConnected(service);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            handleDisconnected();
        }
    };

    mSandboxService = null;
    mTaintSet = null;
    mIsRestarting = false;

    g_onCreated.fire(this, null);
}