Program: 194113
Project: 194113
Buggy source:
private void movePackageInternal(final String packageName,final String volumeUuid,final int moveId) throws PackageManagerException {
  final UserHandle user=new UserHandle(UserHandle.getCallingUserId());
  final StorageManager storage=mContext.getSystemService(StorageManager.class);
  final PackageManager pm=mContext.getPackageManager();
  final boolean currentAsec;
  final String currentVolumeUuid;
  final File codeFile;
  final String installerPackageName;
  final String packageAbiOverride;
  final int appId;
  final String seinfo;
  final String label;
synchronized (mPackages) {
    final PackageParser.Package pkg=mPackages.get(packageName);
    final PackageSetting ps=mSettings.mPackages.get(packageName);
    if (pkg == null || ps == null) {
      throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST,"String_Node_Str");
    }
    if (pkg.applicationInfo.isSystemApp()) {
      throw new PackageManagerException(MOVE_FAILED_SYSTEM_PACKAGE,"String_Node_Str");
    }
    if (Objects.equals(ps.volumeUuid,volumeUuid)) {
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str" + volumeUuid);
    }
    final File probe=new File(pkg.codePath);
    final File probeOat=new File(probe,"String_Node_Str");
    if (!probe.isDirectory() || !probeOat.isDirectory()) {
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
    if (ps.frozen) {
      throw new PackageManagerException(MOVE_FAILED_OPERATION_PENDING,"String_Node_Str");
    }
    ps.frozen=true;
    currentAsec=pkg.applicationInfo.isForwardLocked() || pkg.applicationInfo.isExternalAsec();
    currentVolumeUuid=ps.volumeUuid;
    codeFile=new File(pkg.codePath);
    installerPackageName=ps.installerPackageName;
    packageAbiOverride=ps.cpuAbiOverrideString;
    appId=UserHandle.getAppId(pkg.applicationInfo.uid);
    seinfo=pkg.applicationInfo.seinfo;
    label=String.valueOf(pm.getApplicationLabel(pkg.applicationInfo));
  }
  killApplication(packageName,appId,"String_Node_Str");
  final Bundle extras=new Bundle();
  extras.putString(Intent.EXTRA_PACKAGE_NAME,packageName);
  extras.putString(Intent.EXTRA_TITLE,label);
  mMoveCallbacks.notifyCreated(moveId,extras);
  int installFlags;
  final boolean moveCompleteApp;
  final File measurePath;
  if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL,volumeUuid)) {
    installFlags=INSTALL_INTERNAL;
    moveCompleteApp=!currentAsec;
    measurePath=Environment.getDataAppDirectory(volumeUuid);
  }
 else   if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,volumeUuid)) {
    installFlags=INSTALL_EXTERNAL;
    moveCompleteApp=false;
    measurePath=storage.getPrimaryPhysicalVolume().getPath();
  }
 else {
    final VolumeInfo volume=storage.findVolumeByUuid(volumeUuid);
    if (volume == null || volume.getType() != VolumeInfo.TYPE_PRIVATE || !volume.isMountedWritable()) {
      unfreezePackage(packageName);
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
    Preconditions.checkState(!currentAsec);
    installFlags=INSTALL_INTERNAL;
    moveCompleteApp=true;
    measurePath=Environment.getDataAppDirectory(volumeUuid);
  }
  final PackageStats stats=new PackageStats(null,-1);
synchronized (mInstaller) {
    if (!getPackageSizeInfoLI(packageName,-1,stats)) {
      unfreezePackage(packageName);
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
  }
  if (DEBUG_INSTALL)   Slog.d(TAG,"String_Node_Str" + stats.codeSize + "String_Node_Str"+ stats.dataSize);
  final long startFreeBytes=measurePath.getFreeSpace();
  final long sizeBytes;
  if (moveCompleteApp) {
    sizeBytes=stats.codeSize + stats.dataSize;
  }
 else {
    sizeBytes=stats.codeSize;
  }
  if (sizeBytes > storage.getStorageBytesUntilLow(measurePath)) {
    unfreezePackage(packageName);
    throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
  }
  mMoveCallbacks.notifyStatusChanged(moveId,10);
  final CountDownLatch installedLatch=new CountDownLatch(1);
  final IPackageInstallObserver2 installObserver=new IPackageInstallObserver2.Stub(){
    @Override public void onUserActionRequired(    Intent intent) throws RemoteException {
      throw new IllegalStateException();
    }
    @Override public void onPackageInstalled(    String basePackageName,    int returnCode,    String msg,    Bundle extras) throws RemoteException {
      if (DEBUG_INSTALL)       Slog.d(TAG,"String_Node_Str" + PackageManager.installStatusToString(returnCode,msg));
      installedLatch.countDown();
      unfreezePackage(packageName);
      final int status=PackageManager.installStatusToPublicStatus(returnCode);
switch (status) {
case PackageInstaller.STATUS_SUCCESS:
        mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_SUCCEEDED);
      break;
case PackageInstaller.STATUS_FAILURE_STORAGE:
    mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE);
  break;
default :
mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_FAILED_INTERNAL_ERROR);
break;
}
}
}
;
final MoveInfo move;
if (moveCompleteApp) {
new Thread(){
@Override public void run(){
while (true) {
try {
if (installedLatch.await(1,TimeUnit.SECONDS)) {
  break;
}
}
 catch (InterruptedException ignored) {
}
final long deltaFreeBytes=startFreeBytes - measurePath.getFreeSpace();
final int progress=10 + (int)MathUtils.constrain(((deltaFreeBytes * 80) / sizeBytes),0,80);
mMoveCallbacks.notifyStatusChanged(moveId,progress);
}
}
}
.start();
final String dataAppName=codeFile.getName();
move=new MoveInfo(moveId,currentVolumeUuid,volumeUuid,packageName,dataAppName,appId,seinfo);
}
 else {
move=null;
}
installFlags|=PackageManager.INSTALL_REPLACE_EXISTING;
final Message msg=mHandler.obtainMessage(INIT_COPY);
final OriginInfo origin=OriginInfo.fromExistingFile(codeFile);
msg.obj=new InstallParams(origin,move,installObserver,installFlags,installerPackageName,volumeUuid,null,user,packageAbiOverride,null);
mHandler.sendMessage(msg);
}

