Skip to content

Commit

Permalink
make sure PackageInstaller UI returns a result
Browse files Browse the repository at this point in the history
  • Loading branch information
muhomorr authored and sfX-bot committed Sep 18, 2024
1 parent f0142b5 commit 01dfae8
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public class PackageInstallerActivity extends AlertActivity {

// Would the mOk button be enabled if this activity would be resumed
private boolean mEnableOk = false;
private boolean mPermissionResultWasSet;
private boolean mAllowNextOnPause;

private void startInstallConfirm() {
View viewToEnable;
Expand Down Expand Up @@ -298,6 +300,7 @@ void setPmResult(int pmResult) {
protected void onCreate(Bundle icicle) {
if (mLocalLOGV) Log.i(TAG, "creating for user " + getUserId());
getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
getWindow().setCloseOnTouchOutside(false);

super.onCreate(null);

Expand Down Expand Up @@ -390,6 +393,24 @@ protected void onPause() {
// Don't allow the install button to be clicked as there might be overlays
mOk.setEnabled(false);
}
// sometimes this activity becomes hidden after onPause(),
// and the user is unable to bring it back
if (!mPermissionResultWasSet && mSessionId != -1) {
if (mAllowNextOnPause) {
mAllowNextOnPause = false;
} else {
if (!isFinishing()) {
finish();
}
}
}
}

// handles startActivity() calls too
@Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
mAllowNextOnPause = true;
super.startActivityForResult(intent, requestCode, options);
}

@Override
Expand All @@ -405,6 +426,9 @@ protected void onDestroy() {
while (!mActiveUnknownSourcesListeners.isEmpty()) {
unregister(mActiveUnknownSourcesListeners.get(0));
}
if (!mPermissionResultWasSet) {
mInstaller.setPermissionsResult(mSessionId, false);
}
}

private void bindUi() {
Expand All @@ -416,6 +440,7 @@ private void bindUi() {
if (mOk.isEnabled()) {
if (mSessionId != -1) {
mInstaller.setPermissionsResult(mSessionId, true);
mPermissionResultWasSet = true;
finish();
} else {
startInstall();
Expand All @@ -428,6 +453,7 @@ private void bindUi() {
setResult(RESULT_CANCELED);
if (mSessionId != -1) {
mInstaller.setPermissionsResult(mSessionId, false);
mPermissionResultWasSet = true;
}
finish();
}, null);
Expand Down Expand Up @@ -599,6 +625,7 @@ private boolean processPackageUri(final Uri packageUri) {
public void onBackPressed() {
if (mSessionId != -1) {
mInstaller.setPermissionsResult(mSessionId, false);
mPermissionResultWasSet = true;
}
super.onBackPressed();
}
Expand Down

0 comments on commit 01dfae8

Please sign in to comment.