Revert "Remove the APIs for the old encryption scheme."

This reverts commit 1125d780a8b61703b8eb28c5c77dac5f3f0022dd.
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index 3b0a6d5..cb1d775 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -16,11 +16,6 @@
 
 package com.android.server;
 
-import com.android.internal.backup.BackupConstants;
-import com.android.internal.backup.IBackupTransport;
-import com.android.internal.backup.LocalTransport;
-import com.android.server.PackageManagerBackupAgent.Metadata;
-
 import android.app.ActivityManagerNative;
 import android.app.AlarmManager;
 import android.app.AppGlobals;
@@ -28,10 +23,10 @@
 import android.app.IApplicationThread;
 import android.app.IBackupAgent;
 import android.app.PendingIntent;
+import android.app.backup.RestoreSet;
 import android.app.backup.IBackupManager;
 import android.app.backup.IRestoreObserver;
 import android.app.backup.IRestoreSession;
-import android.app.backup.RestoreSet;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
@@ -43,8 +38,8 @@
 import android.content.pm.IPackageManager;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.Signature;
+import android.content.pm.PackageManager.NameNotFoundException;
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Bundle;
@@ -66,6 +61,11 @@
 import android.util.SparseArray;
 import android.util.SparseIntArray;
 
+import com.android.internal.backup.BackupConstants;
+import com.android.internal.backup.IBackupTransport;
+import com.android.internal.backup.LocalTransport;
+import com.android.server.PackageManagerBackupAgent.Metadata;
+
 import java.io.EOFException;
 import java.io.File;
 import java.io.FileDescriptor;
@@ -145,7 +145,6 @@
             fullBackup = isFull;
         }
 
-        @Override
         public String toString() {
             return "BackupRequest{app=" + appInfo + " full=" + fullBackup + "}";
         }
@@ -272,7 +271,6 @@
             super(looper);
         }
 
