List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:android.support.v7.internal.widget.ActionBarView.java
public ActionBarView(Context context, AttributeSet attrs) { super(context, attrs); mContext = context;//from w w w . j a va 2 s .co m // Background is always provided by the container. setBackgroundResource(0); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, R.attr.actionBarStyle, 0); ApplicationInfo appInfo = context.getApplicationInfo(); PackageManager pm = context.getPackageManager(); mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD); mTitle = a.getText(R.styleable.ActionBar_title); mSubtitle = a.getText(R.styleable.ActionBar_subtitle); mLogo = a.getDrawable(R.styleable.ActionBar_logo); if (mLogo == null) { if (Build.VERSION.SDK_INT >= 9) { if (context instanceof Activity) { try { mLogo = pm.getActivityLogo(((Activity) context).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Activity component name not found!", e); } } if (mLogo == null) { mLogo = appInfo.loadLogo(pm); } } } // TODO(trevorjohns): Should these use the android namespace mIcon = a.getDrawable(R.styleable.ActionBar_icon); if (mIcon == null) { if (context instanceof Activity) { try { mIcon = pm.getActivityIcon(((Activity) context).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Activity component name not found!", e); } } if (mIcon == null) { mIcon = appInfo.loadIcon(pm); } } final LayoutInflater inflater = LayoutInflater.from(context); final int homeResId = a.getResourceId(R.styleable.ActionBar_homeLayout, R.layout.abc_action_bar_home); mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false); mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false); mExpandedHomeLayout.setUp(true); mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener); mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abc_action_bar_up_description)); mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0); mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0); mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0); mIndeterminateProgressStyle = a.getResourceId(R.styleable.ActionBar_indeterminateProgressStyle, 0); mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0); mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0); setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT)); final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0); if (customNavId != 0) { mCustomNavView = (View) inflater.inflate(customNavId, this, false); mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD; setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM); } mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0); a.recycle(); mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle); mHomeLayout.setOnClickListener(mUpClickListener); mHomeLayout.setClickable(true); mHomeLayout.setFocusable(true); }
From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java
/** * Get attributes// ww w .j ava 2 s.co m **/ private void getAttributes(AttributeSet attrs) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup); hasDivider = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_dividerSize); dividerSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerSize, 0); dividerColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_dividerColor, Color.WHITE); dividerPadding = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerPadding, 0); dividerRadius = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerRadius, 0); textColorOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor, Color.GRAY); hasTextColorOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor); drawableTintOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint, Color.GRAY); hasDrawableTintOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint); selectorColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorColor, Color.GRAY); animateSelector = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelector, 0); animateSelectorDuration = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelectorDuration, 500); shadow = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_shadow, false); shadowElevation = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_shadowElevation, 0); shadowMargin = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMargin, -1); shadowMarginTop = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginTop, 0); shadowMarginBottom = typedArray .getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginBottom, 0); shadowMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginLeft, 0); shadowMarginRight = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginRight, 0); radius = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_radius, 0); position = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_position, 0); backgroundColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_backgroundColor, Color.WHITE); ripple = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_ripple, false); hasRippleColor = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_rippleColor); rippleColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_rippleColor, Color.GRAY); borderSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_borderSize, 0); borderColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_borderColor, Color.BLACK); backgroundDrawable = typedArray.getDrawable(R.styleable.SegmentedButtonGroup_sbg_backgroundDrawable); selectorBackgroundDrawable = typedArray .getDrawable(R.styleable.SegmentedButtonGroup_sbg_selectorBackgroundDrawable); dividerBackgroundDrawable = typedArray .getDrawable(R.styleable.SegmentedButtonGroup_sbg_dividerBackgroundDrawable); enabled = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_enabled, true); try { clickable = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true); } catch (Exception ex) { Log.d("SegmentedButtonGroup", ex.toString()); } typedArray.recycle(); }
From source file:cc.flydev.launcher.Workspace.java
/** * Used to inflate the Workspace from XML. * * @param context The application's context. * @param attrs The attributes set containing the Workspace's customization values. * @param defStyle Unused.//w ww . j av a 2s . c om */ public Workspace(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mContentIsRefreshable = false; mOutlineHelper = HolographicOutlineHelper.obtain(context); mDragEnforcer = new DropTarget.DragEnforcer(context); // With workspace, data is available straight from the get-go setDataIsReady(); mLauncher = (Launcher) context; final Resources res = getResources(); mWorkspaceFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens); mFadeInAdjacentScreens = false; mWallpaperManager = WallpaperManager.getInstance(context); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0); mSpringLoadedShrinkFactor = res.getInteger(R.integer.config_workspaceSpringLoadShrinkPercentage) / 100.0f; mOverviewModeShrinkFactor = res.getInteger(R.integer.config_workspaceOverviewShrinkPercentage) / 100.0f; mOverviewModePageOffset = res.getDimensionPixelSize(R.dimen.overview_mode_page_offset); mCameraDistance = res.getInteger(R.integer.config_cameraDistance); mOriginalDefaultPage = mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); a.recycle(); setOnHierarchyChangeListener(this); setHapticFeedbackEnabled(false); initWorkspace(); // Disable multitouch across the workspace/all apps/customize tray setMotionEventSplittingEnabled(true); setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); }
From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java
public PaginationSeekBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFocusable(true);/*from w w w .j ava 2 s. c om*/ setWillNotDraw(false); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); float density = context.getResources().getDisplayMetrics().density; mTrackHeight = (int) (1 * density); mScrubberHeight = (int) (4 * density); int thumbSize = (int) (density * ThumbDrawable.DEFAULT_SIZE_DP); //Extra pixels for a touch area of 48dp int touchBounds = (int) (density * 32); mAddedTouchBounds = (touchBounds - thumbSize) / 2; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, defStyle); int max = 100; int min = 0; int value = 1; mMirrorForRtl = a.getBoolean(R.styleable.PaginationSeekBar_psb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.getBoolean(R.styleable.PaginationSeekBar_psb_allowTrackClickToDrag, mAllowTrackClick); int indexMax = R.styleable.PaginationSeekBar_psb_max; int indexMin = R.styleable.PaginationSeekBar_psb_min; int indexValue = R.styleable.PaginationSeekBar_psb_value; pageCountPerOneBoard = R.styleable.PaginationSeekBar_psb_pageCountPerOneBoard; final TypedValue out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.getValue(indexMax, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { max = a.getDimensionPixelSize(indexMax, max); } else { max = a.getInteger(indexMax, max); } } if (a.getValue(indexMin, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { min = a.getDimensionPixelSize(indexMin, min); } else { min = a.getInteger(indexMin, min); } } if (a.getValue(indexValue, out)) { if (out.type == TypedValue.TYPE_DIMENSION) { value = a.getDimensionPixelSize(indexValue, value); } else { value = a.getInteger(indexValue, value); } } if (a.getValue(pageCountPerOneBoard, out)) { pageCountPerOneBoard = a.getInteger(pageCountPerOneBoard, pageCountPerOneBoard); } mMin = min; mMax = Math.max(min + 1, max); mValue = Math.max(min, Math.min(max, value)); updateKeyboardRange(); mPrevPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorPrevPageText); mNextPageText = a.getString(R.styleable.PaginationSeekBar_psb_indicatorNextPageText); mIndicatorFormatter = a.getString(R.styleable.PaginationSeekBar_psb_indicatorFormatter); ColorStateList trackColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_trackColor); ColorStateList progressColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_progressColor); ColorStateList rippleColor = a.getColorStateList(R.styleable.PaginationSeekBar_psb_rippleColor); int thumbTextColor = a.getColor(R.styleable.PaginationSeekBar_psb_thumbTextColor, Color.WHITE); boolean editMode = isInEditMode(); if (editMode && rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY }); } if (editMode && trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY }); } if (editMode && progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { 0xff009688 }); } if (editMode && thumbTextColor == 0) { thumbTextColor = Color.WHITE; } mRipple = SeekBarCompat.getRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.setBackground(this, mRipple); } else { mRipple.setCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.setCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.setCallback(this); ThumbDrawable thumbDrawable = new ThumbDrawable(progressColor, thumbTextColor, thumbSize, mValue); mThumb = thumbDrawable; mThumb.setCallback(this); mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight()); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyle, convertValueToMessage(mMax), mPrevPageText, mNextPageText); mIndicator.setListener(mFloaterListener); } a.recycle(); setNumericTransformer(new DefaultNumericTransformer()); initPagecountPerOneboard(pageCountPerOneBoard); }
From source file:android.content.pm.PackageParser.java
private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data, String[] outError) throws XmlPullParserException, IOException { TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData); if (data == null) { data = new Bundle(); }//from w ww.j a va2 s. com String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); if (name == null) { outError[0] = "<meta-data> requires an android:name attribute"; sa.recycle(); return null; } name = name.intern(); TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource); if (v != null && v.resourceId != 0) { //Slog.i(TAG, "Meta data ref " + name + ": " + v); data.putInt(name, v.resourceId); } else { v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value); //Slog.i(TAG, "Meta data " + name + ": " + v); if (v != null) { if (v.type == TypedValue.TYPE_STRING) { CharSequence cs = v.coerceToString(); data.putString(name, cs != null ? cs.toString().intern() : null); } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { data.putBoolean(name, v.data != 0); } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) { data.putInt(name, v.data); } else if (v.type == TypedValue.TYPE_FLOAT) { data.putFloat(name, v.getFloat()); } else { if (!RIGID_PARSER) { Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription()); } else { outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; data = null; } } } else { outError[0] = "<meta-data> requires an android:value or android:resource attribute"; data = null; } } sa.recycle(); XmlUtils.skipCurrentTag(parser); return data; }
From source file:android.content.pm.PackageParser.java
private Activity parseActivityAlias(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.AndroidManifestActivityAlias); String targetActivity = sa.getNonConfigurationString( com.android.internal.R.styleable.AndroidManifestActivityAlias_targetActivity, Configuration.NATIVE_CONFIG_VERSION); if (targetActivity == null) { outError[0] = "<activity-alias> does not specify android:targetActivity"; sa.recycle(); return null; }//from w w w. ja va 2 s .c o m targetActivity = buildClassName(owner.applicationInfo.packageName, targetActivity, outError); if (targetActivity == null) { sa.recycle(); return null; } if (mParseActivityAliasArgs == null) { mParseActivityAliasArgs = new ParseComponentArgs(owner, outError, com.android.internal.R.styleable.AndroidManifestActivityAlias_name, com.android.internal.R.styleable.AndroidManifestActivityAlias_label, com.android.internal.R.styleable.AndroidManifestActivityAlias_icon, com.android.internal.R.styleable.AndroidManifestActivityAlias_logo, com.android.internal.R.styleable.AndroidManifestActivityAlias_banner, mSeparateProcesses, 0, com.android.internal.R.styleable.AndroidManifestActivityAlias_description, com.android.internal.R.styleable.AndroidManifestActivityAlias_enabled); mParseActivityAliasArgs.tag = "<activity-alias>"; } mParseActivityAliasArgs.sa = sa; mParseActivityAliasArgs.flags = flags; Activity target = null; final int NA = owner.activities.size(); for (int i = 0; i < NA; i++) { Activity t = owner.activities.get(i); if (targetActivity.equals(t.info.name)) { target = t; break; } } if (target == null) { outError[0] = "<activity-alias> target activity " + targetActivity + " not found in manifest"; sa.recycle(); return null; } ActivityInfo info = new ActivityInfo(); info.targetActivity = targetActivity; info.configChanges = target.info.configChanges; info.flags = target.info.flags; info.icon = target.info.icon; info.logo = target.info.logo; info.banner = target.info.banner; info.labelRes = target.info.labelRes; info.nonLocalizedLabel = target.info.nonLocalizedLabel; info.launchMode = target.info.launchMode; info.lockTaskLaunchMode = target.info.lockTaskLaunchMode; info.processName = target.info.processName; if (info.descriptionRes == 0) { info.descriptionRes = target.info.descriptionRes; } info.screenOrientation = target.info.screenOrientation; info.taskAffinity = target.info.taskAffinity; info.theme = target.info.theme; info.softInputMode = target.info.softInputMode; info.uiOptions = target.info.uiOptions; info.parentActivityName = target.info.parentActivityName; info.maxRecents = target.info.maxRecents; Activity a = new Activity(mParseActivityAliasArgs, info); if (outError[0] != null) { sa.recycle(); return null; } final boolean setExported = sa .hasValue(com.android.internal.R.styleable.AndroidManifestActivityAlias_exported); if (setExported) { a.info.exported = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestActivityAlias_exported, false); } String str; str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestActivityAlias_permission, 0); if (str != null) { a.info.permission = str.length() > 0 ? str.toString().intern() : null; } String parentName = sa.getNonConfigurationString( com.android.internal.R.styleable.AndroidManifestActivityAlias_parentActivityName, Configuration.NATIVE_CONFIG_VERSION); if (parentName != null) { String parentClassName = buildClassName(a.info.packageName, parentName, outError); if (outError[0] == null) { a.info.parentActivityName = parentClassName; } else { Log.e(TAG, "Activity alias " + a.info.name + " specified invalid parentActivityName " + parentName); outError[0] = null; } } sa.recycle(); if (outError[0] != null) { 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")) { ActivityIntentInfo intent = new ActivityIntentInfo(a); if (!parseIntent(res, parser, attrs, true, true, intent, outError)) { return null; } if (intent.countActions() == 0) { Slog.w(TAG, "No actions in intent filter at " + mArchiveSourcePath + " " + parser.getPositionDescription()); } else { a.intents.add(intent); } } else if (parser.getName().equals("meta-data")) { if ((a.metaData = parseMetaData(res, parser, attrs, a.metaData, outError)) == null) { return null; } } else { if (!RIGID_PARSER) { Slog.w(TAG, "Unknown element under <activity-alias>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; } else { outError[0] = "Bad element under <activity-alias>: " + parser.getName(); return null; } } } if (!setExported) { a.info.exported = a.intents.size() > 0; } return a; }
From source file:android.content.pm.PackageParser.java
private boolean parseKeySets(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException { // we've encountered the 'key-sets' tag // all the keys and keysets that we want must be defined here // so we're going to iterate over the parser and pull out the things we want int outerDepth = parser.getDepth(); int currentKeySetDepth = -1; int type;// ww w . j av a 2s .c o m String currentKeySet = null; ArrayMap<String, PublicKey> publicKeys = new ArrayMap<String, PublicKey>(); ArraySet<String> upgradeKeySets = new ArraySet<String>(); ArrayMap<String, ArraySet<String>> definedKeySets = new ArrayMap<String, ArraySet<String>>(); ArraySet<String> improperKeySets = new ArraySet<String>(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { if (type == XmlPullParser.END_TAG) { if (parser.getDepth() == currentKeySetDepth) { currentKeySet = null; currentKeySetDepth = -1; } continue; } String tagName = parser.getName(); if (tagName.equals("key-set")) { if (currentKeySet != null) { outError[0] = "Improperly nested 'key-set' tag at " + parser.getPositionDescription(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return false; } final TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestKeySet); final String keysetName = sa .getNonResourceString(com.android.internal.R.styleable.AndroidManifestKeySet_name); definedKeySets.put(keysetName, new ArraySet<String>()); currentKeySet = keysetName; currentKeySetDepth = parser.getDepth(); sa.recycle(); } else if (tagName.equals("public-key")) { if (currentKeySet == null) { outError[0] = "Improperly nested 'key-set' tag at " + parser.getPositionDescription(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return false; } final TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPublicKey); final String publicKeyName = sa .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPublicKey_name); final String encodedKey = sa .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPublicKey_value); if (encodedKey == null && publicKeys.get(publicKeyName) == null) { outError[0] = "'public-key' " + publicKeyName + " must define a public-key value" + " on first use at " + parser.getPositionDescription(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; sa.recycle(); return false; } else if (encodedKey != null) { PublicKey currentKey = parsePublicKey(encodedKey); if (currentKey == null) { Slog.w(TAG, "No recognized valid key in 'public-key' tag at " + parser.getPositionDescription() + " key-set " + currentKeySet + " will not be added to the package's defined key-sets."); sa.recycle(); improperKeySets.add(currentKeySet); XmlUtils.skipCurrentTag(parser); continue; } if (publicKeys.get(publicKeyName) == null || publicKeys.get(publicKeyName).equals(currentKey)) { /* public-key first definition, or matches old definition */ publicKeys.put(publicKeyName, currentKey); } else { outError[0] = "Value of 'public-key' " + publicKeyName + " conflicts with previously defined value at " + parser.getPositionDescription(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; sa.recycle(); return false; } } definedKeySets.get(currentKeySet).add(publicKeyName); sa.recycle(); XmlUtils.skipCurrentTag(parser); } else if (tagName.equals("upgrade-key-set")) { final TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUpgradeKeySet); String name = sa .getNonResourceString(com.android.internal.R.styleable.AndroidManifestUpgradeKeySet_name); upgradeKeySets.add(name); sa.recycle(); XmlUtils.skipCurrentTag(parser); } else if (RIGID_PARSER) { outError[0] = "Bad element under <key-sets>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return false; } else { Slog.w(TAG, "Unknown element under <key-sets>: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription()); XmlUtils.skipCurrentTag(parser); continue; } } Set<String> publicKeyNames = publicKeys.keySet(); if (publicKeyNames.removeAll(definedKeySets.keySet())) { outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' and 'public-key' names must be distinct."; mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return false; } owner.mKeySetMapping = new ArrayMap<String, ArraySet<PublicKey>>(); for (ArrayMap.Entry<String, ArraySet<String>> e : definedKeySets.entrySet()) { final String keySetName = e.getKey(); if (e.getValue().size() == 0) { Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' " + keySetName + " has no valid associated 'public-key'." + " Not including in package's defined key-sets."); continue; } else if (improperKeySets.contains(keySetName)) { Slog.w(TAG, "Package" + owner.packageName + " AndroidManifext.xml " + "'key-set' " + keySetName + " contained improper 'public-key'" + " tags. Not including in package's defined key-sets."); continue; } owner.mKeySetMapping.put(keySetName, new ArraySet<PublicKey>()); for (String s : e.getValue()) { owner.mKeySetMapping.get(keySetName).add(publicKeys.get(s)); } } if (owner.mKeySetMapping.keySet().containsAll(upgradeKeySets)) { owner.mUpgradeKeySets = upgradeKeySets; } else { outError[0] = "Package" + owner.packageName + " AndroidManifext.xml " + "does not define all 'upgrade-key-set's ."; mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return false; } return true; }
From source file:android.content.pm.PackageParser.java
private Permission parsePermission(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException { Permission perm = new Permission(owner); TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermission); if (!parsePackageItemInfo(owner, perm.info, outError, "<permission>", sa, com.android.internal.R.styleable.AndroidManifestPermission_name, com.android.internal.R.styleable.AndroidManifestPermission_label, com.android.internal.R.styleable.AndroidManifestPermission_icon, com.android.internal.R.styleable.AndroidManifestPermission_logo, com.android.internal.R.styleable.AndroidManifestPermission_banner)) { sa.recycle(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; }//ww w. j a va2 s . com // Note: don't allow this value to be a reference to a resource // that may change. perm.info.group = sa .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup); if (perm.info.group != null) { perm.info.group = perm.info.group.intern(); } perm.info.descriptionRes = sa .getResourceId(com.android.internal.R.styleable.AndroidManifestPermission_description, 0); perm.info.protectionLevel = sa.getInt( com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel, PermissionInfo.PROTECTION_NORMAL); perm.info.flags = sa.getInt(com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0); sa.recycle(); if (perm.info.protectionLevel == -1) { outError[0] = "<permission> does not specify protectionLevel"; mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel); if ((perm.info.protectionLevel & PermissionInfo.PROTECTION_MASK_FLAGS) != 0) { if ((perm.info.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE) != PermissionInfo.PROTECTION_SIGNATURE) { outError[0] = "<permission> protectionLevel specifies a flag but is " + "not based on signature type"; mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } } if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, outError)) { mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } owner.permissions.add(perm); return perm; }
From source file:android.content.pm.PackageParser.java
private Permission parsePermissionTree(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException { Permission perm = new Permission(owner); TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermissionTree); if (!parsePackageItemInfo(owner, perm.info, outError, "<permission-tree>", sa, com.android.internal.R.styleable.AndroidManifestPermissionTree_name, com.android.internal.R.styleable.AndroidManifestPermissionTree_label, com.android.internal.R.styleable.AndroidManifestPermissionTree_icon, com.android.internal.R.styleable.AndroidManifestPermissionTree_logo, com.android.internal.R.styleable.AndroidManifestPermissionTree_banner)) { sa.recycle(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; }/* w w w. j a va 2 s . c o m*/ sa.recycle(); int index = perm.info.name.indexOf('.'); if (index > 0) { index = perm.info.name.indexOf('.', index + 1); } if (index < 0) { outError[0] = "<permission-tree> name has less than three segments: " + perm.info.name; mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } perm.info.descriptionRes = 0; perm.info.protectionLevel = PermissionInfo.PROTECTION_NORMAL; perm.tree = true; if (!parseAllMetaData(res, parser, attrs, "<permission-tree>", perm, outError)) { mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } owner.permissions.add(perm); return perm; }
From source file:android.content.pm.PackageParser.java
private PermissionGroup parsePermissionGroup(Package owner, int flags, Resources res, XmlPullParser parser, AttributeSet attrs, String[] outError) throws XmlPullParserException, IOException { PermissionGroup perm = new PermissionGroup(owner); TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermissionGroup); if (!parsePackageItemInfo(owner, perm.info, outError, "<permission-group>", sa, com.android.internal.R.styleable.AndroidManifestPermissionGroup_name, com.android.internal.R.styleable.AndroidManifestPermissionGroup_label, com.android.internal.R.styleable.AndroidManifestPermissionGroup_icon, com.android.internal.R.styleable.AndroidManifestPermissionGroup_logo, com.android.internal.R.styleable.AndroidManifestPermissionGroup_banner)) { sa.recycle(); mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; }/*from w w w . j a v a 2 s . c om*/ perm.info.descriptionRes = sa .getResourceId(com.android.internal.R.styleable.AndroidManifestPermissionGroup_description, 0); perm.info.flags = sa .getInt(com.android.internal.R.styleable.AndroidManifestPermissionGroup_permissionGroupFlags, 0); perm.info.priority = sa.getInt(com.android.internal.R.styleable.AndroidManifestPermissionGroup_priority, 0); if (perm.info.priority > 0 && (flags & PARSE_IS_SYSTEM) == 0) { perm.info.priority = 0; } sa.recycle(); if (!parseAllMetaData(res, parser, attrs, "<permission-group>", perm, outError)) { mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED; return null; } owner.permissionGroups.add(perm); return perm; }