Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 571ffc5b authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Reattempt install after Op change

Once Op status for install is changed, bring Pia to foreground and attempt to install the app again. Op status is verified once again. If op is allowed, proceed with the install, else abort it.

Bug: 182205982
Test: builds successfully
Test: No CTS Tests. Flag to use new app is turned off by default

Change-Id: I600cd1fbe004eb9642e49b746d08ffd4ac6ea4fd
parent 7e99d654
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -641,6 +641,32 @@ public class InstallRepository {
        return true;
        return true;
    }
    }


    /**
     * Once the user returns from Settings related to installing from unknown sources, reattempt
     * the installation if the source app is granted permission to install other apps. Abort the
     * installation if the source app is still not granted installing permission.
     * @return {@link InstallUserActionRequired} containing data required to ask user confirmation
     * to proceed with the install.
     * {@link InstallAborted} if there was an error while recomputing, or the source still
     * doesn't have install permission.
     */
    public InstallStage reattemptInstall() {
        InstallStage unknownSourceStage = handleUnknownSources(mAppOpRequestInfo);
        if (unknownSourceStage.getStageCode() == InstallStage.STAGE_READY) {
            // Source app now has appOp granted.
            return generateConfirmationSnippet();
        } else if (unknownSourceStage.getStageCode() == InstallStage.STAGE_ABORTED) {
            // There was some error in determining the AppOp code for the source app.
            // Abort installation
            return unknownSourceStage;
        } else {
            // AppOpsManager again returned a MODE_ERRORED or MODE_DEFAULT op code. This was
            // unexpected while reattempting the install. Let's abort it.
            Log.e(TAG, "AppOp still not granted.");
            return new InstallAborted.Builder(ABORT_REASON_INTERNAL_ERROR).build();
        }
    }

    private InstallStage handleUnknownSources(AppOpRequestInfo requestInfo) {
    private InstallStage handleUnknownSources(AppOpRequestInfo requestInfo) {
        if (requestInfo.getCallingPackage() == null) {
        if (requestInfo.getCallingPackage() == null) {
            Log.i(TAG, "No source found for package " + mNewPackageInfo.packageName);
            Log.i(TAG, "No source found for package " + mNewPackageInfo.packageName);
+14 −6
Original line number Original line Diff line number Diff line
@@ -253,6 +253,16 @@ public class InstallLaunch extends FragmentActivity implements InstallActionList
        mAppOpsManager.stopWatchingMode(listener);
        mAppOpsManager.stopWatchingMode(listener);
    }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_TRUST_EXTERNAL_SOURCE) {
            mInstallViewModel.reattemptInstall();
        } else {
            setResult(Activity.RESULT_CANCELED, true);
        }
    }

    @Override
    @Override
    protected void onDestroy() {
    protected void onDestroy() {
        super.onDestroy();
        super.onDestroy();
@@ -281,12 +291,10 @@ public class InstallLaunch extends FragmentActivity implements InstallActionList
            }
            }
            new Handler(Looper.getMainLooper()).postDelayed(() -> {
            new Handler(Looper.getMainLooper()).postDelayed(() -> {
                if (!isDestroyed()) {
                if (!isDestroyed()) {
                    startActivity(getIntent());
                    // Bring Pia to the foreground. FLAG_ACTIVITY_REORDER_TO_FRONT will reuse the
                    // The start flag (FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP) doesn't
                    // paused instance, so we don't unnecessarily create a new instance of Pia.
                    // work for the multiple user case, i.e. the caller task user and started
                    startActivity(getIntent()
                    // Activity user are not the same. To avoid having multiple PIAs in the task,
                        .addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
                    // finish the current PackageInstallerActivity
                    finish();
                }
                }
            }, 500);
            }, 500);
        }
        }
+5 −0
Original line number Original line Diff line number Diff line
@@ -81,4 +81,9 @@ public class InstallViewModel extends AndroidViewModel {
    public void cleanupInstall() {
    public void cleanupInstall() {
        mRepository.cleanupInstall();
        mRepository.cleanupInstall();
    }
    }

    public void reattemptInstall() {
        InstallStage stage = mRepository.reattemptInstall();
        mCurrentInstallStage.setValue(stage);
    }
}
}