Loading core/java/android/os/storage/IMountService.java +55 −4 Original line number Diff line number Diff line Loading @@ -252,7 +252,7 @@ public interface IMountService extends IInterface { * an int consistent with MountServiceResultCode */ public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid) throws RemoteException { int ownerUid, boolean external) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); int _result; Loading @@ -263,6 +263,7 @@ public interface IMountService extends IInterface { _data.writeString(fstype); _data.writeString(key); _data.writeInt(ownerUid); _data.writeInt(external ? 1 : 0); mRemote.transact(Stub.TRANSACTION_createSecureContainer, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); Loading Loading @@ -711,6 +712,31 @@ public interface IMountService extends IInterface { } return _result; } /** * Fix permissions in a container which has just been created and * populated. Returns an int consistent with MountServiceResultCode */ public int fixPermissionsSecureContainer(String id, int gid, String filename) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); int _result; try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeString(id); _data.writeInt(gid); _data.writeString(filename); mRemote.transact(Stub.TRANSACTION_fixPermissionsSecureContainer, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); } finally { _reply.recycle(); _data.recycle(); } return _result; } } private static final String DESCRIPTOR = "IMountService"; Loading Loading @@ -781,6 +807,8 @@ public interface IMountService extends IInterface { static final int TRANSACTION_verifyEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 32; static final int TRANSACTION_fixPermissionsSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 33; /** * Cast an IBinder object into an IMountService interface, generating a * proxy if needed. Loading Loading @@ -909,7 +937,10 @@ public interface IMountService extends IInterface { key = data.readString(); int ownerUid; ownerUid = data.readInt(); int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid); boolean external; external = 0 != data.readInt(); int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid, external); reply.writeNoException(); reply.writeInt(resultCode); return true; Loading Loading @@ -1109,6 +1140,19 @@ public interface IMountService extends IInterface { reply.writeInt(result); return true; } case TRANSACTION_fixPermissionsSecureContainer: { data.enforceInterface(DESCRIPTOR); String id; id = data.readString(); int gid; gid = data.readInt(); String filename; filename = data.readString(); int resultCode = fixPermissionsSecureContainer(id, gid, filename); reply.writeNoException(); reply.writeInt(resultCode); return true; } } return super.onTransact(code, data, reply, flags); } Loading @@ -1118,8 +1162,8 @@ public interface IMountService extends IInterface { * Creates a secure container with the specified parameters. Returns an int * consistent with MountServiceResultCode */ public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid) throws RemoteException; public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid, boolean external) throws RemoteException; /* * Destroy a secure container, and free up all resources associated with it. Loading Loading @@ -1317,4 +1361,11 @@ public interface IMountService extends IInterface { public Parcelable[] getVolumeList() throws RemoteException; public String getSecureContainerFilesystemPath(String id) throws RemoteException; /* * Fix permissions in a container which has just been created and populated. * Returns an int consistent with MountServiceResultCode */ public int fixPermissionsSecureContainer(String id, int gid, String filename) throws RemoteException; } core/java/com/android/internal/app/IMediaContainerService.aidl +5 −5 Original line number Diff line number Diff line Loading @@ -22,14 +22,14 @@ import android.content.pm.PackageInfoLite; import android.content.res.ObbInfo; interface IMediaContainerService { String copyResourceToContainer(in Uri packageURI, String containerId, String key, String resFileName); String copyResourceToContainer(in Uri packageURI, String containerId, String key, String resFileName, String publicResFileName, boolean isExternal, boolean isForwardLocked); int copyResource(in Uri packageURI, in ParcelFileDescriptor outStream); PackageInfoLite getMinimalPackageInfo(in Uri fileUri, in int flags, in long threshold); boolean checkInternalFreeStorage(in Uri fileUri, in long threshold); boolean checkExternalFreeStorage(in Uri fileUri); boolean checkInternalFreeStorage(in Uri fileUri, boolean isForwardLocked, in long threshold); boolean checkExternalFreeStorage(in Uri fileUri, boolean isForwardLocked); ObbInfo getObbInfo(in String filename); long calculateDirectorySize(in String directory); /** Return file system stats: [0] is total bytes, [1] is available bytes */ Loading core/java/com/android/internal/content/PackageHelper.java +47 −18 Original line number Diff line number Diff line Loading @@ -67,8 +67,8 @@ public class PackageHelper { return null; } public static String createSdDir(int sizeMb, String cid, String sdEncKey, int uid) { public static String createSdDir(int sizeMb, String cid, String sdEncKey, int uid, boolean isExternal) { // Create mount point via MountService IMountService mountService = getMountService(); Loading @@ -76,8 +76,8 @@ public class PackageHelper { Log.i(TAG, "Size of container " + sizeMb + " MB"); try { int rc = mountService.createSecureContainer( cid, sizeMb, "fat", sdEncKey, uid); int rc = mountService.createSecureContainer(cid, sizeMb, "ext4", sdEncKey, uid, isExternal); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to create secure container " + cid); return null; Loading Loading @@ -206,10 +206,21 @@ public class PackageHelper { return false; } public static void extractPublicFiles(String packagePath, File publicZipFile) public static int extractPublicFiles(String packagePath, File publicZipFile) throws IOException { final FileOutputStream fstr = new FileOutputStream(publicZipFile); final ZipOutputStream publicZipOutStream = new ZipOutputStream(fstr); final FileOutputStream fstr; final ZipOutputStream publicZipOutStream; if (publicZipFile == null) { fstr = null; publicZipOutStream = null; } else { fstr = new FileOutputStream(publicZipFile); publicZipOutStream = new ZipOutputStream(fstr); } int size = 0; try { final ZipFile privateZip = new ZipFile(packagePath); try { Loading @@ -219,25 +230,29 @@ public class PackageHelper { if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) { size += zipEntry.getSize(); if (publicZipFile != null) { copyZipEntry(zipEntry, privateZip, publicZipOutStream); } } } finally { try { privateZip.close(); } catch (IOException e) { } } finally { try { privateZip.close(); } catch (IOException e) {} } if (publicZipFile != null) { publicZipOutStream.finish(); publicZipOutStream.flush(); FileUtils.sync(fstr); publicZipOutStream.close(); FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1); } } finally { IoUtils.closeQuietly(publicZipOutStream); } return size; } private static void copyZipEntry(ZipEntry zipEntry, ZipFile inZipFile, Loading Loading @@ -265,4 +280,18 @@ public class PackageHelper { IoUtils.closeQuietly(data); } } public static boolean fixSdPermissions(String cid, int gid, String filename) { try { int rc = getMountService().fixPermissionsSecureContainer(cid, gid, filename); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to fixperms container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to fixperms container " + cid + " with exception " + e); } return false; } } core/tests/coretests/src/android/content/pm/PackageHelperTests.java +2 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,8 @@ public class PackageHelperTests extends AndroidTestCase { public void testMountAndPullSdCard() { try { fullId = PREFIX; fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid()); fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid(), true); Log.d(TAG,PackageHelper.getSdDir(fullId)); PackageHelper.unMountSdDir(fullId); Loading core/tests/coretests/src/android/content/pm/PackageManagerTests.java +85 −60 Original line number Diff line number Diff line Loading @@ -309,9 +309,7 @@ public class PackageManagerTests extends AndroidTestCase { private static final int INSTALL_LOC_ERR = -1; private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) { // Flags explicitly over ride everything else. if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) { return INSTALL_LOC_INT; } else if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { return INSTALL_LOC_SD; } else if ((flags & PackageManager.INSTALL_INTERNAL) != 0) { return INSTALL_LOC_INT; Loading Loading @@ -380,19 +378,27 @@ public class PackageManagerTests extends AndroidTestCase { String publicSrcPath = publicSrcDir.getParent(); long pkgLen = new File(info.sourceDir).length(); int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); if (rLoc == INSTALL_LOC_INT) { if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { assertTrue((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); assertEquals(srcPath, drmInstallPath); assertEquals(publicSrcPath, appInstallPath); assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); assertTrue("The application should be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); assertTrue("The APK path (" + srcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The public APK path (" + publicSrcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The native library path (" + info.nativeLibraryDir + ") should start with " + SECURE_CONTAINERS_PREFIX, info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); } else { assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); if (rLoc == INSTALL_LOC_INT) { assertEquals(srcPath, appInstallPath); assertEquals(publicSrcPath, appInstallPath); assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); } assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); // Make sure the native library dir is not a symlink final File nativeLibDir = new File(info.nativeLibraryDir); Loading @@ -406,15 +412,23 @@ public class PackageManagerTests extends AndroidTestCase { fail("Can't read " + nativeLibDir.getPath()); } } else if (rLoc == INSTALL_LOC_SD){ if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { assertTrue("The application should be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); } else { assertFalse("The application should not be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); } assertTrue("Application flags (" + info.flags + ") should contain FLAG_EXTERNAL_STORAGE", (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); // Might need to check: // ((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) assertTrue("The APK path (" + srcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, srcPath .startsWith(SECURE_CONTAINERS_PREFIX)); + SECURE_CONTAINERS_PREFIX, srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The public APK path (" + publicSrcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, publicSrcPath .startsWith(SECURE_CONTAINERS_PREFIX)); + SECURE_CONTAINERS_PREFIX, publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The native library path (" + info.nativeLibraryDir + ") should start with " + SECURE_CONTAINERS_PREFIX, info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); Loading @@ -435,7 +449,6 @@ public class PackageManagerTests extends AndroidTestCase { // TODO handle error. Install should have failed. fail("Install should have failed"); } } } catch (NameNotFoundException e) { failStr("failed with exception : " + e); } Loading Loading @@ -1774,15 +1787,17 @@ public class PackageManagerTests extends AndroidTestCase { } /* * Install an app with both external and forward-lock flags set. should fail * Install an app with both external and forward-lock flags set. */ @LargeTest public void testFlagEF() { installFromRawResource("install.apk", R.raw.install, PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL, false, true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION, PackageInfo.INSTALL_LOCATION_AUTO); // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL, true); } /* Loading Loading @@ -1899,15 +1914,20 @@ public class PackageManagerTests extends AndroidTestCase { PackageManager.INSTALL_FORWARD_LOCK, true, false, -1, PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL); PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY); } /* * Install an app with fwd locked flag set and install location set to * preferExternal. should install internally. * preferExternal. Should install externally. */ @LargeTest public void testFlagFManifestE() { // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } installFromRawResource("install.apk", R.raw.install_loc_sdcard, PackageManager.INSTALL_FORWARD_LOCK, true, Loading @@ -1916,11 +1936,16 @@ public class PackageManagerTests extends AndroidTestCase { } /* * Install an app with fwd locked flag set and install location set to * auto. should install internally. * Install an app with fwd locked flag set and install location set to auto. * should install externally. */ @LargeTest public void testFlagFManifestA() { // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } installFromRawResource("install.apk", R.raw.install_loc_auto, PackageManager.INSTALL_FORWARD_LOCK, true, Loading Loading
core/java/android/os/storage/IMountService.java +55 −4 Original line number Diff line number Diff line Loading @@ -252,7 +252,7 @@ public interface IMountService extends IInterface { * an int consistent with MountServiceResultCode */ public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid) throws RemoteException { int ownerUid, boolean external) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); int _result; Loading @@ -263,6 +263,7 @@ public interface IMountService extends IInterface { _data.writeString(fstype); _data.writeString(key); _data.writeInt(ownerUid); _data.writeInt(external ? 1 : 0); mRemote.transact(Stub.TRANSACTION_createSecureContainer, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); Loading Loading @@ -711,6 +712,31 @@ public interface IMountService extends IInterface { } return _result; } /** * Fix permissions in a container which has just been created and * populated. Returns an int consistent with MountServiceResultCode */ public int fixPermissionsSecureContainer(String id, int gid, String filename) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); int _result; try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeString(id); _data.writeInt(gid); _data.writeString(filename); mRemote.transact(Stub.TRANSACTION_fixPermissionsSecureContainer, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); } finally { _reply.recycle(); _data.recycle(); } return _result; } } private static final String DESCRIPTOR = "IMountService"; Loading Loading @@ -781,6 +807,8 @@ public interface IMountService extends IInterface { static final int TRANSACTION_verifyEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 32; static final int TRANSACTION_fixPermissionsSecureContainer = IBinder.FIRST_CALL_TRANSACTION + 33; /** * Cast an IBinder object into an IMountService interface, generating a * proxy if needed. Loading Loading @@ -909,7 +937,10 @@ public interface IMountService extends IInterface { key = data.readString(); int ownerUid; ownerUid = data.readInt(); int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid); boolean external; external = 0 != data.readInt(); int resultCode = createSecureContainer(id, sizeMb, fstype, key, ownerUid, external); reply.writeNoException(); reply.writeInt(resultCode); return true; Loading Loading @@ -1109,6 +1140,19 @@ public interface IMountService extends IInterface { reply.writeInt(result); return true; } case TRANSACTION_fixPermissionsSecureContainer: { data.enforceInterface(DESCRIPTOR); String id; id = data.readString(); int gid; gid = data.readInt(); String filename; filename = data.readString(); int resultCode = fixPermissionsSecureContainer(id, gid, filename); reply.writeNoException(); reply.writeInt(resultCode); return true; } } return super.onTransact(code, data, reply, flags); } Loading @@ -1118,8 +1162,8 @@ public interface IMountService extends IInterface { * Creates a secure container with the specified parameters. Returns an int * consistent with MountServiceResultCode */ public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid) throws RemoteException; public int createSecureContainer(String id, int sizeMb, String fstype, String key, int ownerUid, boolean external) throws RemoteException; /* * Destroy a secure container, and free up all resources associated with it. Loading Loading @@ -1317,4 +1361,11 @@ public interface IMountService extends IInterface { public Parcelable[] getVolumeList() throws RemoteException; public String getSecureContainerFilesystemPath(String id) throws RemoteException; /* * Fix permissions in a container which has just been created and populated. * Returns an int consistent with MountServiceResultCode */ public int fixPermissionsSecureContainer(String id, int gid, String filename) throws RemoteException; }
core/java/com/android/internal/app/IMediaContainerService.aidl +5 −5 Original line number Diff line number Diff line Loading @@ -22,14 +22,14 @@ import android.content.pm.PackageInfoLite; import android.content.res.ObbInfo; interface IMediaContainerService { String copyResourceToContainer(in Uri packageURI, String containerId, String key, String resFileName); String copyResourceToContainer(in Uri packageURI, String containerId, String key, String resFileName, String publicResFileName, boolean isExternal, boolean isForwardLocked); int copyResource(in Uri packageURI, in ParcelFileDescriptor outStream); PackageInfoLite getMinimalPackageInfo(in Uri fileUri, in int flags, in long threshold); boolean checkInternalFreeStorage(in Uri fileUri, in long threshold); boolean checkExternalFreeStorage(in Uri fileUri); boolean checkInternalFreeStorage(in Uri fileUri, boolean isForwardLocked, in long threshold); boolean checkExternalFreeStorage(in Uri fileUri, boolean isForwardLocked); ObbInfo getObbInfo(in String filename); long calculateDirectorySize(in String directory); /** Return file system stats: [0] is total bytes, [1] is available bytes */ Loading
core/java/com/android/internal/content/PackageHelper.java +47 −18 Original line number Diff line number Diff line Loading @@ -67,8 +67,8 @@ public class PackageHelper { return null; } public static String createSdDir(int sizeMb, String cid, String sdEncKey, int uid) { public static String createSdDir(int sizeMb, String cid, String sdEncKey, int uid, boolean isExternal) { // Create mount point via MountService IMountService mountService = getMountService(); Loading @@ -76,8 +76,8 @@ public class PackageHelper { Log.i(TAG, "Size of container " + sizeMb + " MB"); try { int rc = mountService.createSecureContainer( cid, sizeMb, "fat", sdEncKey, uid); int rc = mountService.createSecureContainer(cid, sizeMb, "ext4", sdEncKey, uid, isExternal); if (rc != StorageResultCode.OperationSucceeded) { Log.e(TAG, "Failed to create secure container " + cid); return null; Loading Loading @@ -206,10 +206,21 @@ public class PackageHelper { return false; } public static void extractPublicFiles(String packagePath, File publicZipFile) public static int extractPublicFiles(String packagePath, File publicZipFile) throws IOException { final FileOutputStream fstr = new FileOutputStream(publicZipFile); final ZipOutputStream publicZipOutStream = new ZipOutputStream(fstr); final FileOutputStream fstr; final ZipOutputStream publicZipOutStream; if (publicZipFile == null) { fstr = null; publicZipOutStream = null; } else { fstr = new FileOutputStream(publicZipFile); publicZipOutStream = new ZipOutputStream(fstr); } int size = 0; try { final ZipFile privateZip = new ZipFile(packagePath); try { Loading @@ -219,25 +230,29 @@ public class PackageHelper { if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) { size += zipEntry.getSize(); if (publicZipFile != null) { copyZipEntry(zipEntry, privateZip, publicZipOutStream); } } } finally { try { privateZip.close(); } catch (IOException e) { } } finally { try { privateZip.close(); } catch (IOException e) {} } if (publicZipFile != null) { publicZipOutStream.finish(); publicZipOutStream.flush(); FileUtils.sync(fstr); publicZipOutStream.close(); FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1); } } finally { IoUtils.closeQuietly(publicZipOutStream); } return size; } private static void copyZipEntry(ZipEntry zipEntry, ZipFile inZipFile, Loading Loading @@ -265,4 +280,18 @@ public class PackageHelper { IoUtils.closeQuietly(data); } } public static boolean fixSdPermissions(String cid, int gid, String filename) { try { int rc = getMountService().fixPermissionsSecureContainer(cid, gid, filename); if (rc != StorageResultCode.OperationSucceeded) { Log.i(TAG, "Failed to fixperms container " + cid); return false; } return true; } catch (RemoteException e) { Log.e(TAG, "Failed to fixperms container " + cid + " with exception " + e); } return false; } }
core/tests/coretests/src/android/content/pm/PackageHelperTests.java +2 −1 Original line number Diff line number Diff line Loading @@ -81,7 +81,8 @@ public class PackageHelperTests extends AndroidTestCase { public void testMountAndPullSdCard() { try { fullId = PREFIX; fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid()); fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid(), true); Log.d(TAG,PackageHelper.getSdDir(fullId)); PackageHelper.unMountSdDir(fullId); Loading
core/tests/coretests/src/android/content/pm/PackageManagerTests.java +85 −60 Original line number Diff line number Diff line Loading @@ -309,9 +309,7 @@ public class PackageManagerTests extends AndroidTestCase { private static final int INSTALL_LOC_ERR = -1; private int getInstallLoc(int flags, int expInstallLocation, long pkgLen) { // Flags explicitly over ride everything else. if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 ) { return INSTALL_LOC_INT; } else if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { if ((flags & PackageManager.INSTALL_EXTERNAL) != 0 ) { return INSTALL_LOC_SD; } else if ((flags & PackageManager.INSTALL_INTERNAL) != 0) { return INSTALL_LOC_INT; Loading Loading @@ -380,19 +378,27 @@ public class PackageManagerTests extends AndroidTestCase { String publicSrcPath = publicSrcDir.getParent(); long pkgLen = new File(info.sourceDir).length(); int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); if (rLoc == INSTALL_LOC_INT) { if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { assertTrue((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); assertEquals(srcPath, drmInstallPath); assertEquals(publicSrcPath, appInstallPath); assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); assertTrue("The application should be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); assertTrue("The APK path (" + srcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The public APK path (" + publicSrcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The native library path (" + info.nativeLibraryDir + ") should start with " + SECURE_CONTAINERS_PREFIX, info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); } else { assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); int rLoc = getInstallLoc(flags, expInstallLocation, pkgLen); if (rLoc == INSTALL_LOC_INT) { assertEquals(srcPath, appInstallPath); assertEquals(publicSrcPath, appInstallPath); assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); assertTrue(info.nativeLibraryDir.startsWith(dataDir.getPath())); } assertFalse((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); // Make sure the native library dir is not a symlink final File nativeLibDir = new File(info.nativeLibraryDir); Loading @@ -406,15 +412,23 @@ public class PackageManagerTests extends AndroidTestCase { fail("Can't read " + nativeLibDir.getPath()); } } else if (rLoc == INSTALL_LOC_SD){ if ((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) { assertTrue("The application should be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); } else { assertFalse("The application should not be installed forward locked", (info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0); } assertTrue("Application flags (" + info.flags + ") should contain FLAG_EXTERNAL_STORAGE", (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0); // Might need to check: // ((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0) assertTrue("The APK path (" + srcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, srcPath .startsWith(SECURE_CONTAINERS_PREFIX)); + SECURE_CONTAINERS_PREFIX, srcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The public APK path (" + publicSrcPath + ") should start with " + SECURE_CONTAINERS_PREFIX, publicSrcPath .startsWith(SECURE_CONTAINERS_PREFIX)); + SECURE_CONTAINERS_PREFIX, publicSrcPath.startsWith(SECURE_CONTAINERS_PREFIX)); assertTrue("The native library path (" + info.nativeLibraryDir + ") should start with " + SECURE_CONTAINERS_PREFIX, info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX)); Loading @@ -435,7 +449,6 @@ public class PackageManagerTests extends AndroidTestCase { // TODO handle error. Install should have failed. fail("Install should have failed"); } } } catch (NameNotFoundException e) { failStr("failed with exception : " + e); } Loading Loading @@ -1774,15 +1787,17 @@ public class PackageManagerTests extends AndroidTestCase { } /* * Install an app with both external and forward-lock flags set. should fail * Install an app with both external and forward-lock flags set. */ @LargeTest public void testFlagEF() { installFromRawResource("install.apk", R.raw.install, PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL, false, true, PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION, PackageInfo.INSTALL_LOCATION_AUTO); // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } sampleInstallFromRawResource(PackageManager.INSTALL_FORWARD_LOCK | PackageManager.INSTALL_EXTERNAL, true); } /* Loading Loading @@ -1899,15 +1914,20 @@ public class PackageManagerTests extends AndroidTestCase { PackageManager.INSTALL_FORWARD_LOCK, true, false, -1, PackageInfo.INSTALL_LOCATION_PREFER_EXTERNAL); PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY); } /* * Install an app with fwd locked flag set and install location set to * preferExternal. should install internally. * preferExternal. Should install externally. */ @LargeTest public void testFlagFManifestE() { // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } installFromRawResource("install.apk", R.raw.install_loc_sdcard, PackageManager.INSTALL_FORWARD_LOCK, true, Loading @@ -1916,11 +1936,16 @@ public class PackageManagerTests extends AndroidTestCase { } /* * Install an app with fwd locked flag set and install location set to * auto. should install internally. * Install an app with fwd locked flag set and install location set to auto. * should install externally. */ @LargeTest public void testFlagFManifestA() { // Do not run on devices with emulated external storage. if (Environment.isExternalStorageEmulated()) { return; } installFromRawResource("install.apk", R.raw.install_loc_auto, PackageManager.INSTALL_FORWARD_LOCK, true, Loading