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
17package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
23 * A single feature that can be requested by an application. This corresponds
24 * to information collected from the
25 * AndroidManifest.xml's {@code <uses-feature>} tag.
26 */
27public class FeatureInfo implements Parcelable {
28    /**
29     * The name of this feature, for example "android.hardware.camera".  If
30     * this is null, then this is an OpenGL ES version feature as described
31     * in {@link #reqGlEsVersion}.
32     */
33    public String name;
34
35    /**
36     * Default value for {@link #reqGlEsVersion};
37     */
38    public static final int GL_ES_VERSION_UNDEFINED = 0;
39
40    /**
41     * The GLES version used by an application. The upper order 16 bits represent the
42     * major version and the lower order 16 bits the minor version.  Only valid
43     * if {@link #name} is null.
44     */
45    public int reqGlEsVersion;
46
47    /**
48     * Set on {@link #flags} if this feature has been required by the application.
49     */
50    public static final int FLAG_REQUIRED = 0x0001;
51
52    /**
53     * Additional flags.  May be zero or more of {@link #FLAG_REQUIRED}.
54     */
55    public int flags;
56
57    public FeatureInfo() {
58    }
59
60    public FeatureInfo(FeatureInfo orig) {
61        name = orig.name;
62        reqGlEsVersion = orig.reqGlEsVersion;
63        flags = orig.flags;
64    }
65
66    public String toString() {
67        if (name != null) {
68            return "FeatureInfo{"
69                    + Integer.toHexString(System.identityHashCode(this))
70                    + " " + name + " fl=0x" + Integer.toHexString(flags) + "}";
71        } else {
72            return "FeatureInfo{"
73                    + Integer.toHexString(System.identityHashCode(this))
74                    + " glEsVers=" + getGlEsVersion()
75                    + " fl=0x" + Integer.toHexString(flags) + "}";
76        }
77    }
78
79    public int describeContents() {
80        return 0;
81    }
82
83    public void writeToParcel(Parcel dest, int parcelableFlags) {
84        dest.writeString(name);
85        dest.writeInt(reqGlEsVersion);
86        dest.writeInt(flags);
87    }
88
89    public static final Creator<FeatureInfo> CREATOR =
90        new Creator<FeatureInfo>() {
91        public FeatureInfo createFromParcel(Parcel source) {
92            return new FeatureInfo(source);
93        }
94        public FeatureInfo[] newArray(int size) {
95            return new FeatureInfo[size];
96        }
97    };
98
99    private FeatureInfo(Parcel source) {
100        name = source.readString();
101        reqGlEsVersion = source.readInt();
102        flags = source.readInt();
103    }
104
105    /**
106     * This method extracts the major and minor version of reqGLEsVersion attribute
107     * and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned
108     * as 1.2
109     * @return String representation of the reqGlEsVersion attribute
110     */
111    public String getGlEsVersion() {
112        int major = ((reqGlEsVersion & 0xffff0000) >> 16);
113        int minor = reqGlEsVersion & 0x0000ffff;
114        return String.valueOf(major)+"."+String.valueOf(minor);
115    }
116}
117