Search in sources :

Example 41 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by ResurrectionRemix.

the class DefaultPermissionGrantPolicy method readDefaultPermissionExceptionsLPw.

@NonNull
private ArrayMap<String, List<DefaultPermissionGrant>> readDefaultPermissionExceptionsLPw() {
    File dir = new File(Environment.getRootDirectory(), "etc/default-permissions");
    if (!dir.exists() || !dir.isDirectory() || !dir.canRead()) {
        return new ArrayMap<>(0);
    }
    File[] files = dir.listFiles();
    if (files == null) {
        return new ArrayMap<>(0);
    }
    ArrayMap<String, List<DefaultPermissionGrant>> grantExceptions = new ArrayMap<>();
    // Iterate over the files in the directory and scan .xml files
    for (File file : files) {
        if (!file.getPath().endsWith(".xml")) {
            Slog.i(TAG, "Non-xml file " + file + " in " + dir + " directory, ignoring");
            continue;
        }
        if (!file.canRead()) {
            Slog.w(TAG, "Default permissions file " + file + " cannot be read");
            continue;
        }
        try (InputStream str = new BufferedInputStream(new FileInputStream(file))) {
            XmlPullParser parser = Xml.newPullParser();
            parser.setInput(str, null);
            parse(parser, grantExceptions);
        } catch (XmlPullParserException | IOException e) {
            Slog.w(TAG, "Error reading default permissions file " + file, e);
        }
    }
    return grantExceptions;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayMap(android.util.ArrayMap) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) ArrayList(java.util.ArrayList) List(java.util.List) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) NonNull(android.annotation.NonNull)

Example 42 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by ResurrectionRemix.

the class VendorConfig method readVendorConfigs.

/**
     * Read the vendor configuration file.
     *
     * @param context The content issuing the read
     *
     * @return An map pointing from vendor name to config
     *
     * @throws IOException
     * @throws XmlPullParserException
     */
