Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 17 | package android.content.pm; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | import android.os.Parcelable.Creator; |
| 22 | |
| 23 | /** |
| 24 | * A single feature that can be requested by an application. This corresponds |
| 25 | * to information collected from the |
| 26 | * AndroidManifest.xml's <uses-feature> tag. |
| 27 | */ |
| 28 | public class FeatureInfo implements Parcelable { |
| 29 | /** |
| 30 | * The name of this feature, for example "android.hardware.camera". If |
| 31 | * this is null, then this is an OpenGL ES version feature as described |
| 32 | * in {@link #reqGlEsVersion}. |
| 33 | */ |
| 34 | public String name; |
| 35 | |
| 36 | /** |
| 37 | * Default value for {@link #reqGlEsVersion}; |
| 38 | */ |
| 39 | public static final int GL_ES_VERSION_UNDEFINED = 0; |
| 40 | |
| 41 | /** |
| 42 | * The GLES version used by an application. The upper order 16 bits represent the |
| 43 | * major version and the lower order 16 bits the minor version. Only valid |
| 44 | * if {@link #name} is null. |
| 45 | */ |
| 46 | public int reqGlEsVersion; |
| 47 | |
| 48 | /** |
| 49 | * Set on {@link #flags} if this feature has been required by the application. |
| 50 | */ |
| 51 | public static final int FLAG_REQUIRED = 0x0001; |
| 52 | |
| 53 | /** |
| 54 | * Additional flags. May be zero or more of {@link #FLAG_REQUIRED}. |
| 55 | */ |
| 56 | public int flags; |
| 57 | |
| 58 | public FeatureInfo() { |
| 59 | } |
| 60 | |
| 61 | public FeatureInfo(FeatureInfo orig) { |
| 62 | name = orig.name; |
| 63 | reqGlEsVersion = orig.reqGlEsVersion; |
| 64 | flags = orig.flags; |
| 65 | } |
| 66 | |
| 67 | public String toString() { |
| 68 | if (name != null) { |
| 69 | return "FeatureInfo{" |
| 70 | + Integer.toHexString(System.identityHashCode(this)) |
| 71 | + " " + name + " fl=0x" + Integer.toHexString(flags) + "}"; |
| 72 | } else { |
| 73 | return "FeatureInfo{" |
| 74 | + Integer.toHexString(System.identityHashCode(this)) |
| 75 | + " glEsVers=" + getGlEsVersion() |
| 76 | + " fl=0x" + Integer.toHexString(flags) + "}"; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | public int describeContents() { |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 85 | dest.writeString(name); |
| 86 | dest.writeInt(reqGlEsVersion); |
| 87 | dest.writeInt(flags); |
| 88 | } |
| 89 | |
| 90 | public static final Creator<FeatureInfo> CREATOR = |
| 91 | new Creator<FeatureInfo>() { |
| 92 | public FeatureInfo createFromParcel(Parcel source) { |
| 93 | return new FeatureInfo(source); |
| 94 | } |
| 95 | public FeatureInfo[] newArray(int size) { |
| 96 | return new FeatureInfo[size]; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | private FeatureInfo(Parcel source) { |
| 101 | name = source.readString(); |
| 102 | reqGlEsVersion = source.readInt(); |
| 103 | flags = source.readInt(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * This method extracts the major and minor version of reqGLEsVersion attribute |
| 108 | * and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned |
| 109 | * as 1.2 |
| 110 | * @return String representation of the reqGlEsVersion attribute |
| 111 | */ |
| 112 | public String getGlEsVersion() { |
| 113 | int major = ((reqGlEsVersion & 0xffff0000) >> 16); |
| 114 | int minor = reqGlEsVersion & 0x0000ffff; |
| 115 | return String.valueOf(major)+"."+String.valueOf(minor); |
| 116 | } |
| 117 | } |