-        @Override
         public void handleMessage(Message msg) {
 
             switch (msg.what) {
@@ -445,7 +443,7 @@
                 Settings.Secure.BACKUP_AUTO_RESTORE, 1) != 0;
         // If Encrypted file systems is enabled or disabled, this call will return the
         // correct directory.
-        mBaseStateDir = new File(Environment.getDataDirectory(), "backup");
+        mBaseStateDir = new File(Environment.getSecureDataDirectory(), "backup");
         mBaseStateDir.mkdirs();
         mDataDir = Environment.getDownloadCacheDirectory();
 
@@ -535,7 +533,6 @@
     }
 
     private class RunBackupReceiver extends BroadcastReceiver {
-        @Override
         public void onReceive(Context context, Intent intent) {
             if (RUN_BACKUP_ACTION.equals(intent.getAction())) {
                 synchronized (mQueueLock) {
@@ -572,7 +569,6 @@
     }
 
     private class RunInitializeReceiver extends BroadcastReceiver {
-        @Override
         public void onReceive(Context context, Intent intent) {
             if (RUN_INITIALIZE_ACTION.equals(intent.getAction())) {
                 synchronized (mQueueLock) {
@@ -816,7 +812,6 @@
 
     // ----- Track installation/removal of packages -----
     BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
-        @Override
         public void onReceive(Context context, Intent intent) {
             if (DEBUG) Slog.d(TAG, "Received broadcast " + intent);
 
diff --git a/services/java/com/android/server/Installer.java b/services/java/com/android/server/Installer.java
index 1028b89..85eca60 100644
--- a/services/java/com/android/server/Installer.java
+++ b/services/java/com/android/server/Installer.java
@@ -17,13 +17,16 @@
 package com.android.server;
 
 import android.content.pm.PackageStats;
-import android.net.LocalSocket;
 import android.net.LocalSocketAddress;
+import android.net.LocalSocket;
+import android.util.Config;
 import android.util.Slog;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.Socket;
+
 
 class Installer {
     private static final String TAG = "Installer";
@@ -98,7 +101,7 @@
 		int len;
 		buflen = 0;
 		if (!readBytes(buf, 2)) return false;
-		len = ((buf[0]) & 0xff) | (((buf[1]) & 0xff) << 8);
+		len = (((int) buf[0]) & 0xff) | ((((int) buf[1]) & 0xff) << 8);
 		if ((len < 1) || (len > 1024)) {
             Slog.e(TAG,"invalid reply length ("+len+")");
 			disconnect();
@@ -163,11 +166,17 @@
 		}
 	}
 
-    public int install(String name, int uid, int gid) {
+    public int install(String name, boolean useEncryptedFilesystem, int uid, int gid) {
         StringBuilder builder = new StringBuilder("install");
         builder.append(' ');
         builder.append(name);
         builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
+        builder.append(' ');
         builder.append(uid);
         builder.append(' ');
         builder.append(gid);
@@ -200,34 +209,57 @@
         return execute(builder.toString());
     }
 
-    public int remove(String name) {
+    public int remove(String name, boolean useEncryptedFilesystem) {
         StringBuilder builder = new StringBuilder("remove");
         builder.append(' ');
         builder.append(name);
+        builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
         return execute(builder.toString());
     }
 
-    public int rename(String oldname, String newname) {
+    public int rename(String oldname, String newname, boolean useEncryptedFilesystem) {
         StringBuilder builder = new StringBuilder("rename");
         builder.append(' ');
         builder.append(oldname);
         builder.append(' ');
         builder.append(newname);
+        builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
         return execute(builder.toString());
     }
 
-    public int deleteCacheFiles(String name) {
+    public int deleteCacheFiles(String name, boolean useEncryptedFilesystem) {
         StringBuilder builder = new StringBuilder("rmcache");
         builder.append(' ');
         builder.append(name);
         builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
         return execute(builder.toString());
     }
     
-    public int clearUserData(String name) {
+    public int clearUserData(String name, boolean useEncryptedFilesystem) {
         StringBuilder builder = new StringBuilder("rmuserdata");
         builder.append(' ');
         builder.append(name);
+        builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
         return execute(builder.toString());
     }
     
@@ -260,8 +292,8 @@
         return execute(builder.toString());
     }
     
-    public int getSizeInfo(String pkgName, String apkPath, String fwdLockApkPath,
-            PackageStats pStats) {
+    public int getSizeInfo(String pkgName, String apkPath,
+            String fwdLockApkPath, PackageStats pStats, boolean useEncryptedFilesystem) {
         StringBuilder builder = new StringBuilder("getsize");
         builder.append(' ');
         builder.append(pkgName);
@@ -269,6 +301,12 @@
         builder.append(apkPath);
         builder.append(' ');
         builder.append(fwdLockApkPath != null ? fwdLockApkPath : "!");
+        builder.append(' ');
+        if (useEncryptedFilesystem) {
+            builder.append('1');
+        } else {
+            builder.append('0');
+        }
 
         String s = transaction(builder.toString());
         String res[] = s.split(" ");
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 286463d..b196f74 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -16,10 +16,6 @@
 
 package com.android.server;
 
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
-
 import com.android.internal.app.IMediaContainerService;
 import com.android.internal.app.ResolverActivity;
 import com.android.internal.content.NativeLibraryHelper;
@@ -28,18 +24,22 @@
 import com.android.internal.util.JournaledFile;
 import com.android.internal.util.XmlUtils;
 
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
 import android.app.ActivityManagerNative;
 import android.app.IActivityManager;
 import android.app.admin.IDevicePolicyManager;
 import android.app.backup.IBackupManager;
-import android.content.ComponentName;
 import android.content.Context;
+import android.content.ComponentName;
 import android.content.IIntentReceiver;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.IntentSender;
-import android.content.IntentSender.SendIntentException;
 import android.content.ServiceConnection;
+import android.content.IntentSender.SendIntentException;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.ComponentInfo;
@@ -54,10 +54,13 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInfoLite;
 import android.content.pm.PackageManager;
-import android.content.pm.PackageParser;
 import android.content.pm.PackageStats;
-import android.content.pm.PermissionGroupInfo;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+import android.content.pm.PackageParser;
 import android.content.pm.PermissionInfo;
+import android.content.pm.PermissionGroupInfo;
 import android.content.pm.ProviderInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
@@ -67,30 +70,24 @@
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Debug;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.FileUtils;
-import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
 import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.Environment;
+import android.os.FileObserver;
+import android.os.FileUtils;
+import android.os.Handler;
 import android.os.ParcelFileDescriptor;
 import android.os.Process;
-import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.os.SystemProperties;
+import android.provider.Settings;
 import android.security.SystemKeyStore;
-import android.util.Config;
-import android.util.DisplayMetrics;
-import android.util.EventLog;
-import android.util.Log;
-import android.util.LogPrinter;
-import android.util.Slog;
-import android.util.SparseArray;
-import android.util.Xml;
+import android.util.*;
 import android.view.Display;
 import android.view.WindowManager;
 
@@ -117,17 +114,15 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipOutputStream;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlSerializer;
-
 /**
  * Keep track of all those .apks everywhere.
  * 
@@ -435,7 +430,6 @@
             super(looper);
         }
         
-        @Override
         public void handleMessage(Message msg) {
             try {
                 doHandleMessage(msg);
@@ -577,7 +571,7 @@
                     // Send broadcasts
                     for (int i = 0; i < size; i++) {
                         sendPackageChangedBroadcast(packages[i], true,
-                                components[i], uids[i]);
+                                (ArrayList<String>)components[i], uids[i]);
                     }
                     Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
                     break;
@@ -970,7 +964,9 @@
                             + " no longer exists; wiping its data";
                     reportSettingsProblem(Log.WARN, msg);
                     if (mInstaller != null) {
-                            mInstaller.remove(ps.name);
+                        // XXX how to set useEncryptedFSDir for packages that
+                        // are not encrypted?
+                        mInstaller.remove(ps.name, true);
                     }
                 }
             }
@@ -1054,7 +1050,8 @@
     void cleanupInstallFailedPackage(PackageSetting ps) {
         Slog.i(TAG, "Cleaning up incompletely installed app: " + ps.name);
         if (mInstaller != null) {
-            int retCode = mInstaller.remove(ps.name);
+            boolean useSecureFS = useEncryptedFilesystemForPackage(ps.pkg);
+            int retCode = mInstaller.remove(ps.name, useSecureFS);
             if (retCode < 0) {
                 Slog.w(TAG, "Couldn't remove app data directory for package: "
                            + ps.name + ", retcode=" + retCode);
@@ -2082,12 +2079,12 @@
         synchronized (mPackages) {
             String pkgName = intent.getPackage();
             if (pkgName == null) {
-                return mActivities.queryIntent(intent,
+                return (List<ResolveInfo>)mActivities.queryIntent(intent,
                         resolvedType, flags);
             }
             PackageParser.Package pkg = mPackages.get(pkgName);
             if (pkg != null) {
-                return mActivities.queryIntentForPackage(intent,
+                return (List<ResolveInfo>) mActivities.queryIntentForPackage(intent,
                         resolvedType, flags, pkg.activities);
             }
             return null;
@@ -2272,12 +2269,12 @@
         synchronized (mPackages) {
             String pkgName = intent.getPackage();
             if (pkgName == null) {
-                return mReceivers.queryIntent(intent,
+                return (List<ResolveInfo>)mReceivers.queryIntent(intent,
                         resolvedType, flags);
             }
             PackageParser.Package pkg = mPackages.get(pkgName);
             if (pkg != null) {
-                return mReceivers.queryIntentForPackage(intent,
+                return (List<ResolveInfo>) mReceivers.queryIntentForPackage(intent,
                         resolvedType, flags, pkg.receivers);
             }
             return null;
@@ -2315,12 +2312,12 @@
         synchronized (mPackages) {
             String pkgName = intent.getPackage();
             if (pkgName == null) {
-                return mServices.queryIntent(intent,
+                return (List<ResolveInfo>)mServices.queryIntent(intent,
                         resolvedType, flags);
             }
             PackageParser.Package pkg = mPackages.get(pkgName);
             if (pkg != null) {
-                return mServices.queryIntentForPackage(intent,
+                return (List<ResolveInfo>)mServices.queryIntentForPackage(intent,
                         resolvedType, flags, pkg.services);
             }
             return null;
@@ -2419,7 +2416,6 @@
     /**
      * @deprecated
      */
-    @Deprecated
     public void querySyncProviders(List outNames, List outInfo) {
         synchronized (mPackages) {
             Iterator<Map.Entry<String, PackageParser.Provider>> i
@@ -2784,6 +2780,11 @@
         return performed ? DEX_OPT_PERFORMED : DEX_OPT_SKIPPED;
     }
 
+    private static boolean useEncryptedFilesystemForPackage(PackageParser.Package pkg) {
+        return Environment.isEncryptedFilesystemEnabled() &&
+                ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_NEVER_ENCRYPT) == 0);
+    }
+    
     private boolean verifyPackageUpdate(PackageSetting oldPkg, PackageParser.Package newPkg) {
         if ((oldPkg.pkgFlags&ApplicationInfo.FLAG_SYSTEM) == 0) {
             Slog.w(TAG, "Unable to update from " + oldPkg.name
@@ -2800,7 +2801,14 @@
     }
 
     private File getDataPathForPackage(PackageParser.Package pkg) {
-        return new File(mAppDataDir, pkg.packageName);
+        boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg);
+        File dataPath;
+        if (useEncryptedFSDir) {
+            dataPath = new File(mSecureAppDataDir, pkg.packageName);
+        } else {
+            dataPath = new File(mAppDataDir, pkg.packageName);
+        }
+        return dataPath;
     }
     
     private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
@@ -3149,6 +3157,7 @@
             pkg.applicationInfo.dataDir = dataPath.getPath();
         } else {
             // This is a normal package, need to make its data directory.
+            boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(pkg);
             dataPath = getDataPathForPackage(pkg);
             
             boolean uidError = false;
@@ -3165,7 +3174,7 @@
                         // If this is a system app, we can at least delete its
                         // current data so the application will still work.
                         if (mInstaller != null) {
-                            int ret = mInstaller.remove(pkgName);
+                            int ret = mInstaller.remove(pkgName, useEncryptedFSDir);
                             if (ret >= 0) {
                                 // Old data gone!
                                 String msg = "System package " + pkg.packageName
@@ -3176,7 +3185,7 @@
                                 recovered = true;
 
                                 // And now re-install the app.
-                                ret = mInstaller.install(pkgName, pkg.applicationInfo.uid,
+                                ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid,
                                         pkg.applicationInfo.uid);
                                 if (ret == -1) {
                                     // Ack should not happen!
@@ -3217,7 +3226,7 @@
                     Log.v(TAG, "Want this data dir: " + dataPath);
                 //invoke installer to do the actual installation
                 if (mInstaller != null) {
-                    int ret = mInstaller.install(pkgName, pkg.applicationInfo.uid,
+                    int ret = mInstaller.install(pkgName, useEncryptedFSDir, pkg.applicationInfo.uid,
                             pkg.applicationInfo.uid);
                     if(ret < 0) {
                         // Error from installer
@@ -4038,7 +4047,6 @@
     
     private final class ActivityIntentResolver
             extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> {
-        @Override
         public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) {
             mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
             return super.queryIntent(intent, resolvedType, defaultOnly);
@@ -4198,7 +4206,6 @@
 
     private final class ServiceIntentResolver
             extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> {
-        @Override
         public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) {
             mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
             return super.queryIntent(intent, resolvedType, defaultOnly);
@@ -4294,7 +4301,7 @@
         @Override
         protected ResolveInfo newResult(PackageParser.ServiceIntentInfo filter,
                 int match) {
-            final PackageParser.ServiceIntentInfo info = filter;
+            final PackageParser.ServiceIntentInfo info = (PackageParser.ServiceIntentInfo)filter;
             if (!mSettings.isEnabledLP(info.service.info, mFlags)) {
                 return null;
             }
@@ -4455,7 +4462,6 @@
             mIsRom = isrom;
         }
 
-        @Override
         public void onEvent(int event, String path) {
             String removedPackage = null;
             int removedUid = -1;
@@ -4840,7 +4846,6 @@
          * policy if needed and then create install arguments based
          * on the install location.
          */
-        @Override
         public void handleStartCopy() throws RemoteException {
             int ret = PackageManager.INSTALL_SUCCEEDED;
             boolean fwdLocked = (flags & PackageManager.INSTALL_FORWARD_LOCK) != 0;
@@ -4950,7 +4955,6 @@
             }
         }
 
-        @Override
         public void handleStartCopy() throws RemoteException {
             mRet = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
             // Check for storage space on target medium
@@ -5080,7 +5084,6 @@
             libraryPath = new File(dataDir, LIB_DIR_NAME).getPath();
         }
 
-        @Override
         boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
             try {
                 mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
@@ -5091,12 +5094,10 @@
             }
         }
 
-        @Override
         String getCodePath() {
             return codeFileName;
         }
 
-        @Override
         void createCopyFile() {
             installDir = isFwdLocked() ? mDrmAppPrivateInstallDir : mAppInstallDir;
             codeFileName = createTempPackageFile(installDir).getPath();
@@ -5104,7 +5105,6 @@
             created = true;
         }
 
-        @Override
         int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
             if (temp) {
                 // Generate temp file name
@@ -5148,7 +5148,6 @@
             return ret;
         }
 
-        @Override
         int doPreInstall(int status) {
             if (status != PackageManager.INSTALL_SUCCEEDED) {
                 cleanUp();
@@ -5156,7 +5155,6 @@
             return status;
         }
 
-        @Override
         boolean doRename(int status, final String pkgName, String oldCodePath) {
             if (status != PackageManager.INSTALL_SUCCEEDED) {
                 cleanUp();
@@ -5181,7 +5179,6 @@
             }
         }
 
-        @Override
         int doPostInstall(int status) {
             if (status != PackageManager.INSTALL_SUCCEEDED) {
                 cleanUp();
@@ -5189,7 +5186,6 @@
             return status;
         }
 
-        @Override
         String getResourcePath() {
             return resourceFileName;
         }
@@ -5234,7 +5230,6 @@
             return ret;
         }
 
-        @Override
         void cleanUpResourcesLI() {
             String sourceDir = getCodePath();
             if (cleanUp() && mInstaller != null) {
@@ -5267,7 +5262,6 @@
             return true;
         }
 
-        @Override
         boolean doPostDeleteLI(boolean delete) {
             // XXX err, shouldn't we respect the delete flag?
             cleanUpResourcesLI();
@@ -5312,12 +5306,10 @@
             this.cid = cid;
         }
 
-        @Override
         void createCopyFile() {
             cid = getTempContainerId();
         }
 
-        @Override
         boolean checkFreeStorage(IMediaContainerService imcs) throws RemoteException {
             try {
                 mContext.grantUriPermission(DEFAULT_CONTAINER_PACKAGE, packageURI,
@@ -5328,7 +5320,6 @@
             }
         }
 
-        @Override
         int copyApk(IMediaContainerService imcs, boolean temp) throws RemoteException {
             if (temp) {
                 createCopyFile();
@@ -5367,7 +5358,6 @@
             return libraryPath;
         }
 
-        @Override
         int doPreInstall(int status) {
             if (status != PackageManager.INSTALL_SUCCEEDED) {
                 // Destroy container
@@ -5387,7 +5377,6 @@
             return status;
         }
 
-        @Override
         boolean doRename(int status, final String pkgName,
                 String oldCodePath) {
             String newCacheId = getNextCodePath(oldCodePath, pkgName, "/" + RES_FILE_NAME);
@@ -5439,7 +5428,6 @@
             packagePath = new File(cachePath, RES_FILE_NAME).getPath();
         }
 
-        @Override
         int doPostInstall(int status) {
             if (status != PackageManager.INSTALL_SUCCEEDED) {
                 cleanUp();
@@ -5458,7 +5446,6 @@
             PackageHelper.destroySdDir(cid);
         }
 
-        @Override
         void cleanUpResourcesLI() {
             String sourceFile = getCodePath();
             // Remove dex file
@@ -5489,7 +5476,6 @@
             return cid.substring(0, idx);
         }
 
-        @Override
         boolean doPostDeleteLI(boolean delete) {
             boolean ret = false;
             boolean mounted = PackageHelper.isContainerMounted(cid);
@@ -6275,8 +6261,9 @@
             deletedPs = mSettings.mPackages.get(packageName);
         }
         if ((flags&PackageManager.DONT_DELETE_DATA) == 0) {
+            boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p);
             if (mInstaller != null) {
-                int retCode = mInstaller.remove(packageName);
+                int retCode = mInstaller.remove(packageName, useEncryptedFSDir);
                 if (retCode < 0) {
                     Slog.w(TAG, "Couldn't remove app data or cache directory for package: "
                                + packageName + ", retcode=" + retCode);
@@ -6529,9 +6516,10 @@
                 Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
                 return false;
             }
+            useEncryptedFSDir = useEncryptedFilesystemForPackage(p);
         }
         if (mInstaller != null) {
-            int retCode = mInstaller.clearUserData(packageName);
+            int retCode = mInstaller.clearUserData(packageName, useEncryptedFSDir);
             if (retCode < 0) {
                 Slog.w(TAG, "Couldn't remove cache files for package: "
                         + packageName);
@@ -6582,8 +6570,9 @@
             Slog.w(TAG, "Package " + packageName + " has no applicationInfo.");
             return false;
         }
+        boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p);
         if (mInstaller != null) {
-            int retCode = mInstaller.deleteCacheFiles(packageName);
+            int retCode = mInstaller.deleteCacheFiles(packageName, useEncryptedFSDir);
             if (retCode < 0) {
                 Slog.w(TAG, "Couldn't remove cache files for package: "
                            + packageName);
@@ -6645,8 +6634,10 @@
             }
             publicSrcDir = isForwardLocked(p) ? applicationInfo.publicSourceDir : null;
         }
+        boolean useEncryptedFSDir = useEncryptedFilesystemForPackage(p);
         if (mInstaller != null) {
-            int res = mInstaller.getSizeInfo(packageName, p.mPath, publicSrcDir, pStats);
+            int res = mInstaller.getSizeInfo(packageName, p.mPath,
+                    publicSrcDir, pStats, useEncryptedFSDir);
             if (res < 0) {
                 return false;
             } else {
@@ -7452,7 +7443,6 @@
             protectionLevel = PermissionInfo.PROTECTION_SIGNATURE;
         }
         
-        @Override
         public String toString() {
             return "BasePermission{"
                 + Integer.toHexString(System.identityHashCode(this))
@@ -7749,7 +7739,6 @@
             mSetComponents = myComponents;
         }
 
-        @Override
         public void writeToXml(XmlSerializer serializer) throws IOException {
             final int NS = mSetClasses != null ? mSetClasses.length : 0;
             serializer.attribute(null, "name", mShortActivity);
@@ -7803,7 +7792,8 @@
             this.pkgFlags = pkgFlags & (
                     ApplicationInfo.FLAG_SYSTEM |
                     ApplicationInfo.FLAG_FORWARD_LOCK |
-                    ApplicationInfo.FLAG_EXTERNAL_STORAGE);
+                    ApplicationInfo.FLAG_EXTERNAL_STORAGE |
+                    ApplicationInfo.FLAG_NEVER_ENCRYPT);
         }
     }
 
@@ -7947,7 +7937,7 @@
         }
 
         public void copyFrom(PackageSetting base) {
-            super.copyFrom(base);
+            super.copyFrom((PackageSettingBase) base);
 
             userId = base.userId;
             sharedUser = base.sharedUser;
@@ -8760,7 +8750,7 @@
                         sb.setLength(0);
                         sb.append(ai.packageName);
                         sb.append(" ");
-                        sb.append(ai.uid);
+                        sb.append((int)ai.uid);
                         sb.append(isDebug ? " 1 " : " 0 ");
                         sb.append(dataPath);
                         sb.append("\n");