@NonNull
private static ArrayMap<String, VendorConfig> readVendorConfigs(@NonNull final Context context) throws IOException, XmlPullParserException {
    try (XmlResourceParser parser = context.getResources().getXml(R.xml.vendorconfigs)) {
        // Skip header
        int parsingEvent;
        do {
            parsingEvent = parser.next();
        } while (parsingEvent != XmlResourceParser.START_TAG);
        ArrayList<VendorConfig> configs = readTagList(parser, VENDORS_TAG, VENDOR_TAG, new TagReader<VendorConfig>() {

            public VendorConfig readTag(XmlPullParser parser, String tagName) throws XmlPullParserException, IOException {
                return readVendorConfig(context, parser, tagName);
            }
        });
        ArrayMap<String, VendorConfig> configMap = new ArrayMap<>(configs.size());
        final int numConfigs = configs.size();
        for (int i = 0; i < numConfigs; i++) {
            VendorConfig config = configs.get(i);
            configMap.put(config.name, config);
        }
        return configMap;
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayMap(android.util.ArrayMap) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) NonNull(android.annotation.NonNull)

Example 43 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by ResurrectionRemix.

the class PackageParser method parseBaseApkCommon.

/**
     * This is the common parsing routing for handling parent and child
     * packages in a base APK. The difference between parent and child
     * parsing is that some tags are not supported by child packages as
     * well as some manifest attributes are ignored. The implementation
     * assumes the calling code has already handled the manifest tag if needed
     * (this applies to the parent only).
     *
     * @param pkg The package which to populate
     * @param acceptedTags Which tags to handle, null to handle all
     * @param res Resources against which to resolve values
     * @param parser Parser of the manifest
     * @param flags Flags about how to parse
     * @param outError Human readable error if parsing fails
     * @return The package if parsing succeeded or null.
     *
     * @throws XmlPullParserException
     * @throws IOException
     */
private Package parseBaseApkCommon(Package pkg, Set<String> acceptedTags, Resources res, XmlResourceParser parser, int flags, String[] outError) throws XmlPullParserException, IOException {
    mParseInstrumentationArgs = null;
    mParseActivityArgs = null;
    mParseServiceArgs = null;
    mParseProviderArgs = null;
    int type;
    boolean foundApp = false;
    TypedArray sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifest);
    String str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
    if (str != null && str.length() > 0) {
        String nameError = validateName(str, true, false);
        if (nameError != null && !"android".equals(pkg.packageName)) {
            outError[0] = "<manifest> specifies bad sharedUserId name \"" + str + "\": " + nameError;
            mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
            return null;
        }
        pkg.mSharedUserId = str.intern();
        pkg.mSharedUserLabel = sa.getResourceId(com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
    }
    pkg.installLocation = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_installLocation, PARSE_DEFAULT_INSTALL_LOCATION);
    pkg.applicationInfo.installLocation = pkg.installLocation;
    /* Set the global "forward lock" flag */
    if ((flags & PARSE_FORWARD_LOCK) != 0) {
        pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK;
    }
    /* Set the global "on SD card" flag */
    if ((flags & PARSE_EXTERNAL_STORAGE) != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }
    if ((flags & PARSE_IS_EPHEMERAL) != 0) {
        pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_EPHEMERAL;
    }
    // Resource boolean are -1, so 1 means we don't know the value.
    int supportsSmallScreens = 1;
    int supportsNormalScreens = 1;
    int supportsLargeScreens = 1;
    int supportsXLargeScreens = 1;
    int resizeable = 1;
    int anyDensity = 1;
    int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (acceptedTags != null && !acceptedTags.contains(tagName)) {
            Slog.w(TAG, "Skipping unsupported element under <manifest>: " + tagName + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
        if (tagName.equals(TAG_APPLICATION)) {
            if (foundApp) {
                if (RIGID_PARSER) {
                    outError[0] = "<manifest> has more than one <application>";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return null;
                } else {
                    Slog.w(TAG, "<manifest> has more than one <application>");
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
            }
            foundApp = true;
            if (!parseBaseApplication(pkg, res, parser, flags, outError)) {
                return null;
            }
        } else if (tagName.equals(TAG_OVERLAY)) {
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestResourceOverlay);
            pkg.mOverlayTarget = sa.getString(com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage);
            sa.recycle();
            if (pkg.mOverlayTarget == null) {
                outError[0] = "<overlay> does not specify a target package";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_KEY_SETS)) {
            if (!parseKeySets(pkg, res, parser, outError)) {
                return null;
            }
        } else if (tagName.equals(TAG_PERMISSION_GROUP)) {
            if (parsePermissionGroup(pkg, flags, res, parser, outError) == null) {
                return null;
            }
        } else if (tagName.equals(TAG_PERMISSION)) {
            if (parsePermission(pkg, res, parser, outError) == null) {
                return null;
            }
        } else if (tagName.equals(TAG_PERMISSION_TREE)) {
            if (parsePermissionTree(pkg, res, parser, outError) == null) {
                return null;
            }
        } else if (tagName.equals(TAG_USES_PERMISSION)) {
            if (!parseUsesPermission(pkg, res, parser)) {
                return null;
            }
        } else if (tagName.equals(TAG_USES_PERMISSION_SDK_M) || tagName.equals(TAG_USES_PERMISSION_SDK_23)) {
            if (!parseUsesPermission(pkg, res, parser)) {
                return null;
            }
        } else if (tagName.equals(TAG_USES_CONFIGURATION)) {
            ConfigurationInfo cPref = new ConfigurationInfo();
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
            cPref.reqTouchScreen = sa.getInt(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen, Configuration.TOUCHSCREEN_UNDEFINED);
            cPref.reqKeyboardType = sa.getInt(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType, Configuration.KEYBOARD_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard, false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
            }
            cPref.reqNavigation = sa.getInt(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation, Configuration.NAVIGATION_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav, false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
            }
            sa.recycle();
            pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_USES_FEATURE)) {
            FeatureInfo fi = parseUsesFeature(res, parser);
            pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi);
            if (fi.name == null) {
                ConfigurationInfo cPref = new ConfigurationInfo();
                cPref.reqGlEsVersion = fi.reqGlEsVersion;
                pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_FEATURE_GROUP)) {
            FeatureGroupInfo group = new FeatureGroupInfo();
            ArrayList<FeatureInfo> features = null;
            final int innerDepth = parser.getDepth();
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }
                final String innerTagName = parser.getName();
                if (innerTagName.equals("uses-feature")) {
                    FeatureInfo featureInfo = parseUsesFeature(res, parser);
                    // FeatureGroups are stricter and mandate that
                    // any <uses-feature> declared are mandatory.
                    featureInfo.flags |= FeatureInfo.FLAG_REQUIRED;
                    features = ArrayUtils.add(features, featureInfo);
                } else {
                    Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
                }
                XmlUtils.skipCurrentTag(parser);
            }
            if (features != null) {
                group.features = new FeatureInfo[features.size()];
                group.features = features.toArray(group.features);
            }
            pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group);
        } else if (tagName.equals(TAG_USES_SDK)) {
            if (SDK_VERSION > 0) {
                sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestUsesSdk);
                int minVers = 1;
                String minCode = null;
                int targetVers = 0;
                String targetCode = null;
                TypedValue val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = minVers = val.data;
                    }
                }
                val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = val.string.toString();
                        if (minCode == null) {
                            minCode = targetCode;
                        }
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = val.data;
                    }
                }
                sa.recycle();
                if (minCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (minCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + minCode + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + minCode + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    pkg.applicationInfo.minSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
                } else if (minVers > SDK_VERSION) {
                    outError[0] = "Requires newer sdk version #" + minVers + " (current version is #" + SDK_VERSION + ")";
                    mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                    return null;
                } else {
                    pkg.applicationInfo.minSdkVersion = minVers;
                }
                if (targetCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (targetCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + targetCode + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + targetCode + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    // If the code matches, it definitely targets this SDK.
                    pkg.applicationInfo.targetSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
                } else {
                    pkg.applicationInfo.targetSdkVersion = targetVers;
                }
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_SUPPORT_SCREENS)) {
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestSupportsScreens);
            pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, 0);
            pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, 0);
            pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, 0);
            // This is a trick to get a boolean and still able to detect
            // if a value was actually set.
            supportsSmallScreens = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens, supportsSmallScreens);
            supportsNormalScreens = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens, supportsNormalScreens);
            supportsLargeScreens = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens, supportsLargeScreens);
            supportsXLargeScreens = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens, supportsXLargeScreens);
            resizeable = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, resizeable);
            anyDensity = sa.getInteger(com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, anyDensity);
            sa.recycle();
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_PROTECTED_BROADCAST)) {
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);
            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String name = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);
            String permission = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_permission);
            sa.recycle();
            if (name != null && (flags & PARSE_IS_SYSTEM) != 0) {
                if (pkg.protectedBroadcasts == null) {
                    pkg.protectedBroadcasts = new ArrayMap<>();
                }
                if (!pkg.protectedBroadcasts.containsKey(name)) {
                    pkg.protectedBroadcasts.put(name.intern(), permission != null ? permission.intern() : null);
                }
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_INSTRUMENTATION)) {
            if (parseInstrumentation(pkg, res, parser, outError) == null) {
                return null;
            }
        } else if (tagName.equals(TAG_ORIGINAL_PACKAGE)) {
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestOriginalPackage);
            String orig = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
            if (!pkg.packageName.equals(orig)) {
                if (pkg.mOriginalPackages == null) {
                    pkg.mOriginalPackages = new ArrayList<String>();
                    pkg.mRealPackage = pkg.packageName;
                }
                pkg.mOriginalPackages.add(orig);
            }
            sa.recycle();
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_ADOPT_PERMISSIONS)) {
            sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestOriginalPackage);
            String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
            sa.recycle();
            if (name != null) {
                if (pkg.mAdoptPermissions == null) {
                    pkg.mAdoptPermissions = new ArrayList<String>();
                }
                pkg.mAdoptPermissions.add(name);
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (tagName.equals(TAG_USES_GL_TEXTURE)) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals(TAG_COMPATIBLE_SCREENS)) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals(TAG_SUPPORTS_INPUT)) {
            //
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals(TAG_EAT_COMMENT)) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals(TAG_PACKAGE)) {
            if (!MULTI_PACKAGE_APK_ENABLED) {
                XmlUtils.skipCurrentTag(parser);
                continue;
            }
            if (!parseBaseApkChild(pkg, res, parser, flags, outError)) {
                // If parsing a child failed the error is already set
                return null;
            }
        } else if (tagName.equals(TAG_RESTRICT_UPDATE)) {
            if ((flags & PARSE_IS_SYSTEM_DIR) != 0) {
                sa = res.obtainAttributes(parser, com.android.internal.R.styleable.AndroidManifestRestrictUpdate);
                final String hash = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestRestrictUpdate_hash, 0);
                sa.recycle();
                pkg.restrictUpdateHash = null;
                if (hash != null) {
                    final int hashLength = hash.length();
                    final byte[] hashBytes = new byte[hashLength / 2];
                    for (int i = 0; i < hashLength; i += 2) {
                        hashBytes[i / 2] = (byte) ((Character.digit(hash.charAt(i), 16) << 4) + Character.digit(hash.charAt(i + 1), 16));
                    }
                    pkg.restrictUpdateHash = hashBytes;
                }
            }
            XmlUtils.skipCurrentTag(parser);
        } else if (RIGID_PARSER) {
            outError[0] = "Bad element under <manifest>: " + parser.getName();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        } else {
            Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
    }
    if (!foundApp && pkg.instrumentation.size() == 0) {
        outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
    }
    final int NP = PackageParser.NEW_PERMISSIONS.length;
    StringBuilder implicitPerms = null;
    for (int ip = 0; ip < NP; ip++) {
        final PackageParser.NewPermissionInfo npi = PackageParser.NEW_PERMISSIONS[ip];
        if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
            break;
        }
        if (!pkg.requestedPermissions.contains(npi.name)) {
            if (implicitPerms == null) {
                implicitPerms = new StringBuilder(128);
                implicitPerms.append(pkg.packageName);
                implicitPerms.append(": compat added ");
            } else {
                implicitPerms.append(' ');
            }
            implicitPerms.append(npi.name);
            pkg.requestedPermissions.add(npi.name);
        }
    }
    if (implicitPerms != null) {
        Slog.i(TAG, implicitPerms.toString());
    }
    final int NS = PackageParser.SPLIT_PERMISSIONS.length;
    for (int is = 0; is < NS; is++) {
        final PackageParser.SplitPermissionInfo spi = PackageParser.SPLIT_PERMISSIONS[is];
        if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk || !pkg.requestedPermissions.contains(spi.rootPerm)) {
            continue;
        }
        for (int in = 0; in < spi.newPerms.length; in++) {
            final String perm = spi.newPerms[in];
            if (!pkg.requestedPermissions.contains(perm)) {
                pkg.requestedPermissions.add(perm);
            }
        }
    }
    if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
    }
    if (supportsNormalScreens != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
    }
    if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
    }
    if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
    }
    if (resizeable < 0 || (resizeable > 0 && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
    }
    if (anyDensity < 0 || (anyDensity > 0 && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
    }
    return pkg;
}
Also used : ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue)

