From fc58ae598819fac0fce2f47816dd2a92a4d5b4e0 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Tue, 18 May 2010 17:30:46 -0700 Subject: [PATCH] Add parsing of in the manifest. Change-Id: Id6f4b58c5a811b0b7e32b40162c8bd6680f2fc67 --- .../TextInputMethodQualifierTest.java | 2 +- .../src/com/android/sdklib/resources/Keyboard.java | 18 ++--- .../com/android/sdklib/xml/AndroidManifest.java | 10 ++- .../android/sdklib/xml/AndroidManifestParser.java | 41 ++++++++++-- .../src/com/android/sdklib/xml/ManifestData.java | 76 ++++++++++++++++++++++ .../sdklib/xml/AndroidManifestParserTest.java | 16 +++++ 6 files changed, 148 insertions(+), 15 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/TextInputMethodQualifierTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/TextInputMethodQualifierTest.java index 04eb8dad2..e51c12d1e 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/TextInputMethodQualifierTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/unittests/com/android/ide/eclipse/adt/internal/editors/resources/configurations/TextInputMethodQualifierTest.java @@ -51,7 +51,7 @@ public class TextInputMethodQualifierTest extends TestCase { public void test12Key() { assertEquals(true, timq.checkAndSet("12key", config)); //$NON-NLS-1$ assertTrue(config.getTextInputMethodQualifier() != null); - assertEquals(Keyboard.TWELVEKEYS, config.getTextInputMethodQualifier().getValue()); + assertEquals(Keyboard.TWELVEKEY, config.getTextInputMethodQualifier().getValue()); assertEquals("12key", config.getTextInputMethodQualifier().toString()); //$NON-NLS-1$ } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Keyboard.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Keyboard.java index 1b910d4d0..914b20510 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Keyboard.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/resources/Keyboard.java @@ -21,15 +21,16 @@ package com.android.sdklib.resources; *

This is used in the manifest in the uses-configuration node and in the resource folder names. */ public enum Keyboard { - NOKEY("nokeys", "No Keys"), //$NON-NLS-1$ - QWERTY("qwerty", "Qwerty"), //$NON-NLS-1$ - TWELVEKEYS("12key", "12 Key"); //$NON-NLS-1$ + NOKEY("nokeys", null, "No Keys"), //$NON-NLS-1$ + QWERTY("qwerty", null, "Qwerty"), //$NON-NLS-1$ + TWELVEKEY("12key", "twelvekey", "12 Key"); //$NON-NLS-1$ - private String mValue; + private String mValue, mValue2; private String mDisplayValue; - private Keyboard(String value, String displayValue) { + private Keyboard(String value, String value2, String displayValue) { mValue = value; + mValue2 = value2; mDisplayValue = displayValue; } @@ -39,9 +40,10 @@ public enum Keyboard { * @return the enum for the qualifier value or null if no matching was found. */ public static Keyboard getEnum(String value) { - for (Keyboard orient : values()) { - if (orient.mValue.equals(value)) { - return orient; + for (Keyboard kbrd : values()) { + if (kbrd.mValue.equals(value) || + (kbrd.mValue2 != null && kbrd.mValue2.equals(value))) { + return kbrd; } } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java index 47340eb1b..f137928fd 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java @@ -46,7 +46,8 @@ public final class AndroidManifest { public final static String NODE_USES_SDK = "uses-sdk"; public final static String NODE_INSTRUMENTATION = "instrumentation"; public final static String NODE_USES_LIBRARY = "uses-library"; - public static final String NODE_SUPPORTS_SCREENS = "supports-screens"; + public final static String NODE_SUPPORTS_SCREENS = "supports-screens"; + public final static String NODE_USES_CONFIGURATION = "uses-configuration"; public final static String ATTRIBUTE_PACKAGE = "package"; public final static String ATTRIBUTE_VERSIONCODE = "versionCode"; @@ -56,11 +57,16 @@ public final class AndroidManifest { public final static String ATTRIBUTE_MIN_SDK_VERSION = "minSdkVersion"; public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage"; public final static String ATTRIBUTE_EXPORTED = "exported"; - public final static String ATTRIBUTE_RESIZABLE = "resizeable"; + public final static String ATTRIBUTE_RESIZEABLE = "resizeable"; public final static String ATTRIBUTE_ANYDENSITY = "anyDensity"; public final static String ATTRIBUTE_SMALLSCREENS = "smallScreens"; public final static String ATTRIBUTE_NORMALSCREENS = "normalScreens"; public final static String ATTRIBUTE_LARGESCREENS = "largeScreens"; + public final static String ATTRIBUTE_REQ_5WAYNAV = "reqFiveWayNav"; + public final static String ATTRIBUTE_REQ_NAVIGATION = "reqNavigation"; + public final static String ATTRIBUTE_REQ_HARDKEYBOARD = "reqHardKeyboard"; + public final static String ATTRIBUTE_REQ_KEYBOARDTYPE = "reqKeyboardType"; + public final static String ATTRIBUTE_REQ_TOUCHSCREEN = "reqTouchScreen"; /** * Returns the package for a given project. diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java index cd7bca44c..e1c6aa4ef 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifestParser.java @@ -20,9 +20,13 @@ import com.android.sdklib.SdkConstants; import com.android.sdklib.io.IAbstractFile; import com.android.sdklib.io.IAbstractFolder; import com.android.sdklib.io.StreamException; +import com.android.sdklib.resources.Keyboard; +import com.android.sdklib.resources.Navigation; +import com.android.sdklib.resources.TouchScreen; import com.android.sdklib.xml.ManifestData.Activity; import com.android.sdklib.xml.ManifestData.Instrumentation; import com.android.sdklib.xml.ManifestData.SupportsScreens; +import com.android.sdklib.xml.ManifestData.UsesConfiguration; import org.xml.sax.Attributes; import org.xml.sax.ErrorHandler; @@ -76,8 +80,8 @@ public class AndroidManifestParser { /** * XML error & data handler used when parsing the AndroidManifest.xml file. *

- * This serves both as an {@link XmlErrorHandler} to report errors and as a data repository - * to collect data from the manifest. + * During parsing this will fill up the {@link ManifestData} object given to the constructor + * and call out errors to the given {@link ManifestErrorHandler}. */ private static class ManifestHandler extends DefaultHandler { @@ -90,7 +94,7 @@ public class AndroidManifestParser { private Locator mLocator; /** - * Creates a new {@link ManifestHandler}, which is also an {@link XmlErrorHandler}. + * Creates a new {@link ManifestHandler}. * * @param manifestFile The manifest file being parsed. Can be null. * @param errorListener An optional error listener. @@ -173,8 +177,13 @@ public class AndroidManifestParser { true /* hasNamespace */); } else if (AndroidManifest.NODE_INSTRUMENTATION.equals(localName)) { processInstrumentationNode(attributes); + } else if (AndroidManifest.NODE_SUPPORTS_SCREENS.equals(localName)) { processSupportsScreensNode(attributes); + + } else if (AndroidManifest.NODE_USES_CONFIGURATION.equals(localName)) { + processUsesConfiguration(attributes); + } break; case LEVEL_ACTIVITY: @@ -412,7 +421,7 @@ public class AndroidManifestParser { mManifestData.mSupportsScreens.mResizeable = Boolean.valueOf( getAttributeValue(attributes, - AndroidManifest.ATTRIBUTE_RESIZABLE, true /*hasNamespace*/)); + AndroidManifest.ATTRIBUTE_RESIZEABLE, true /*hasNamespace*/)); mManifestData.mSupportsScreens.mAnyDensity = Boolean.valueOf( getAttributeValue(attributes, AndroidManifest.ATTRIBUTE_ANYDENSITY, true /*hasNamespace*/)); @@ -428,6 +437,30 @@ public class AndroidManifestParser { } /** + * Processes the supports-screens node. + * @param attributes the attributes for the supports-screens node. + */ + private void processUsesConfiguration(Attributes attributes) { + mManifestData.mUsesConfiguration = new UsesConfiguration(); + + mManifestData.mUsesConfiguration.mReqFiveWayNav = Boolean.valueOf( + getAttributeValue(attributes, + AndroidManifest.ATTRIBUTE_REQ_5WAYNAV, true /*hasNamespace*/)); + mManifestData.mUsesConfiguration.mReqNavigation = Navigation.getEnum( + getAttributeValue(attributes, + AndroidManifest.ATTRIBUTE_REQ_NAVIGATION, true /*hasNamespace*/)); + mManifestData.mUsesConfiguration.mReqHardKeyboard = Boolean.valueOf( + getAttributeValue(attributes, + AndroidManifest.ATTRIBUTE_REQ_HARDKEYBOARD, true /*hasNamespace*/)); + mManifestData.mUsesConfiguration.mReqKeyboardType = Keyboard.getEnum( + getAttributeValue(attributes, + AndroidManifest.ATTRIBUTE_REQ_KEYBOARDTYPE, true /*hasNamespace*/)); + mManifestData.mUsesConfiguration.mReqTouchScreen = TouchScreen.getEnum( + getAttributeValue(attributes, + AndroidManifest.ATTRIBUTE_REQ_TOUCHSCREEN, true /*hasNamespace*/)); + } + + /** * Searches through the attributes list for a particular one and returns its value. * @param attributes the attribute list to search through * @param attributeName the name of the attribute to look for. diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java index 5101736ea..390a1ea63 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/ManifestData.java @@ -16,6 +16,10 @@ package com.android.sdklib.xml; +import com.android.sdklib.resources.Keyboard; +import com.android.sdklib.resources.Navigation; +import com.android.sdklib.resources.TouchScreen; + import java.util.ArrayList; import java.util.Set; import java.util.TreeSet; @@ -45,6 +49,7 @@ public final class ManifestData { final ArrayList mLibraries = new ArrayList(); SupportsScreens mSupportsScreens; + UsesConfiguration mUsesConfiguration; /** * Instrumentation info obtained from manifest @@ -127,6 +132,9 @@ public final class ManifestData { } } + /** + * Class representing the supports-screens node in the manifest. + */ public final static class SupportsScreens { Boolean mResizeable; Boolean mAnyDensity; @@ -134,30 +142,86 @@ public final class ManifestData { Boolean mLargeScreens; Boolean mNormalScreens; + /** + * returns the value of the resizeable attribute or null if not present. + */ public Boolean getResizeable() { return mResizeable; } + /** + * returns the value of the anyDensity attribute or null if not present. + */ public Boolean getAnyDensity() { return mAnyDensity; } + /** + * returns the value of the smallScreens attribute or null if not present. + */ public Boolean getSmallScreens() { return mSmallScreens; } + /** + * returns the value of the normalScreens attribute or null if not present. + */ public Boolean getNormalScreens() { return mNormalScreens; } + /** + * returns the value of the largeScreens attribute or null if not present. + */ public Boolean getLargeScreens() { return mLargeScreens; } } + /** + * Class representing the uses-configuration node in the manifest. + */ public final static class UsesConfiguration { Boolean mReqFiveWayNav; Boolean mReqHardKeyboard; + Keyboard mReqKeyboardType; + TouchScreen mReqTouchScreen; + Navigation mReqNavigation; + + /** + * returns the value of the reqFiveWayNav attribute or null if not present. + */ + public Boolean getReqFiveWayNav() { + return mReqFiveWayNav; + } + + /** + * returns the value of the reqNavigation attribute or null if not present. + */ + public Navigation getReqNavigation() { + return mReqNavigation; + } + + /** + * returns the value of the reqHardKeyboard attribute or null if not present. + */ + public Boolean getReqHardKeyboard() { + return mReqHardKeyboard; + } + + /** + * returns the value of the reqKeyboardType attribute or null if not present. + */ + public Keyboard getReqKeyboardType() { + return mReqKeyboardType; + } + + /** + * returns the value of the reqTouchScreen attribute or null if not present. + */ + public TouchScreen getReqTouchScreen() { + return mReqTouchScreen; + } } /** @@ -235,10 +299,22 @@ public final class ManifestData { return mLibraries.toArray(new String[mLibraries.size()]); } + /** + * Returns the {@link SupportsScreens} object representing the supports-screens + * node, or null if the node doesn't exist at all. + */ public SupportsScreens getSupportsScreens() { return mSupportsScreens; } + /** + * Returns the {@link UsesConfiguration} object representing the uses-configuration + * node, or null if the node doesn't exist at all. + */ + public UsesConfiguration getUsesConfiguration() { + return mUsesConfiguration; + } + void addProcessName(String processName) { if (mProcesses == null) { mProcesses = new TreeSet(); diff --git a/sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java b/sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java index 647aa74f8..8c69a9c1f 100644 --- a/sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java +++ b/sdkmanager/libs/sdklib/tests/com/android/sdklib/xml/AndroidManifestParserTest.java @@ -16,6 +16,10 @@ package com.android.sdklib.xml; +import com.android.sdklib.resources.Keyboard; +import com.android.sdklib.resources.Navigation; +import com.android.sdklib.resources.TouchScreen; + import java.io.InputStream; import junit.framework.TestCase; @@ -95,6 +99,7 @@ public class AndroidManifestParserTest extends TestCase { public void testSupportsScreen() { ManifestData.SupportsScreens supportsScreens = mManifestTestApp.getSupportsScreens(); + assertNotNull(supportsScreens); assertEquals(Boolean.TRUE, supportsScreens.getAnyDensity()); assertEquals(Boolean.TRUE, supportsScreens.getResizeable()); assertEquals(Boolean.TRUE, supportsScreens.getSmallScreens()); @@ -102,6 +107,17 @@ public class AndroidManifestParserTest extends TestCase { assertEquals(Boolean.TRUE, supportsScreens.getLargeScreens()); } + public void testUsesConfiguration() { + ManifestData.UsesConfiguration usesConfig = mManifestTestApp.getUsesConfiguration(); + + assertNotNull(usesConfig); + assertEquals(Boolean.TRUE, usesConfig.getReqFiveWayNav()); + assertEquals(Navigation.NONAV, usesConfig.getReqNavigation()); + assertEquals(Boolean.TRUE, usesConfig.getReqHardKeyboard()); + assertEquals(Keyboard.TWELVEKEY, usesConfig.getReqKeyboardType()); + assertEquals(TouchScreen.FINGER, usesConfig.getReqTouchScreen()); + } + private void assertEquals(ManifestData.Activity lhs, ManifestData.Activity rhs) { assertTrue(lhs == rhs || (lhs != null && rhs != null)); if (lhs != null && rhs != null) { -- 2.11.0