From 3ce5984c09403c0ef09f0826f5fe18520192bec2 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Tue, 12 Jan 2016 17:01:25 -0800 Subject: Improve untrusted sources UX for app side-loading When an app is side-loaded we request the user to enable installs from untrusted sources by sending them to setting. After the user enables untrusted sources they have to start the install again instead of continuing from where they were interrupted by the settings UI. With this change the settings activity is started for a result by the package installer, so if the settings app wants to support non-interruptive side- loading flow it can check whether the calling package is the instaler and if true finish itself returning RESULT_OK. Change-Id: I893f48ecfa0ccece8623e0393a59da307ed4aa5b --- .../packageinstaller/PackageInstallerActivity.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/com/android/packageinstaller/PackageInstallerActivity.java') diff --git a/src/com/android/packageinstaller/PackageInstallerActivity.java b/src/com/android/packageinstaller/PackageInstallerActivity.java index 868872a9..3693470b 100644 --- a/src/com/android/packageinstaller/PackageInstallerActivity.java +++ b/src/com/android/packageinstaller/PackageInstallerActivity.java @@ -68,6 +68,8 @@ import java.util.List; 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; @@ -245,7 +247,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) @@ -350,12 +352,19 @@ 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); - finish(); + startActivityForResult(launchSettingsIntent, REQUEST_ENABLE_UNKNOWN_SOURCES); + } + + @Override + public void onActivityResult(int request, int result, Intent data) { + if (request == REQUEST_ENABLE_UNKNOWN_SOURCES + && result == RESULT_OK && isUnknownSourcesEnabled()) { + initiateInstall(); + } else { + finish(); + } } private boolean isInstallRequestFromUnknownSource(Intent intent) { -- cgit v1.2.3