Example 44 with ArrayMap

use of android.util.ArrayMap in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AppStateAppOpsBridge method loadAllExtraInfo.

@Override
protected void loadAllExtraInfo() {
    SparseArray<ArrayMap<String, PermissionState>> entries = getEntries();
    // Load state info.
    loadPermissionsStates(entries);
    loadAppOpsStates(entries);
    // Map states to application info.
    List<AppEntry> apps = mAppSession.getAllApps();
    final int N = apps.size();
    for (int i = 0; i < N; i++) {
        AppEntry app = apps.get(i);
        int userId = UserHandle.getUserId(app.info.uid);
        ArrayMap<String, PermissionState> userMap = entries.get(userId);
        app.extraInfo = userMap != null ? userMap.get(app.info.packageName) : null;
    }
}
Also used : AppEntry(com.android.settingslib.applications.ApplicationsState.AppEntry) ArrayMap(android.util.ArrayMap)

Example 45 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by ResurrectionRemix.

the class ArrayMapTests method run.

public static void run() {
    HashMap<ControlledHash, Integer> hashMap = new HashMap<ControlledHash, Integer>();
    ArrayMap<ControlledHash, Integer> arrayMap = new ArrayMap<ControlledHash, Integer>();
    HashSet<ControlledHash> hashSet = new HashSet<ControlledHash>();
    ArraySet<ControlledHash> arraySet = new ArraySet<ControlledHash>();
    for (int i = 0; i < OPS.length; i++) {
        Integer oldHash;
        Integer oldArray;
        boolean hashChanged;
        boolean arrayChanged;
        ControlledHash key = KEYS[i] < 0 ? null : new ControlledHash(KEYS[i]);
        switch(OPS[i]) {
            case OP_ADD:
                Log.i("test", "Adding key: " + KEYS[i]);
                oldHash = hashMap.put(key, i);
                oldArray = arrayMap.put(key, i);
                hashChanged = hashSet.add(key);
                arrayChanged = arraySet.add(key);
                break;
            case OP_REM:
                Log.i("test", "Removing key: " + KEYS[i]);
                oldHash = hashMap.remove(key);
                oldArray = arrayMap.remove(key);
                hashChanged = hashSet.remove(key);
                arrayChanged = arraySet.remove(key);
                break;
            default:
                Log.e("test", "Bad operation " + OPS[i] + " @ " + i);
                return;
        }
        if (!compare(oldHash, oldArray)) {
            Log.e("test", "Bad result: expected " + oldHash + ", got " + oldArray);
            dump(hashMap, arrayMap);
            return;
        }
        if (hashChanged != arrayChanged) {
            Log.e("test", "Bad change: expected " + hashChanged + ", got " + arrayChanged);
            dump(hashSet, arraySet);
            return;
        }
        if (!validateArrayMap(arrayMap)) {
            dump(hashMap, arrayMap);
            return;
        }
        if (!compareMaps(hashMap, arrayMap)) {
            dump(hashMap, arrayMap);
            return;
        }
        if (!compareSets(hashSet, arraySet)) {
            dump(hashSet, arraySet);
            return;
        }
    }
    arrayMap.put(new ControlledHash(50000), 100);
    ControlledHash lookup = new ControlledHash(50000);
    Iterator<ControlledHash> it = arrayMap.keySet().iterator();
    while (it.hasNext()) {
        if (it.next().equals(lookup)) {
            it.remove();
        }
    }
    if (arrayMap.containsKey(lookup)) {
        Log.e("test", "Bad map iterator: didn't remove test key");
        dump(hashMap, arrayMap);
    }
    arraySet.add(new ControlledHash(50000));
    it = arraySet.iterator();
    while (it.hasNext()) {
        if (it.next().equals(lookup)) {
            it.remove();
        }
    }
    if (arraySet.contains(lookup)) {
        Log.e("test", "Bad set iterator: didn't remove test key");
        dump(hashSet, arraySet);
    }
    if (!equalsMapTest()) {
        return;
    }
    if (!equalsSetTest()) {
        return;
    }
    // map copy constructor test
    ArrayMap newMap = new ArrayMap<Integer, String>();
    for (int i = 0; i < 10; ++i) {
        newMap.put(i, String.valueOf(i));
    }
    ArrayMap mapCopy = new ArrayMap(newMap);
    if (!compare(mapCopy, newMap)) {
        Log.e("test", "ArrayMap copy constructor failure: expected " + newMap + ", got " + mapCopy);
        dump(newMap, mapCopy);
        return;
    }
    // set copy constructor test
    ArraySet newSet = new ArraySet<Integer>();
    for (int i = 0; i < 10; ++i) {
        newSet.add(i);
    }
    ArraySet setCopy = new ArraySet(newSet);
    if (!compare(setCopy, newSet)) {
        Log.e("test", "ArraySet copy constructor failure: expected " + newSet + ", got " + setCopy);
        dump(newSet, setCopy);
        return;
    }
    Log.e("test", "Test successful; printing final map.");
    dump(hashMap, arrayMap);
    Log.e("test", "Test successful; printing final set.");
    dump(hashSet, arraySet);
}
Also used : ArraySet(android.util.ArraySet) HashMap(java.util.HashMap) ArrayMap(android.util.ArrayMap) HashSet(java.util.HashSet)

Aggregations

ArrayMap (android.util.ArrayMap)242 ArraySet (android.util.ArraySet)77 ArrayList (java.util.ArrayList)58 PublicKey (java.security.PublicKey)49 IOException (java.io.IOException)27 HashMap (java.util.HashMap)26 Map (java.util.Map)19 Point (android.graphics.Point)17 X509Certificate (java.security.cert.X509Certificate)15 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)15 RemoteException (android.os.RemoteException)14 List (java.util.List)14 ComponentName (android.content.ComponentName)13 SparseArray (android.util.SparseArray)12 Field (java.lang.reflect.Field)12 Method (java.lang.reflect.Method)11 NonNull (android.annotation.NonNull)10 Paint (android.graphics.Paint)10 BatterySipper (com.android.internal.os.BatterySipper)10 BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)10