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

Commit 8e9c4fef authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by android-build-merger
Browse files

Merge "Improve untrusted sources UX for app side-loading" am: c23d8029

am: e3ebb33a

* commit 'e3ebb33a':
  Improve untrusted sources UX for app side-loading
parents f72df377 e3ebb33a
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -64,6 +64,8 @@ import java.io.File;
public class PackageInstallerActivity extends Activity implements OnCancelListener, OnClickListener {
    private static final String TAG = "PackageInstaller";

    private static final int REQUEST_ENABLE_UNKNOWN_SOURCES = 1;

    private int mSessionId = -1;
    private Uri mPackageURI;
    private Uri mOriginatingURI;
@@ -222,7 +224,7 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
                    .setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            Log.i(TAG, "Launching settings");
                            launchSettingsAppAndFinish();
                            launchSecuritySettings();
                        }
                    })
                    .setOnCancelListener(this)
@@ -327,13 +329,22 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen
       return null;
   }

    private void launchSettingsAppAndFinish() {
        // Create an intent to launch SettingsTwo activity
    private void launchSecuritySettings() {
        Intent launchSettingsIntent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
        launchSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(launchSettingsIntent);
        startActivityForResult(launchSettingsIntent, REQUEST_ENABLE_UNKNOWN_SOURCES);
    }

    @Override
    public void onActivityResult(int request, int result, Intent data) {
        // If the settings app approved the install we are good to go regardless
        // whether the untrusted sources setting is on. This allows partners to
        // implement a "allow untrusted source once" feature.
        if (request == REQUEST_ENABLE_UNKNOWN_SOURCES && result == RESULT_OK) {
            initiateInstall();
        } else {
            finish();
        }
    }

    private boolean isInstallRequestFromUnknownSource(Intent intent) {
        String callerPackage = getCallingPackage();