SyncAdaptersCache.java revision 4a6679b97e0285c5b65ec5c0d9080ff90d3e9e81
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 17package android.content; 18 19import android.content.pm.RegisteredServicesCache; 20import android.content.res.TypedArray; 21import android.content.Context; 22import android.util.AttributeSet; 23 24/** 25 * A cache of services that export the {@link android.content.ISyncAdapter} interface. 26 * @hide 27 */ 28/* package private */ class SyncAdaptersCache extends RegisteredServicesCache<SyncAdapterType> { 29 private static final String TAG = "Account"; 30 31 private static final String SERVICE_INTERFACE = "android.content.SyncAdapter"; 32 private static final String SERVICE_META_DATA = "android.content.SyncAdapter"; 33 private static final String ATTRIBUTES_NAME = "sync-adapter"; 34 35 SyncAdaptersCache(Context context) { 36 super(context, SERVICE_INTERFACE, SERVICE_META_DATA, ATTRIBUTES_NAME); 37 } 38 39 public SyncAdapterType parseServiceAttributes(String packageName, AttributeSet attrs) { 40 TypedArray sa = mContext.getResources().obtainAttributes(attrs, 41 com.android.internal.R.styleable.SyncAdapter); 42 try { 43 final String authority = 44 sa.getString(com.android.internal.R.styleable.SyncAdapter_contentAuthority); 45 final String accountType = 46 sa.getString(com.android.internal.R.styleable.SyncAdapter_accountType); 47 if (authority == null || accountType == null) { 48 return null; 49 } 50 final boolean userVisible = 51 sa.getBoolean(com.android.internal.R.styleable.SyncAdapter_userVisible, true); 52 return new SyncAdapterType(authority, accountType, userVisible); 53 } finally { 54 sa.recycle(); 55 } 56 } 57}