Example usage for android.content.pm ServiceInfo FLAG_ISOLATED_PROCESS

List of usage examples for android.content.pm ServiceInfo FLAG_ISOLATED_PROCESS

Introduction

In this page you can find the example usage for android.content.pm ServiceInfo FLAG_ISOLATED_PROCESS.

Prototype

int FLAG_ISOLATED_PROCESS

To view the source code for android.content.pm ServiceInfo FLAG_ISOLATED_PROCESS.

Click Source Link

Document

Bit in #flags : If set, the service will run in its own isolated process.

Usage

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

private Sandbox(int id) {
    mID = id;// www .ja v  a2 s.c  om
    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);
}

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

private Sandbox(int id) {
    mID = id;/*  w  w  w  .  ja v a  2 s  . c  o 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:android.content.pm.PackageParser.java

private Service parseService(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs, int flags,
        String[] outError) throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestService);

    if (mParseServiceArgs == null) {
        mParseServiceArgs = new ParseComponentArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestService_name,
                com.android.internal.R.styleable.AndroidManifestService_label,
                com.android.internal.R.styleable.AndroidManifestService_icon,
                com.android.internal.R.styleable.AndroidManifestService_logo,
                com.android.internal.R.styleable.AndroidManifestService_banner, mSeparateProcesses,
                com.android.internal.R.styleable.AndroidManifestService_process,
                com.android.internal.R.styleable.AndroidManifestService_description,
                com.android.internal.R.styleable.AndroidManifestService_enabled);
        mParseServiceArgs.tag = "<service>";
    }/*from w  ww .  ja v  a 2s.  c o m*/

    mParseServiceArgs.sa = sa;
    mParseServiceArgs.flags = flags;

    Service s = new Service(mParseServiceArgs, new ServiceInfo());
    if (outError[0] != null) {
        sa.recycle();
        return null;
    }

    boolean setExported = sa.hasValue(com.android.internal.R.styleable.AndroidManifestService_exported);
    if (setExported) {
        s.info.exported = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_exported,
                false);
    }

    String str = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestService_permission, 0);
    if (str == null) {
        s.info.permission = owner.applicationInfo.permission;
    } else {
        s.info.permission = str.length() > 0 ? str.toString().intern() : null;
    }

    s.info.flags = 0;
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_stopWithTask, false)) {
        s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
    }
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, false)) {
        s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
    }
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_singleUser, false)) {
        s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
        if (s.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) {
            Slog.w(TAG, "Service exported request ignored due to singleUser: " + s.className + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            s.info.exported = false;
            setExported = true;
        }
    }

    sa.recycle();

    if ((owner.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
        // A heavy-weight application can not have services in its main process
        // We can do direct compare because we intern all strings.
        if (s.info.processName == owner.packageName) {
            outError[0] = "Heavy-weight applications can not have services in main process";
            return null;
        }
    }

    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getName().equals("intent-filter")) {
            ServiceIntentInfo intent = new ServiceIntentInfo(s);
            if (!parseIntent(res, parser, attrs, true, false, intent, outError)) {
                return null;
            }

            s.intents.add(intent);
        } else if (parser.getName().equals("meta-data")) {
            if ((s.metaData = parseMetaData(res, parser, attrs, s.metaData, outError)) == null) {
                return null;
            }
        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <service>: " + parser.getName() + " at " + mArchiveSourcePath
                        + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <service>: " + parser.getName();
                return null;
            }
        }
    }

    if (!setExported) {
        s.info.exported = s.intents.size() > 0;
    }

    return s;
}