1/*
2 * Copyright (C) 2008 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 * Information you can retrieve about hardware configuration preferences
24 * declared by an application. This corresponds to information collected from the
25 * AndroidManifest.xml's <uses-configuration> and <uses-feature> tags.
26 */
27public class ConfigurationInfo implements Parcelable {
28    /**
29     * The kind of touch screen attached to the device.
30     * One of: {@link android.content.res.Configuration#TOUCHSCREEN_NOTOUCH},
31     * {@link android.content.res.Configuration#TOUCHSCREEN_STYLUS},
32     * {@link android.content.res.Configuration#TOUCHSCREEN_FINGER}.
33     */
34    public int reqTouchScreen;
35
36    /**
37     * Application's input method preference.
38     * One of: {@link android.content.res.Configuration#KEYBOARD_UNDEFINED},
39     * {@link android.content.res.Configuration#KEYBOARD_NOKEYS},
40     * {@link android.content.res.Configuration#KEYBOARD_QWERTY},
41     * {@link android.content.res.Configuration#KEYBOARD_12KEY}
42     */
43    public int reqKeyboardType;
44
45    /**
46     * A flag indicating whether any keyboard is available.
47     * one of: {@link android.content.res.Configuration#NAVIGATION_UNDEFINED},
48     * {@link android.content.res.Configuration#NAVIGATION_DPAD},
49     * {@link android.content.res.Configuration#NAVIGATION_TRACKBALL},
50     * {@link android.content.res.Configuration#NAVIGATION_WHEEL}
51     */
52    public int reqNavigation;
53
54    /**
55     * Value for {@link #reqInputFeatures}: if set, indicates that the application
56     * requires a hard keyboard
57     */
58    public static final int INPUT_FEATURE_HARD_KEYBOARD = 0x00000001;
59
60    /**
61     * Value for {@link #reqInputFeatures}: if set, indicates that the application
62     * requires a five way navigation device
63     */
64    public static final int INPUT_FEATURE_FIVE_WAY_NAV = 0x00000002;
65
66    /**
67     * Flags associated with the input features.  Any combination of
68     * {@link #INPUT_FEATURE_HARD_KEYBOARD},
69     * {@link #INPUT_FEATURE_FIVE_WAY_NAV}
70     */
71    public int reqInputFeatures = 0;
72
73    /**
74     * Default value for {@link #reqGlEsVersion};
75     */
76    public static final int GL_ES_VERSION_UNDEFINED = 0;
77    /**
78     * The GLES version used by an application. The upper order 16 bits represent the
79     * major version and the lower order 16 bits the minor version.
80     */
81    public int reqGlEsVersion;
82
83    public ConfigurationInfo() {
84    }
85
86    public ConfigurationInfo(ConfigurationInfo orig) {
87        reqTouchScreen = orig.reqTouchScreen;
88        reqKeyboardType = orig.reqKeyboardType;
89        reqNavigation = orig.reqNavigation;
90        reqInputFeatures = orig.reqInputFeatures;
91        reqGlEsVersion = orig.reqGlEsVersion;
92    }
93
94    public String toString() {
95        return "ConfigurationInfo{"
96            + Integer.toHexString(System.identityHashCode(this))
97            + " touchscreen = " + reqTouchScreen
98            + " inputMethod = " + reqKeyboardType
99            + " navigation = " + reqNavigation
100            + " reqInputFeatures = " + reqInputFeatures
101            + " reqGlEsVersion = " + reqGlEsVersion + "}";
102    }
103
104    public int describeContents() {
105        return 0;
106    }
107
108    public void writeToParcel(Parcel dest, int parcelableFlags) {
109        dest.writeInt(reqTouchScreen);
110        dest.writeInt(reqKeyboardType);
111        dest.writeInt(reqNavigation);
112        dest.writeInt(reqInputFeatures);
113        dest.writeInt(reqGlEsVersion);
114    }
115
116    public static final Creator<ConfigurationInfo> CREATOR =
117        new Creator<ConfigurationInfo>() {
118        public ConfigurationInfo createFromParcel(Parcel source) {
119            return new ConfigurationInfo(source);
120        }
121        public ConfigurationInfo[] newArray(int size) {
122            return new ConfigurationInfo[size];
123        }
124    };
125
126    private ConfigurationInfo(Parcel source) {
127        reqTouchScreen = source.readInt();
128        reqKeyboardType = source.readInt();
129        reqNavigation = source.readInt();
130        reqInputFeatures = source.readInt();
131        reqGlEsVersion = 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     */
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