Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 183c6fec authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "EditSchema: add mandatory check for "name" and "photo"." into ics-mr1

parents 97f4d04f c641e622
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -930,16 +930,16 @@ public abstract class BaseAccountType extends AccountType {
            final boolean displayOrderPrimary =
                    context.getResources().getBoolean(R.bool.config_editor_field_order_primary);

            final boolean supportsDisplayName = getAttr(attrs, "supportsDisplayName", true);
            final boolean supportsPrefix = getAttr(attrs, "supportsPrefix", true);
            final boolean supportsMiddleName = getAttr(attrs, "supportsMiddleName", true);
            final boolean supportsSuffix = getAttr(attrs, "supportsSuffix", true);
            final boolean supportsDisplayName = getAttr(attrs, "supportsDisplayName", false);
            final boolean supportsPrefix = getAttr(attrs, "supportsPrefix", false);
            final boolean supportsMiddleName = getAttr(attrs, "supportsMiddleName", false);
            final boolean supportsSuffix = getAttr(attrs, "supportsSuffix", false);
            final boolean supportsPhoneticFamilyName =
                    getAttr(attrs, "supportsPhoneticFamilyName", true);
                    getAttr(attrs, "supportsPhoneticFamilyName", false);
            final boolean supportsPhoneticMiddleName =
                    getAttr(attrs, "supportsPhoneticMiddleName", true);
                    getAttr(attrs, "supportsPhoneticMiddleName", false);
            final boolean supportsPhoneticGivenName =
                    getAttr(attrs, "supportsPhoneticGivenName", true);
                    getAttr(attrs, "supportsPhoneticGivenName", false);

            // For now, every things must be supported.
            checkAttributeTrue(supportsDisplayName, "supportsDisplayName");
+18 −2
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
@@ -117,12 +119,20 @@ public class ExternalAccountType extends BaseAccountType {
        } else {
            parser = injectedMetadata;
        }
        boolean needLineNumberInErrorLog = true;
        try {
            if (parser != null) {
                inflate(context, parser);
            }

            if (!mHasEditSchema) {
            // Done parsing; line number no longer needed in error log.
            needLineNumberInErrorLog = false;
            if (mHasEditSchema) {
                checkKindExists(StructuredName.CONTENT_ITEM_TYPE);
                checkKindExists(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME);
                checkKindExists(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME);
                checkKindExists(Photo.CONTENT_ITEM_TYPE);
            } else {
                // Bring in name and photo from fallback source, which are non-optional
                addDataKindStructuredName(context);
                addDataKindDisplayName(context);
@@ -131,7 +141,7 @@ public class ExternalAccountType extends BaseAccountType {
            }
        } catch (DefinitionException e) {
            String message = "Problem reading XML";
            if (parser != null) {
            if (needLineNumberInErrorLog && (parser != null)) {
                message = message + " in line " + parser.getLineNumber();
            }
            Log.e(TAG, message, e);
@@ -185,6 +195,12 @@ public class ExternalAccountType extends BaseAccountType {
        return null;
    }

    private void checkKindExists(String mimeType) throws DefinitionException {
        if (getKindForMimetype(mimeType) == null) {
            throw new DefinitionException(mimeType + " must be supported");
        }
    }

    @Override
    public boolean isEmbedded() {
        return false;
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
 * Copyright (c) 2011, 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.
 */
-->

<!-- XML for must-have checks.  Base definition, which is valid. -->

<ContactsAccountType
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <EditSchema>
        <DataKind kind="name"
            maxOccurs="1"
            supportsDisplayName="true"
            supportsPrefix="true"
            supportsMiddleName="true"
            supportsSuffix="true"
            supportsPhoneticFamilyName="true"
            supportsPhoneticMiddleName="true"
            supportsPhoneticGivenName="true"
            >
        </DataKind>
        <DataKind kind="photo" maxOccurs="1" />
    </EditSchema>
</ContactsAccountType>
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
 * Copyright (c) 2011, 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.
 */
-->

<!-- XML for must-have checks.  Missing "name" kind. -->

<ContactsAccountType
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <EditSchema>
        <DataKind kind="photo" maxOccurs="1" />
    </EditSchema>
</ContactsAccountType>
+37 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
 * Copyright (c) 2011, 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.
 */
-->

<!-- XML for must-have checks.  Missing one of the "support*" attributes". -->

<ContactsAccountType
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <EditSchema>
        <DataKind kind="name"
            maxOccurs="1"
            supportsPrefix="true"
            supportsMiddleName="true"
            supportsSuffix="true"
            supportsPhoneticFamilyName="true"
            supportsPhoneticMiddleName="true"
            supportsPhoneticGivenName="true"
            />
        <DataKind kind="photo" maxOccurs="1" />
    </EditSchema>
</ContactsAccountType>
Loading