Example usage for android.content.pm ApplicationInfo FLAG_ALLOW_CLEAR_USER_DATA

List of usage examples for android.content.pm ApplicationInfo FLAG_ALLOW_CLEAR_USER_DATA

Introduction

In this page you can find the example usage for android.content.pm ApplicationInfo FLAG_ALLOW_CLEAR_USER_DATA.

Prototype

int FLAG_ALLOW_CLEAR_USER_DATA

To view the source code for android.content.pm ApplicationInfo FLAG_ALLOW_CLEAR_USER_DATA.

Click Source Link

Document

Value for #flags : default value for the corresponding ActivityInfo flag.

Usage

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

/**
 * Parse the {@code application} XML tree at the current parse location in a
 * <em>base APK</em> manifest.
 * <p>/*from   w ww. j  a  va 2 s  .  c  om*/
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private boolean parseBaseApplication(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        int flags, String[] outError) throws XmlPullParserException, IOException {
    final ApplicationInfo ai = owner.applicationInfo;
    final String pkgName = owner.applicationInfo.packageName;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestApplication);

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_name,
            0);
    if (name != null) {
        ai.className = buildClassName(pkgName, name, outError);
        if (ai.className == null) {
            sa.recycle();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return false;
        }
    }

    String manageSpaceActivity = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
            Configuration.NATIVE_CONFIG_VERSION);
    if (manageSpaceActivity != null) {
        ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, outError);
    }

    boolean allowBackup = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowBackup,
            true);
    if (allowBackup) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;

        // backupAgent, killAfterRestore, fullBackupContent and restoreAnyVersion are only
        // relevant if backup is possible for the given application.
        String backupAgent = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
                Configuration.NATIVE_CONFIG_VERSION);
        if (backupAgent != null) {
            ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
            if (DEBUG_BACKUP) {
                Slog.v(TAG,
                        "android:backupAgent = " + ai.backupAgentName + " from " + pkgName + "+" + backupAgent);
            }

            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
                    true)) {
                ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY;
            }
        }

        TypedValue v = sa
                .peekValue(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent);
        if (v != null && (ai.fullBackupContent = v.resourceId) == 0) {
            if (DEBUG_BACKUP) {
                Slog.v(TAG, "fullBackupContent specified as boolean=" + (v.data == 0 ? "false" : "true"));
            }
            // "false" => -1, "true" => 0
            ai.fullBackupContent = (v.data == 0 ? -1 : 0);
        }
        if (DEBUG_BACKUP) {
            Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName);
        }
    }

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestApplication_label);
    if (v != null && (ai.labelRes = v.resourceId) == 0) {
        ai.nonLocalizedLabel = v.coerceToString();
    }

    ai.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
    ai.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
    ai.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_banner, 0);
    ai.theme = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
    ai.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_description, 0);

    if ((flags & PARSE_IS_SYSTEM) != 0) {
        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_persistent, false)) {
            ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
        }
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, false)) {
        owner.mRequiredForAllUsers = true;
    }

    String restrictedAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_restrictedAccountType);
    if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
        owner.mRestrictedAccountType = restrictedAccountType;
    }

    String requiredAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_requiredAccountType);
    if (requiredAccountType != null && requiredAccountType.length() > 0) {
        owner.mRequiredAccountType = requiredAccountType;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_debuggable, false)) {
        ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, false)) {
        ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
    }

    owner.baseHardwareAccelerated = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
            owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
    if (owner.baseHardwareAccelerated) {
        ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) {
        ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
            false)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, true)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_testOnly, false)) {
        ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, false)) {
        ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, true)) {
        ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
            false /* default is no RTL support*/)) {
        ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_multiArch, false)) {
        ai.flags |= ApplicationInfo.FLAG_MULTIARCH;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, true)) {
        ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS;
    }

    String str;
    str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_permission,
            0);
    ai.permission = (str != null && str.length() > 0) ? str.intern() : null;

    if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
        str = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
                Configuration.NATIVE_CONFIG_VERSION);
    } else {
        // Some older apps have been seen to use a resource reference
        // here that on older builds was ignored (with a warning).  We
        // need to continue to do this for them so they don't break.
        str = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
    }
    ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, str, outError);

    if (outError[0] == null) {
        CharSequence pname;
        if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
            pname = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestApplication_process,
                    Configuration.NATIVE_CONFIG_VERSION);
        } else {
            // Some older apps have been seen to use a resource reference
            // here that on older builds was ignored (with a warning).  We
            // need to continue to do this for them so they don't break.
            pname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_process);
        }
        ai.processName = buildProcessName(ai.packageName, null, pname, flags, mSeparateProcesses, outError);

        ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);

        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) {
            ai.flags |= ApplicationInfo.FLAG_IS_GAME;
        }

        if (false) {
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
                    false)) {
                ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE;

                // A heavy-weight application can not be in a custom process.
                // We can do direct compare because we intern all strings.
                if (ai.processName != null && ai.processName != ai.packageName) {
                    outError[0] = "cantSaveState applications can not use custom processes";
                }
            }
        }
    }

    ai.uiOptions = sa.getInt(com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);

    sa.recycle();

    if (outError[0] != null) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return false;
    }

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

        String tagName = parser.getName();
        if (tagName.equals("activity")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
                    owner.baseHardwareAccelerated);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (tagName.equals("receiver")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.receivers.add(a);

        } else if (tagName.equals("service")) {
            Service s = parseService(owner, res, parser, attrs, flags, outError);
            if (s == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.services.add(s);

        } else if (tagName.equals("provider")) {
            Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
            if (p == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.providers.add(p);

        } else if (tagName.equals("activity-alias")) {
            Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (parser.getName().equals("meta-data")) {
            // note: application meta-data is stored off to the side, so it can
            // remain null in the primary copy (we like to avoid extra copies because
            // it can be large)
            if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
                    outError)) == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

        } else if (tagName.equals("library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestLibrary_name);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (!ArrayUtils.contains(owner.libraryNames, lname)) {
                    owner.libraryNames = ArrayUtils.add(owner.libraryNames, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
            boolean req = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
                    true);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (req) {
                    owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname);
                } else {
                    owner.usesOptionalLibraries = ArrayUtils.add(owner.usesOptionalLibraries, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-package")) {
            // Dependencies for app installers; we don't currently try to
            // enforce this.
            XmlUtils.skipCurrentTag(parser);

        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <application>: " + tagName + " at " + mArchiveSourcePath
                        + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <application>: " + tagName;
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }
        }
    }

    modifySharedLibrariesForBackwardCompatibility(owner);

    if (hasDomainURLs(owner)) {
        owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    } else {
        owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    }

    return true;
}