Delete orphaned staging directories for staged session on reboot

Bug: 173132101
Test: manually created folders in /data/app-staging and observed they were deleted on reboot
Change-Id: If840f35245c2d049401d0d2f6539fe8c4625151e
Merged-In: If840f35245c2d049401d0d2f6539fe8c4625151e
(cherry picked from commit bfbf9608015ba6ff740639625b9a3ea26db60b76)
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index 6a47c4c..a013f05 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -287,6 +287,10 @@
         final ArraySet<File> unclaimedStages = newArraySet(
                 stagingDir.listFiles(sStageFilter));
 
+        // We also need to clean up orphaned staging directory for staged sessions
+        final File stagedSessionStagingDir = Environment.getDataStagingDirectory(volumeUuid);
+        unclaimedStages.addAll(newArraySet(stagedSessionStagingDir.listFiles()));
+
         // Ignore stages claimed by active sessions
         for (int i = 0; i < mSessions.size(); i++) {
             final PackageInstallerSession session = mSessions.valueAt(i);