blob: ff9fd8ec31c533feb9eace587b6c8ba711f44832 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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 Hackborn49237342009-08-27 20:08:01 -070017package android.content.pm;
18
19import android.os.Parcel;
20import android.os.Parcelable;
Yi Jind6759d42017-10-12 15:08:49 -070021import android.util.proto.ProtoOutputStream;
Dianne Hackborn49237342009-08-27 20:08:01 -070022
23/**
Jeff Sharkey115d2c12016-02-15 17:25:57 -070024 * Definition of a single optional hardware or software feature of an Android
25 * device.
26 * <p>
27 * This object is used to represent both features supported by a device and
28 * features requested by an app. Apps can request that certain features be
29 * available as a prerequisite to being installed through the
30 * {@code uses-feature} tag in their manifests.
31 * <p>
32 * Starting in {@link android.os.Build.VERSION_CODES#N}, features can have a
33 * version, which must always be backwards compatible. That is, a device
34 * claiming to support version 3 of a specific feature must support apps
35 * requesting version 1 of that feature.
Dianne Hackborn49237342009-08-27 20:08:01 -070036 */
37public class FeatureInfo implements Parcelable {
38 /**
39 * The name of this feature, for example "android.hardware.camera". If
40 * this is null, then this is an OpenGL ES version feature as described
41 * in {@link #reqGlEsVersion}.
42 */
43 public String name;
Jeff Sharkey115d2c12016-02-15 17:25:57 -070044
45 /**
46 * If this object represents a feature supported by a device, this is the
47 * maximum version of this feature supported by the device. The device
48 * implicitly supports all older versions of this feature.
49 * <p>
50 * If this object represents a feature requested by an app, this is the
51 * minimum version of the feature required by the app.
Jeff Sharkeye7216152016-04-07 14:07:10 -060052 * <p>
53 * When a feature version is undefined by a device, it's assumed to be
54 * version 0.
Jeff Sharkey115d2c12016-02-15 17:25:57 -070055 */
56 public int version;
57
Dianne Hackborn49237342009-08-27 20:08:01 -070058 /**
59 * Default value for {@link #reqGlEsVersion};
60 */
61 public static final int GL_ES_VERSION_UNDEFINED = 0;
62
63 /**
64 * The GLES version used by an application. The upper order 16 bits represent the
65 * major version and the lower order 16 bits the minor version. Only valid
66 * if {@link #name} is null.
67 */
68 public int reqGlEsVersion;
69
70 /**
71 * Set on {@link #flags} if this feature has been required by the application.
72 */
73 public static final int FLAG_REQUIRED = 0x0001;
74
75 /**
76 * Additional flags. May be zero or more of {@link #FLAG_REQUIRED}.
77 */
78 public int flags;
79
80 public FeatureInfo() {
81 }
82
83 public FeatureInfo(FeatureInfo orig) {
84 name = orig.name;
Jeff Sharkey115d2c12016-02-15 17:25:57 -070085 version = orig.version;
Dianne Hackborn49237342009-08-27 20:08:01 -070086 reqGlEsVersion = orig.reqGlEsVersion;
87 flags = orig.flags;
88 }
89
Jeff Sharkey115d2c12016-02-15 17:25:57 -070090 @Override
Dianne Hackborn49237342009-08-27 20:08:01 -070091 public String toString() {
92 if (name != null) {
93 return "FeatureInfo{"
94 + Integer.toHexString(System.identityHashCode(this))
Jeff Sharkey115d2c12016-02-15 17:25:57 -070095 + " " + name + " v=" + version + " fl=0x" + Integer.toHexString(flags) + "}";
Dianne Hackborn49237342009-08-27 20:08:01 -070096 } else {
97 return "FeatureInfo{"
98 + Integer.toHexString(System.identityHashCode(this))
99 + " glEsVers=" + getGlEsVersion()
100 + " fl=0x" + Integer.toHexString(flags) + "}";
101 }
102 }
103
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700104 @Override
Dianne Hackborn49237342009-08-27 20:08:01 -0700105 public int describeContents() {
106 return 0;
107 }
108
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700109 @Override
Dianne Hackborn49237342009-08-27 20:08:01 -0700110 public void writeToParcel(Parcel dest, int parcelableFlags) {
111 dest.writeString(name);
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700112 dest.writeInt(version);
Dianne Hackborn49237342009-08-27 20:08:01 -0700113 dest.writeInt(reqGlEsVersion);
114 dest.writeInt(flags);
115 }
116
Yi Jind6759d42017-10-12 15:08:49 -0700117 /** @hide */
118 public void writeToProto(ProtoOutputStream proto, long fieldId) {
119 long token = proto.start(fieldId);
120 if (name != null) {
121 proto.write(FeatureInfoProto.NAME, name);
122 }
123 proto.write(FeatureInfoProto.VERSION, version);
124 proto.write(FeatureInfoProto.GLES_VERSION, getGlEsVersion());
125 proto.write(FeatureInfoProto.FLAGS, flags);
126 proto.end(token);
127 }
128
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700129 public static final Creator<FeatureInfo> CREATOR = new Creator<FeatureInfo>() {
130 @Override
Dianne Hackborn49237342009-08-27 20:08:01 -0700131 public FeatureInfo createFromParcel(Parcel source) {
132 return new FeatureInfo(source);
133 }
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700134 @Override
Dianne Hackborn49237342009-08-27 20:08:01 -0700135 public FeatureInfo[] newArray(int size) {
136 return new FeatureInfo[size];
137 }
138 };
139
140 private FeatureInfo(Parcel source) {
141 name = source.readString();
Jeff Sharkey115d2c12016-02-15 17:25:57 -0700142 version = source.readInt();
Dianne Hackborn49237342009-08-27 20:08:01 -0700143 reqGlEsVersion = source.readInt();
144 flags = source.readInt();
145 }
146
147 /**
148 * This method extracts the major and minor version of reqGLEsVersion attribute
149 * and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned
150 * as 1.2
151 * @return String representation of the reqGlEsVersion attribute
152 */
153 public String getGlEsVersion() {
154 int major = ((reqGlEsVersion & 0xffff0000) >> 16);
155 int minor = reqGlEsVersion & 0x0000ffff;
156 return String.valueOf(major)+"."+String.valueOf(minor);
157 }
158}