Example usage for android.content.pm ProviderInfo FLAG_SINGLE_USER

List of usage examples for android.content.pm ProviderInfo FLAG_SINGLE_USER

Introduction

In this page you can find the example usage for android.content.pm ProviderInfo FLAG_SINGLE_USER.

Prototype

int FLAG_SINGLE_USER

To view the source code for android.content.pm ProviderInfo FLAG_SINGLE_USER.

Click Source Link

Document

Bit in #flags : If set, a single instance of the provider will run for all users on the device.

Usage

From source file:android.content.pm.PackageParser.java

private Provider parseProvider(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.AndroidManifestProvider);

    if (mParseProviderArgs == null) {
        mParseProviderArgs = new ParseComponentArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestProvider_name,
                com.android.internal.R.styleable.AndroidManifestProvider_label,
                com.android.internal.R.styleable.AndroidManifestProvider_icon,
                com.android.internal.R.styleable.AndroidManifestProvider_logo,
                com.android.internal.R.styleable.AndroidManifestProvider_banner, mSeparateProcesses,
                com.android.internal.R.styleable.AndroidManifestProvider_process,
                com.android.internal.R.styleable.AndroidManifestProvider_description,
                com.android.internal.R.styleable.AndroidManifestProvider_enabled);
        mParseProviderArgs.tag = "<provider>";
    }/*  www .  ja v a  2 s.c  om*/

    mParseProviderArgs.sa = sa;
    mParseProviderArgs.flags = flags;

    Provider p = new Provider(mParseProviderArgs, new ProviderInfo());
    if (outError[0] != null) {
        sa.recycle();
        return null;
    }

    boolean providerExportedDefault = false;

    if (owner.applicationInfo.targetSdkVersion < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // For compatibility, applications targeting API level 16 or lower
        // should have their content providers exported by default, unless they
        // specify otherwise.
        providerExportedDefault = true;
    }

    p.info.exported = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestProvider_exported,
            providerExportedDefault);

    String cpname = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestProvider_authorities, 0);

    p.info.isSyncable = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestProvider_syncable, false);

    String permission = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestProvider_permission, 0);
    String str = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestProvider_readPermission, 0);
    if (str == null) {
        str = permission;
    }
    if (str == null) {
        p.info.readPermission = owner.applicationInfo.permission;
    } else {
        p.info.readPermission = str.length() > 0 ? str.toString().intern() : null;
    }
    str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestProvider_writePermission,
            0);
    if (str == null) {
        str = permission;
    }
    if (str == null) {
        p.info.writePermission = owner.applicationInfo.permission;
    } else {
        p.info.writePermission = str.length() > 0 ? str.toString().intern() : null;
    }

    p.info.grantUriPermissions = sa
            .getBoolean(com.android.internal.R.styleable.AndroidManifestProvider_grantUriPermissions, false);

    p.info.multiprocess = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestProvider_multiprocess,
            false);

    p.info.initOrder = sa.getInt(com.android.internal.R.styleable.AndroidManifestProvider_initOrder, 0);

    p.info.flags = 0;

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestProvider_singleUser, false)) {
        p.info.flags |= ProviderInfo.FLAG_SINGLE_USER;
        if (p.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) {
            Slog.w(TAG, "Provider exported request ignored due to singleUser: " + p.className + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            p.info.exported = false;
        }
    }

    sa.recycle();

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

    if (cpname == null) {
        outError[0] = "<provider> does not include authorities attribute";
        return null;
    }
    if (cpname.length() <= 0) {
        outError[0] = "<provider> has empty authorities attribute";
        return null;
    }
    p.info.authority = cpname.intern();

    if (!parseProviderTags(res, parser, attrs, p, outError)) {
        return null;
    }

    return p;
}