private boolean prepare() {
		final Intent intent = getIntent();
		final Uri data = intent.getData();
		if (data == null) return false;
		final String caller = getCallingPackage();
		if (caller == null) {
			Log.w(TAG, "Caller is unknown, fallback to default package installer.");
			fallbackToSystemPackageInstaller("unknown_caller", null);
			return true;
		}
		final ApplicationInfo callerInfo = Apps.of(this).getAppInfo(caller);
		if (SDK_INT >= O && callerInfo != null && ! isCallerQualified(callerInfo)) {	// Null if caller is not in the same user and has no launcher activity
			Log.w(TAG, "Reject installation for unqualified caller: " + caller);
			return false;
		}

		final DevicePolicies policies = new DevicePolicies(this);
		final boolean silent_install = policies.isActiveDeviceOwner()
				|| SDK_INT >= P && policies.isProfileOwner() && policies.getManager().isAffiliatedUser();
		final PackageManager pm = getPackageManager();
		if (SDK_INT >= P && ! pm.canRequestPackageInstalls() && silent_install) try {
			new AppOpsCompat(this).setMode(AppOpsCompat.OP_REQUEST_INSTALL_PACKAGES, Process.myUid(), getPackageName(), MODE_ALLOWED);
		} catch (final RuntimeException e) {
			Analytics.$().logAndReport(TAG, "Error granting permission REQUEST_INSTALL_PACKAGES", e);
		}

		@SuppressLint("InlinedApi") final AppInstallInfo install = this.mInstallInfo
				= new AppInstallInfo(getApplicationContext(), caller, callerInfo != null ? callerInfo.uid : Process.INVALID_UID);
		if (SCHEME_PACKAGE.equals(data.getScheme())) {
			final String cloningAppId = data.getSchemeSpecificPart();
			install.setMode(CLONE);
			install.setAppId(cloningAppId);
			install.setAppLabel(Apps.of(this).getAppName(cloningAppId));
		} else try {   // InputStream must be opened here synchronously, otherwise "SecurityException: Permission Denial".
			final InputStream input = getContentResolver().openInputStream(data);
			if (input != null) ApkAnalyzer.analyzeAsync(this, input, info -> {
				if (info != null) {
					final ApplicationInfo app = info.applicationInfo; final String appId = info.packageName;
					install.setAppId(appId);
					install.setVersionName(info.versionName);
					install.setAppLabel(app.loadLabel(getPackageManager())); // loadLabel() is overridden in ApplicationInfoEx
					install.setTargetSdkVersion(app.targetSdkVersion);
					install.setRequestedLegacyExternalStorage(AppInstallerUtils.hasRequestedLegacyExternalStorage(app));
					if (info.splitNames != null) {
						install.setMode(INHERIT);
						install.setDetails(info.splitNames[0]);
						AppInstallationNotifier.cancel(this, mSessionId);   // Cancel the notification of previous session

						performInstall(data, appId);
					} else try {
						final ApplicationInfo current = getPackageManager().getApplicationInfo(appId, MATCH_UNINSTALLED_PACKAGES);
						install.setMode((current.flags & ApplicationInfo.FLAG_INSTALLED) != 0 ? UPDATE : INSTALL);
					} catch (final PackageManager.NameNotFoundException ignored) {}
				}

				install.setDetails(AppInstallationNotifier.onPackageInfoReady(this, mSessionId,
						install, Apps.of(this).getPackageInfo(install.getAppId(), MATCH_UNINSTALLED_PACKAGES)));

				AppInstallerStatusReceiver.createCallback(this, install, mSessionId);  // Sync AppInstallInfo by updating PendingIntent

				getPackageManager().getPackageInstaller().updateSessionAppLabel(mSessionId, install.getAppLabel());
				return Unit.INSTANCE;
			});
		} catch (final IOException e) { Log.w(TAG, "Error opening " + data, e); }

		if (! silent_install) {     // PackageInstaller requires confirmation, thus no need for pre-confirmation on our side.
			performInstall(data, null);
			return true;
		}

		if (ContentResolver.SCHEME_FILE.equals(data.getScheme())) {
			final String path = data.getPath();
			if (path == null) {
				Log.w(TAG, "Invalid file URI: " + data);
				return false;
			}
			final File file = new File(path);
			if (! file.exists()) {
				Log.w(TAG, "File not found: " + file);
				return false;
			}
		}

		if (caller.equals(getPackageName()) || requireNonNull(PreferenceManager.getDefaultSharedPreferences(this)
				.getStringSet(PREF_KEY_DIRECT_INSTALL_ALLOWED_CALLERS, Collections.emptySet())).contains(caller)) {
			performInstall(data, null);	// Whitelisted caller to perform installation without confirmation
			return true;
		}
		final String message = getString(install.getMode() == CLONE ? R.string.confirm_cloning : install.getMode() == UPDATE
				? R.string.confirm_updating : R.string.confirm_installing, install.getCallerLabel(), install.getAppLabel());
		final Dialogs.Builder dialog = Dialogs.buildAlert(this, null, message);
		final View view = View.inflate(dialog.getContext()/* For consistent styling */, R.layout.dialog_checkbox, null);
		final CheckBox checkbox = view.findViewById(R.id.checkbox);
		checkbox.setText(getString(R.string.dialog_install_checkbox_always_allow));
		dialog.withCancelButton().withOkButton(() -> {
			if (checkbox.isChecked()) addAlwaysAllowedCallerPackage(install.getCaller());
			performInstall(data, null);
		}).setOnCancelListener(d -> finish()).setView(view).setCancelable(false).show();
		return true;
	}
App installer with following capabilities:
<ul>
<li> Install APK from Mainland into Island, and vice versa.
<li> Install app without user consent
</ul>
Created by Oasis on 2018-11-12.
installer/src/main/java/com/oasisfeng/island/installer/AppInstallerActivity.java