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 17 package android.content.pm; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Definition of a single optional hardware or software feature of an Android 24 * device. 25 * <p> 26 * This object is used to represent both features supported by a device and 27 * features requested by an app. Apps can request that certain features be 28 * available as a prerequisite to being installed through the 29 * {@code uses-feature} tag in their manifests. 30 * <p> 31 * Starting in {@link android.os.Build.VERSION_CODES#N}, features can have a 32 * version, which must always be backwards compatible. That is, a device 33 * claiming to support version 3 of a specific feature must support apps 34 * requesting version 1 of that feature. 35 */ 36 public class FeatureInfo implements Parcelable { 37 /** 38 * The name of this feature, for example "android.hardware.camera". If 39 * this is null, then this is an OpenGL ES version feature as described 40 * in {@link #reqGlEsVersion}. 41 */ 42 public String name; 43 44 /** 45 * If this object represents a feature supported by a device, this is the 46 * maximum version of this feature supported by the device. The device 47 * implicitly supports all older versions of this feature. 48 * <p> 49 * If this object represents a feature requested by an app, this is the 50 * minimum version of the feature required by the app. 51 * <p> 52 * When a feature version is undefined by a device, it's assumed to be 53 * version 0. 54 */ 55 public int version; 56 57 /** 58 * Default value for {@link #reqGlEsVersion}; 59 */ 60 public static final int GL_ES_VERSION_UNDEFINED = 0; 61 62 /** 63 * The GLES version used by an application. The upper order 16 bits represent the 64 * major version and the lower order 16 bits the minor version. Only valid 65 * if {@link #name} is null. 66 */ 67 public int reqGlEsVersion; 68 69 /** 70 * Set on {@link #flags} if this feature has been required by the application. 71 */ 72 public static final int FLAG_REQUIRED = 0x0001; 73 74 /** 75 * Additional flags. May be zero or more of {@link #FLAG_REQUIRED}. 76 */ 77 public int flags; 78 FeatureInfo()79 public FeatureInfo() { 80 } 81 FeatureInfo(FeatureInfo orig)82 public FeatureInfo(FeatureInfo orig) { 83 name = orig.name; 84 version = orig.version; 85 reqGlEsVersion = orig.reqGlEsVersion; 86 flags = orig.flags; 87 } 88 89 @Override toString()90 public String toString() { 91 if (name != null) { 92 return "FeatureInfo{" 93 + Integer.toHexString(System.identityHashCode(this)) 94 + " " + name + " v=" + version + " fl=0x" + Integer.toHexString(flags) + "}"; 95 } else { 96 return "FeatureInfo{" 97 + Integer.toHexString(System.identityHashCode(this)) 98 + " glEsVers=" + getGlEsVersion() 99 + " fl=0x" + Integer.toHexString(flags) + "}"; 100 } 101 } 102 103 @Override describeContents()104 public int describeContents() { 105 return 0; 106 } 107 108 @Override writeToParcel(Parcel dest, int parcelableFlags)109 public void writeToParcel(Parcel dest, int parcelableFlags) { 110 dest.writeString(name); 111 dest.writeInt(version); 112 dest.writeInt(reqGlEsVersion); 113 dest.writeInt(flags); 114 } 115 116 public static final Creator<FeatureInfo> CREATOR = new Creator<FeatureInfo>() { 117 @Override 118 public FeatureInfo createFromParcel(Parcel source) { 119 return new FeatureInfo(source); 120 } 121 @Override 122 public FeatureInfo[] newArray(int size) { 123 return new FeatureInfo[size]; 124 } 125 }; 126 FeatureInfo(Parcel source)127 private FeatureInfo(Parcel source) { 128 name = source.readString(); 129 version = source.readInt(); 130 reqGlEsVersion = source.readInt(); 131 flags = source.readInt(); 132 } 133 134 /** 135 * This method extracts the major and minor version of reqGLEsVersion attribute 136 * and returns it as a string. Say reqGlEsVersion value of 0x00010002 is returned 137 * as 1.2 138 * @return String representation of the reqGlEsVersion attribute 139 */ getGlEsVersion()140 public String getGlEsVersion() { 141 int major = ((reqGlEsVersion & 0xffff0000) >> 16); 142 int minor = reqGlEsVersion & 0x0000ffff; 143 return String.valueOf(major)+"."+String.valueOf(minor); 144 } 145 } 146