Fix re-installation via package uri-s
It is allowed to install a package via a "package" URI. This means that if a package with the same name is already installed (for any user), please (re-)install it for the current user. This was broken as mPackageURI.getPath() does not work for such package URIs. This call is only needed when we need to show UI, but for package URIs we don't even new UI, hence we can move it for the "content" path. Test: atest CtsPackageInstallTestCases Bug: 117768093 Change-Id: I58d3abde22ae0a77aabe5068680fd0148d799776
This commit is contained in:
@@ -83,28 +83,6 @@ public class InstallInstalling extends AlertActivity {
|
||||
ApplicationInfo appInfo = getIntent()
|
||||
.getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO);
|
||||
mPackageURI = getIntent().getData();
|
||||
final File sourceFile = new File(mPackageURI.getPath());
|
||||
PackageUtil.AppSnippet as = PackageUtil.getAppSnippet(this, appInfo, sourceFile);
|
||||
|
||||
mAlert.setIcon(as.icon);
|
||||
mAlert.setTitle(as.label);
|
||||
mAlert.setView(R.layout.install_content_view);
|
||||
mAlert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
|
||||
(ignored, ignored2) -> {
|
||||
if (mInstallingTask != null) {
|
||||
mInstallingTask.cancel(true);
|
||||
}
|
||||
|
||||
if (mSessionId > 0) {
|
||||
getPackageManager().getPackageInstaller().abandonSession(mSessionId);
|
||||
mSessionId = 0;
|
||||
}
|
||||
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}, null);
|
||||
setupAlert();
|
||||
requireViewById(R.id.installing).setVisibility(View.VISIBLE);
|
||||
|
||||
if ("package".equals(mPackageURI.getScheme())) {
|
||||
try {
|
||||
@@ -114,6 +92,29 @@ public class InstallInstalling extends AlertActivity {
|
||||
launchFailure(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, null);
|
||||
}
|
||||
} else {
|
||||
final File sourceFile = new File(mPackageURI.getPath());
|
||||
PackageUtil.AppSnippet as = PackageUtil.getAppSnippet(this, appInfo, sourceFile);
|
||||
|
||||
mAlert.setIcon(as.icon);
|
||||
mAlert.setTitle(as.label);
|
||||
mAlert.setView(R.layout.install_content_view);
|
||||
mAlert.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
|
||||
(ignored, ignored2) -> {
|
||||
if (mInstallingTask != null) {
|
||||
mInstallingTask.cancel(true);
|
||||
}
|
||||
|
||||
if (mSessionId > 0) {
|
||||
getPackageManager().getPackageInstaller().abandonSession(mSessionId);
|
||||
mSessionId = 0;
|
||||
}
|
||||
|
||||
setResult(RESULT_CANCELED);
|
||||
finish();
|
||||
}, null);
|
||||
setupAlert();
|
||||
requireViewById(R.id.installing).setVisibility(View.VISIBLE);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mSessionId = savedInstanceState.getInt(SESSION_ID);
|
||||
mInstallId = savedInstanceState.getInt(INSTALL_ID);
|
||||
|
||||
Reference in New Issue
Block a user