Fixed version (ground truth):
private void movePackageInternal(final String packageName,final String volumeUuid,final int moveId) throws PackageManagerException {
  final UserHandle user=new UserHandle(UserHandle.getCallingUserId());
  final StorageManager storage=mContext.getSystemService(StorageManager.class);
  final PackageManager pm=mContext.getPackageManager();
  final boolean currentAsec;
  final String currentVolumeUuid;
  final File codeFile;
  final String installerPackageName;
  final String packageAbiOverride;
  final int appId;
  final String seinfo;
  final String label;
synchronized (mPackages) {
    final PackageParser.Package pkg=mPackages.get(packageName);
    final PackageSetting ps=mSettings.mPackages.get(packageName);
    if (pkg == null || ps == null) {
      throw new PackageManagerException(MOVE_FAILED_DOESNT_EXIST,"String_Node_Str");
    }
    if (pkg.applicationInfo.isSystemApp()) {
      throw new PackageManagerException(MOVE_FAILED_SYSTEM_PACKAGE,"String_Node_Str");
    }
    if (Objects.equals(ps.volumeUuid,volumeUuid)) {
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str" + volumeUuid);
    }
    final File probe=new File(pkg.codePath);
    final File probeOat=new File(probe,"String_Node_Str");
    if (!probe.isDirectory() || !probeOat.isDirectory()) {
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
    if (ps.frozen) {
      throw new PackageManagerException(MOVE_FAILED_OPERATION_PENDING,"String_Node_Str");
    }
    ps.frozen=true;
    currentAsec=pkg.applicationInfo.isForwardLocked() || pkg.applicationInfo.isExternalAsec();
    currentVolumeUuid=ps.volumeUuid;
    codeFile=new File(pkg.codePath);
    installerPackageName=ps.installerPackageName;
    packageAbiOverride=ps.cpuAbiOverrideString;
    appId=UserHandle.getAppId(pkg.applicationInfo.uid);
    seinfo=pkg.applicationInfo.seinfo;
    label=String.valueOf(pm.getApplicationLabel(pkg.applicationInfo));
  }
  final long token=Binder.clearCallingIdentity();
  try {
    killApplication(packageName,appId,"String_Node_Str");
  }
  finally {
    Binder.restoreCallingIdentity(token);
  }
  final Bundle extras=new Bundle();
  extras.putString(Intent.EXTRA_PACKAGE_NAME,packageName);
  extras.putString(Intent.EXTRA_TITLE,label);
  mMoveCallbacks.notifyCreated(moveId,extras);
  int installFlags;
  final boolean moveCompleteApp;
  final File measurePath;
  if (Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL,volumeUuid)) {
    installFlags=INSTALL_INTERNAL;
    moveCompleteApp=!currentAsec;
    measurePath=Environment.getDataAppDirectory(volumeUuid);
  }
 else   if (Objects.equals(StorageManager.UUID_PRIMARY_PHYSICAL,volumeUuid)) {
    installFlags=INSTALL_EXTERNAL;
    moveCompleteApp=false;
    measurePath=storage.getPrimaryPhysicalVolume().getPath();
  }
 else {
    final VolumeInfo volume=storage.findVolumeByUuid(volumeUuid);
    if (volume == null || volume.getType() != VolumeInfo.TYPE_PRIVATE || !volume.isMountedWritable()) {
      unfreezePackage(packageName);
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
    Preconditions.checkState(!currentAsec);
    installFlags=INSTALL_INTERNAL;
    moveCompleteApp=true;
    measurePath=Environment.getDataAppDirectory(volumeUuid);
  }
  final PackageStats stats=new PackageStats(null,-1);
synchronized (mInstaller) {
    if (!getPackageSizeInfoLI(packageName,-1,stats)) {
      unfreezePackage(packageName);
      throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
    }
  }
  if (DEBUG_INSTALL)   Slog.d(TAG,"String_Node_Str" + stats.codeSize + "String_Node_Str"+ stats.dataSize);
  final long startFreeBytes=measurePath.getFreeSpace();
  final long sizeBytes;
  if (moveCompleteApp) {
    sizeBytes=stats.codeSize + stats.dataSize;
  }
 else {
    sizeBytes=stats.codeSize;
  }
  if (sizeBytes > storage.getStorageBytesUntilLow(measurePath)) {
    unfreezePackage(packageName);
    throw new PackageManagerException(MOVE_FAILED_INTERNAL_ERROR,"String_Node_Str");
  }
  mMoveCallbacks.notifyStatusChanged(moveId,10);
  final CountDownLatch installedLatch=new CountDownLatch(1);
  final IPackageInstallObserver2 installObserver=new IPackageInstallObserver2.Stub(){
    @Override public void onUserActionRequired(    Intent intent) throws RemoteException {
      throw new IllegalStateException();
    }
    @Override public void onPackageInstalled(    String basePackageName,    int returnCode,    String msg,    Bundle extras) throws RemoteException {
      if (DEBUG_INSTALL)       Slog.d(TAG,"String_Node_Str" + PackageManager.installStatusToString(returnCode,msg));
      installedLatch.countDown();
      unfreezePackage(packageName);
      final int status=PackageManager.installStatusToPublicStatus(returnCode);
switch (status) {
case PackageInstaller.STATUS_SUCCESS:
        mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_SUCCEEDED);
      break;
case PackageInstaller.STATUS_FAILURE_STORAGE:
    mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE);
  break;
default :
mMoveCallbacks.notifyStatusChanged(moveId,PackageManager.MOVE_FAILED_INTERNAL_ERROR);
break;
}
}
}
;
final MoveInfo move;
if (moveCompleteApp) {
new Thread(){
@Override public void run(){
while (true) {
try {
if (installedLatch.await(1,TimeUnit.SECONDS)) {
  break;
}
}
 catch (InterruptedException ignored) {
}
final long deltaFreeBytes=startFreeBytes - measurePath.getFreeSpace();
final int progress=10 + (int)MathUtils.constrain(((deltaFreeBytes * 80) / sizeBytes),0,80);
mMoveCallbacks.notifyStatusChanged(moveId,progress);
}
}
}
.start();
final String dataAppName=codeFile.getName();
move=new MoveInfo(moveId,currentVolumeUuid,volumeUuid,packageName,dataAppName,appId,seinfo);
}
 else {
move=null;
}
installFlags|=PackageManager.INSTALL_REPLACE_EXISTING;
final Message msg=mHandler.obtainMessage(INIT_COPY);
final OriginInfo origin=OriginInfo.fromExistingFile(codeFile);
msg.obj=new InstallParams(origin,move,installObserver,installFlags,installerPackageName,volumeUuid,null,user,packageAbiOverride,null);
mHandler.sendMessage(msg);
}