Delete staged APK whenever DeleteStagedFileOnResult finishes.
The DeleteStagedFileOnResult activity commonly doesn't receive a result, because the user either immediately opens the newly installed app or navigates away. When the task containing this activity is either trimmed by the system or explicitly removed by the user, the activity will be finished. We can take this opportunity to delete the staged APK. There is still no guarantee that the staged APK will be deleted; for example, this activity may already have been destroyed (temporarily) in low memory situations while the user was completing the install. Bug: 183940755 Test: Manual, observing when staged APKs are deleted via adb shell ls. Change-Id: Iaabecffe8131333b2eefee1edec8b4641868b2e7
This commit is contained in:
@@ -42,10 +42,17 @@ public class DeleteStagedFileOnResult extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
File sourceFile = new File(getIntent().getData().getPath());
|
||||
sourceFile.delete();
|
||||
|
||||
setResult(resultCode, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (isFinishing()) {
|
||||
File sourceFile = new File(getIntent().getData().getPath());
|
||||
new Thread(sourceFile::delete).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user