1 /* 2 * Copyright (C) 2015 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 com.android.cts.writeexternalstorageapp; 18 19 import static android.test.MoreAsserts.assertNotEqual; 20 21 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.PACKAGE_READ; 22 import static com.android.cts.externalstorageapp.CommonExternalStorageTest.assertFileReadWriteAccess; 23 24 import android.os.SystemClock; 25 import android.system.Os; 26 27 import android.test.AndroidTestCase; 28 import android.text.format.DateUtils; 29 30 import android.util.Log; 31 32 import java.io.File; 33 import java.util.List; 34 35 public class WriteMultiViewTest extends AndroidTestCase { 36 /** 37 * Move PACKAGE_READ's cache to our cache 38 */ 39 public void testMoveAway() throws Exception { 40 final File ourCache = getContext().getExternalCacheDir(); 41 final File otherCache = new File(ourCache.getAbsolutePath() 42 .replace(getContext().getPackageName(), PACKAGE_READ)); 43 final File ourTestDir = new File(ourCache, "testDir"); 44 final File otherTestDir = new File(otherCache, "testDir"); 45 final File beforeFile = new File(otherTestDir, "test.probe"); 46 final File afterFile = new File(ourTestDir, "test.probe"); 47 48 Os.rename(otherTestDir.getAbsolutePath(), ourTestDir.getAbsolutePath()); 49 50 assertEquals(Os.getuid(), Os.stat(ourCache.getAbsolutePath()).st_uid); 51 assertEquals(Os.getuid(), Os.stat(ourTestDir.getAbsolutePath()).st_uid); 52 assertEquals(Os.getuid(), Os.stat(afterFile.getAbsolutePath()).st_uid); 53 } 54 55 /** 56 * Move our cache to PACKAGE_READ's cache 57 */ 58 public void testMoveBack() throws Exception { 59 final File ourCache = getContext().getExternalCacheDir(); 60 final File otherCache = new File(ourCache.getAbsolutePath() 61 .replace(getContext().getPackageName(), PACKAGE_READ)); 62 final File ourTestDir = new File(ourCache, "testDir"); 63 final File otherTestDir = new File(otherCache, "testDir"); 64 final File beforeFile = new File(ourTestDir, "test.probe"); 65 final File afterFile = new File(otherTestDir, "test.probe"); 66 67 Os.rename(ourTestDir.getAbsolutePath(), otherTestDir.getAbsolutePath()); 68 69 // Sit around long enough for VFS cache to expire 70 SystemClock.sleep(15 * DateUtils.SECOND_IN_MILLIS); 71 72 assertNotEqual(Os.getuid(), Os.stat(otherCache.getAbsolutePath()).st_uid); 73 assertNotEqual(Os.getuid(), Os.stat(otherTestDir.getAbsolutePath()).st_uid); 74 assertNotEqual(Os.getuid(), Os.stat(afterFile.getAbsolutePath()).st_uid); 75 } 76 } 77