<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-->
<xsd:schema
    targetNamespace="http://schemas.android.com/sdk/android/sys-img/3"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:sdk="http://schemas.android.com/sdk/android/sys-img/3"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    version="1">

    <!-- The repository contains a collection of downloadable items known as
         "packages". Each package has a type and various attributes and contains
         a list of file "archives" that can be downloaded for specific OSes.

         An Android Addon repository is a web site that contains an "addon.xml"
         file that conforms to this XML Schema.

         History:
         - v1 is used by the SDK Updater in Tools r20.0. It is split out of the
           main SDK Repository XML Schema and can only contain <system-image> packages.

         - v2 is used by the SDK Manager in Tools r22.6.
           It introduces a sub-tag for the <system-image> repository type.

         - v3 is used by the SDK Manager in Tools r22.6.4:
            - It introduces a <list-display> string for all package types.
            - it changes <archive os=... arch=...> to sub-elements: <host-os>, <host-bits>,
              <jvm-bits> and <min-jvm-version>.
            - Support for new ABIs arm64-v8a, x86_64 and mips64.
            - Support for new <addon><vendor-id/name></addon> element.
    -->

    <xsd:element name="sdk-sys-img" type="sdk:repositoryType" />

    <xsd:complexType name="repositoryType">
        <xsd:annotation>
            <xsd:documentation>
                The repository contains a collection of downloadable system images.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="system-image"    type="sdk:systemImageType"  />
            <xsd:element name="license"         type="sdk:licenseType"      />
        </xsd:choice>
    </xsd:complexType>


    <!-- The definition of a system image used by a platform. -->

    <xsd:complexType name="systemImageType" >
        <xsd:annotation>
            <xsd:documentation>
                System Image for a platform.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:all>
            <!-- api-level+codename identifies the platform to which this system image belongs. -->

            <!-- The Android API Level for the platform. An int > 0. -->
            <xsd:element name="api-level" type="xsd:positiveInteger"  />
            <!-- The optional codename for this platform, if it's a preview. -->
            <xsd:element name="codename"  type="xsd:string" minOccurs="0" />

            <!-- The revision, an int > 0, incremented each time a new
                 package is generated. -->
            <xsd:element name="revision"  type="xsd:positiveInteger" />

            <!-- The tag of the system emulated by this image. -->
            <xsd:element name="tag-id"      type="sdk:idType" />
            <!-- The displayed tag of the system emulated by this image. Optional. -->
            <xsd:element name="tag-display" type="xsd:normalizedString" minOccurs="0" />

            <!-- Indicates a system-image is tied to an add-on and which one.
                 Mandatory for add-on system-images.
                 Must not be present for platform system-images. -->
            <xsd:element name="add-on"      type="sdk:addonType" minOccurs="0" />

            <!-- The vendor id of the system-image when it is associated with an add-on.
                 Must not be present for system-image associated with a platform. -->
            <xsd:element name="vendor-id"       type="sdk:idType" minOccurs="0" />
            <!-- The displayed vendor name of the system-image's add-on. -->
            <xsd:element name="vendor-display"  type="xsd:normalizedString" minOccurs="0" />

            <!-- The optional display list item. When missing, it is auto-computed. -->
            <xsd:element name="list-display"   type="xsd:normalizedString" minOccurs="0" />

            <!-- The ABI of the system emulated by this image. -->
            <xsd:element name="abi"       type="sdk:abiType" />

            <!-- The optional license of this package. If present, users will have
                 to agree to it before downloading. -->
            <xsd:element name="uses-license"  type="sdk:usesLicenseType" minOccurs="0" />
            <!-- The optional description of this package. -->
            <xsd:element name="description"   type="xsd:string"      minOccurs="0" />
            <!-- The optional description URL of this package -->
            <xsd:element name="desc-url"      type="xsd:token"       minOccurs="0" />
            <!-- The optional release note for this package. -->
            <xsd:element name="release-note"  type="xsd:string"      minOccurs="0" />
            <!-- The optional release note URL of this package -->
            <xsd:element name="release-url"   type="xsd:token"       minOccurs="0" />

            <!-- A list of file archives for this package. -->
            <xsd:element name="archives"  type="sdk:archivesType" />

            <!-- An optional element indicating the package is obsolete.
                 The string content is however currently not defined and ignored. -->
            <xsd:element name="obsolete"  type="xsd:string" minOccurs="0" />
        </xsd:all>
    </xsd:complexType>


    <!-- The definition of a system image used by a platform. -->

    <xsd:complexType name="addonType" >
        <xsd:annotation>
            <xsd:documentation>
                Indicates a system-image is tied to an add-on and which one
                (the combo tag-id + vendor-id uniquely identifies the add-on.)
                Mandatory for add-on system-images.
                Must not be present for platform system-images.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:all>
            <!-- The vendor id of the add-on. -->
            <xsd:element name="vendor-id"       type="sdk:idType" />
            <!-- The displayed vendor name of the add-on. -->
            <xsd:element name="vendor-display"  type="xsd:normalizedString" minOccurs="0" />
        </xsd:all>
    </xsd:complexType>


    <xsd:simpleType name="idType">
        <xsd:annotation>
            <xsd:documentation>
                An tag string for a system image can only be simple alphanumeric string.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:pattern value="[a-zA-Z0-9_-]+"/>
        </xsd:restriction>
    </xsd:simpleType>


    <!-- The definition of the ABI supported by a platform's system image. -->

    <xsd:simpleType name="abiType">
        <xsd:annotation>
            <xsd:documentation>The ABI of a platform's system image.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:enumeration value="armeabi"     />
            <xsd:enumeration value="armeabi-v7a" />
            <xsd:enumeration value="arm64-v8a"   />
            <xsd:enumeration value="x86"         />
            <xsd:enumeration value="x86_64"      />
            <xsd:enumeration value="mips"        />
            <xsd:enumeration value="mips64"      />
        </xsd:restriction>
    </xsd:simpleType>


    <!-- The definition of a license to be referenced by the uses-license element. -->

    <xsd:complexType name="licenseType">
        <xsd:annotation>
            <xsd:documentation>
                A license definition. Such a license must be used later as a reference
                using a uses-license element in one of the package elements.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="id"   type="xsd:ID" />
                <xsd:attribute name="type" type="xsd:token" fixed="text" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>


    <!-- Type describing the license used by a package.
         The license MUST be defined using a license node and referenced
         using the ref attribute of the license element inside a package.
     -->

    <xsd:complexType name="usesLicenseType">
        <xsd:annotation>
            <xsd:documentation>
                Describes the license used by a package. The license MUST be defined
                using a license node and referenced using the ref attribute of the
                license element inside a package.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="ref" type="xsd:IDREF" />
    </xsd:complexType>


    <!-- A collection of files that can be downloaded for a given architecture.
         The <archives> node is mandatory in the repository elements and the
         collection must have at least one <archive> declared.
         Each archive is a zip file that will be unzipped in a location that depends
         on its package type.
     -->

    <xsd:complexType name="archivesType">
        <xsd:annotation>
            <xsd:documentation>
                A collection of files that can be downloaded for a given architecture.
                The &lt;archives&gt; node is mandatory in the repository packages and the
                collection must have at least one &lt;archive&gt; declared.
                Each archive is a zip file that will be unzipped in a location that depends
                on its package type.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence minOccurs="1" maxOccurs="unbounded">
            <!-- One archive file -->
            <xsd:element name="archive">
                <xsd:complexType>
                    <!-- Properties of the archive file -->
                    <xsd:all>
                        <!-- The size in bytes of the archive to download. -->
                        <xsd:element name="size"     type="xsd:positiveInteger" />
                        <!-- The checksum of the archive file. -->
                        <xsd:element name="checksum" type="sdk:checksumType" />
                        <!-- The URL is an absolute URL if it starts with http://, https://
                             or ftp://. Otherwise it is relative to the parent directory that
                             contains this repository.xml -->
                        <xsd:element name="url"      type="xsd:token" />

                        <xsd:element name="host-os"         type="sdk:osType"         minOccurs="0" />
                        <xsd:element name="host-bits"       type="sdk:bitSizeType"    minOccurs="0" />
                        <xsd:element name="jvm-bits"        type="sdk:bitSizeType"    minOccurs="0" />
                        <xsd:element name="min-jvm-version" type="sdk:jvmVersionType" minOccurs="0" />
                    </xsd:all>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>


    <!-- The definition of archive filters -->

    <xsd:simpleType name="bitSizeType">
        <xsd:annotation>
            <xsd:documentation>A CPU bit size filter.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:enumeration value="32" />
            <xsd:enumeration value="64" />
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="osType">
        <xsd:annotation>
            <xsd:documentation>A host OS filter.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:enumeration value="linux" />
            <xsd:enumeration value="macosx" />
            <xsd:enumeration value="windows" />
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="jvmVersionType">
        <xsd:annotation>
            <xsd:documentation>A JVM version number, e.g. "1" or "1.6" or "1.14.15".</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="([1-9](\.[1-9]{1,2}){0,2})"/>
        </xsd:restriction>
    </xsd:simpleType>


    <!-- The definition of a file checksum -->

    <xsd:simpleType name="sha1Number">
        <xsd:annotation>
            <xsd:documentation>A SHA1 checksum.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="([0-9a-fA-F]){40}"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="checksumType">
        <xsd:annotation>
            <xsd:documentation>A file checksum, currently only SHA1.</xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="sdk:sha1Number">
                <xsd:attribute name="type" type="xsd:token" fixed="sha1" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

</xsd:schema>