1 /* 2 * Copyright (C) 2016 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 17 package android.content.cts; 18 19 import android.accounts.Account; 20 import android.content.ComponentName; 21 import android.content.ContentResolver; 22 import android.content.Context; 23 import android.content.ContextWrapper; 24 import android.content.Intent; 25 import android.content.PeriodicSync; 26 import android.content.res.Resources; 27 import android.content.SyncStatusInfo; 28 import android.os.Bundle; 29 import android.os.Looper; 30 import android.test.AndroidTestCase; 31 import android.test.RenamingDelegatingContext; 32 import android.test.mock.MockContentResolver; 33 import android.test.mock.MockContext; 34 import android.test.suitebuilder.annotation.LargeTest; 35 import android.test.suitebuilder.annotation.MediumTest; 36 import android.test.suitebuilder.annotation.SmallTest; 37 import com.android.server.content.SyncStorageEngine; 38 import com.android.internal.os.AtomicFile; 39 40 import java.io.File; 41 import java.io.FileOutputStream; 42 import java.util.List; 43 44 public class SyncStorageEngineTest extends AndroidTestCase { 45 public void testMalformedAuthority() throws Exception { 46 Looper.prepare(); 47 // Authority id is non integer. It should be discarded by SyncStorageEngine. 48 byte[] accountsFileData = ("<?xml version='1.0' encoding='utf-8' standalone='yes' ?>\n" 49 + "<accounts>\n" 50 + "<listenForTickles user=\"0\" enabled=\"false\" />" 51 + "<listenForTickles user=\"1\" enabled=\"true\" />" 52 + "<authority id=\"nonint\" user=\"0\" account=\"account1\" type=\"type1\"" 53 + " authority=\"auth1\" />\n" 54 + "</accounts>\n").getBytes(); 55 56 File syncDir = getSyncDir(); 57 syncDir.mkdirs(); 58 AtomicFile accountInfoFile = new AtomicFile(new File(syncDir, "accounts.xml")); 59 FileOutputStream fos = accountInfoFile.startWrite(); 60 fos.write(accountsFileData); 61 accountInfoFile.finishWrite(fos); 62 63 SyncStorageEngine engine = SyncStorageEngine.newTestInstance(getContext()); 64 Account account = new Account("account1", "type1"); 65 SyncStorageEngine.EndPoint endPoint = new SyncStorageEngine.EndPoint(account, "auth1", 0); 66 SyncStatusInfo info = engine.getStatusByAuthority(endPoint); 67 assertNull(info); 68 } 69 70 private File getSyncDir() { 71 return new File(new File(getContext().getFilesDir(), "system"), "sync"); 72 } 73 } 74