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; |
Yi Jin | d6759d4 | 2017-10-12 15:08:49 -0700 | [diff] [blame] | 21 | import android.util.proto.ProtoOutputStream; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 24 | * 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 Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 36 | */ |
| 37 | public 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 Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 44 | |
| 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 Sharkey | e721615 | 2016-04-07 14:07:10 -0600 | [diff] [blame] | 52 | * <p> |
| 53 | * When a feature version is undefined by a device, it's assumed to be |
| 54 | * version 0. |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 55 | */ |
| 56 | public int version; |
| 57 | |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 58 | /** |
| 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 Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 85 | version = orig.version; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 86 | reqGlEsVersion = orig.reqGlEsVersion; |
| 87 | flags = orig.flags; |
| 88 | } |
| 89 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 90 | @Override |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 91 | public String toString() { |
| 92 | if (name != null) { |
| 93 | return "FeatureInfo{" |
| 94 | + Integer.toHexString(System.identityHashCode(this)) |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 95 | + " " + name + " v=" + version + " fl=0x" + Integer.toHexString(flags) + "}"; |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 96 | } else { |
| 97 | return "FeatureInfo{" |
| 98 | + Integer.toHexString(System.identityHashCode(this)) |
| 99 | + " glEsVers=" + getGlEsVersion() |
| 100 | + " fl=0x" + Integer.toHexString(flags) + "}"; |
| 101 | } |
| 102 | } |
| 103 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 104 | @Override |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 105 | public int describeContents() { |
| 106 | return 0; |
| 107 | } |
| 108 | |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 109 | @Override |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 110 | public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 111 | dest.writeString(name); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 112 | dest.writeInt(version); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 113 | dest.writeInt(reqGlEsVersion); |
| 114 | dest.writeInt(flags); |
| 115 | } |
| 116 | |
Yi Jin | d6759d4 | 2017-10-12 15:08:49 -0700 | [diff] [blame] | 117 | /** @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 Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 129 | public static final @android.annotation.NonNull Creator<FeatureInfo> CREATOR = new Creator<FeatureInfo>() { |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 130 | @Override |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 131 | public FeatureInfo createFromParcel(Parcel source) { |
| 132 | return new FeatureInfo(source); |
| 133 | } |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 134 | @Override |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 135 | public FeatureInfo[] newArray(int size) { |
| 136 | return new FeatureInfo[size]; |
| 137 | } |
| 138 | }; |
| 139 | |
| 140 | private FeatureInfo(Parcel source) { |
| 141 | name = source.readString(); |
Jeff Sharkey | 115d2c1 | 2016-02-15 17:25:57 -0700 | [diff] [blame] | 142 | version = source.readInt(); |
Dianne Hackborn | 4923734 | 2009-08-27 20:08:01 -0700 | [diff] [blame] | 143 | 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 | } |