Java Code Examples for android.content.pm.PackageInstaller#SessionParams
The following examples show how to use
android.content.pm.PackageInstaller#SessionParams .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DummyActivity.java From Shelter with Do What The F*ck You Want To Public License | 6 votes |
private void actionInstallPackageQ(Uri uri) throws IOException { PackageInstaller pi = getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); int sessionId = pi.createSession(params); // Show the progress dialog first pi.registerSessionCallback(new InstallationProgressListener(this, pi, sessionId)); PackageInstaller.Session session = pi.openSession(sessionId); doInstallPackageQ(uri, session, () -> { // We have finished piping the streams, show the progress as 10% session.setStagingProgress(0.1f); // Commit the session Intent intent = new Intent(this, DummyActivity.class); intent.setAction(PACKAGEINSTALLER_CALLBACK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); session.commit(pendingIntent.getIntentSender()); }); }
Example 2
Source File: InstallerPrivilegedSession.java From YalpStore with GNU General Public License v2.0 | 6 votes |
@Override protected void install(App app) { registerReceiver(); PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); sessionParams.setAppPackageName(app.getPackageName()); sessionParams.setAppLabel(app.getDisplayName()); PackageInstaller.Session session = null; try { int sessionId = packageInstaller.createSession(sessionParams); session = packageInstaller.openSession(sessionId); for (File file: Paths.getApkAndSplits(context, app.getPackageName(), app.getVersionCode())) { writeFileToSession(file, session); } session.commit(getIntentSender(sessionId)); } catch (IOException e) { fail(e, app.getPackageName()); } finally { com.github.yeriomin.yalpstore.Util.closeSilently(session); } }
Example 3
Source File: VersionFixer.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); final byte[] buffer = new byte[65536]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } session.fsync(out); in.close(); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 4
Source File: VersionFixer.java From xDrip with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, byte[] buffer, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); out.write(buffer, 0, buffer.length); session.fsync(out); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 5
Source File: VersionFixer.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); final byte[] buffer = new byte[65536]; int bytes_read; while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } session.fsync(out); in.close(); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 6
Source File: VersionFixer.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
private static boolean installPackage(Context context, byte[] buffer, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("COSU", 0, -1); out.write(buffer, 0, buffer.length); session.fsync(out); out.close(); session.commit(createIntentSender(context, sessionId)); return true; }
Example 7
Source File: PackageInstallationUtils.java From android-testdpc with Apache License 2.0 | 6 votes |
public static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { final PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); final PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); // set params final int sessionId = packageInstaller.createSession(params); final PackageInstaller.Session session = packageInstaller.openSession(sessionId); final OutputStream out = session.openWrite("TestDPC", 0, -1); final byte[] buffer = new byte[65536]; int c; while ((c = in.read(buffer)) != -1) { out.write(buffer, 0, c); } session.fsync(out); in.close(); out.close(); session.commit(createInstallIntentSender(context, sessionId)); return true; }
Example 8
Source File: MainActivity.java From splitapkinstall with Apache License 2.0 | 5 votes |
private int doCreateSession(PackageInstaller.SessionParams params) throws RemoteException { int sessionId = 0 ; try { if(params == null) { Log.d(TAG, "doCreateSession: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!param is null"); } sessionId = packageInstaller.createSession(params); } catch (IOException e) { e.printStackTrace(); } return sessionId; }
Example 9
Source File: MainActivity.java From splitapkinstall with Apache License 2.0 | 5 votes |
private InstallParams makeInstallParams(long totalSize ) { final PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); final InstallParams params = new InstallParams(); params.sessionParams = sessionParams; String opt; sessionParams.setSize(totalSize); return params; }
Example 10
Source File: InstallActivity.java From XAPKInstaller with Apache License 2.0 | 5 votes |
@TargetApi(21) private PackageInstaller.Session initSession() throws IOException { PackageInstaller.Session session = null; PackageInstaller packageInstaller = getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); int sessionId = 0; sessionId = packageInstaller.createSession(params); session = packageInstaller.openSession(sessionId); return session; }
Example 11
Source File: RootlessSAIPackageInstaller.java From SAI with GNU General Public License v3.0 | 5 votes |
@SuppressLint("DefaultLocale") @Override protected void installApkFiles(ApkSource aApkSource) { cleanOldSessions(); PackageInstaller.Session session = null; try (ApkSource apkSource = aApkSource) { PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); sessionParams.setInstallLocation(PreferencesHelper.getInstance(getContext()).getInstallLocation()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) sessionParams.setInstallReason(PackageManager.INSTALL_REASON_USER); int sessionID = mPackageInstaller.createSession(sessionParams); mSessionsMap.put(sessionID, getOngoingInstallation().getId()); session = mPackageInstaller.openSession(sessionID); int currentApkFile = 0; while (apkSource.nextApk()) { try (InputStream inputStream = apkSource.openApkInputStream(); OutputStream outputStream = session.openWrite(String.format("%d.apk", currentApkFile++), 0, apkSource.getApkLength())) { IOUtils.copyStream(inputStream, outputStream); session.fsync(outputStream); } } Intent callbackIntent = new Intent(getContext(), RootlessSAIPIService.class); PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, callbackIntent, 0); session.commit(pendingIntent.getIntentSender()); } catch (Exception e) { Log.w(TAG, e); dispatchCurrentSessionUpdate(InstallationStatus.INSTALLATION_FAILED, getContext().getString(R.string.installer_error_rootless, Utils.throwableToString(e))); installationCompleted(); } finally { if (session != null) session.close(); } }
Example 12
Source File: RootlessSaiPackageInstaller.java From SAI with GNU General Public License v3.0 | 4 votes |
private void install(String sessionId, SaiPiSessionParams params) { PackageInstaller.Session session = null; String appTempName = null; try (ApkSource apkSource = params.apkSource()) { appTempName = apkSource.getAppName(); if (appTempName != null) mSessionIdToAppTempName.put(sessionId, appTempName); setSessionState(sessionId, new SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLING).appTempName(appTempName).build()); PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); sessionParams.setInstallLocation(PreferencesHelper.getInstance(getContext()).getInstallLocation()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) sessionParams.setInstallReason(PackageManager.INSTALL_REASON_USER); int androidSessionId = mPackageInstaller.createSession(sessionParams); mAndroidPiSessionIdToSaiPiSessionId.put(androidSessionId, sessionId); session = mPackageInstaller.openSession(androidSessionId); int currentApkFile = 0; while (apkSource.nextApk()) { try (InputStream inputStream = apkSource.openApkInputStream(); OutputStream outputStream = session.openWrite(String.format("%d.apk", currentApkFile++), 0, apkSource.getApkLength())) { IOUtils.copyStream(inputStream, outputStream); session.fsync(outputStream); } } Intent callbackIntent = new Intent(RootlessSaiPiBroadcastReceiver.ACTION_DELIVER_PI_EVENT); PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, callbackIntent, 0); session.commit(pendingIntent.getIntentSender()); } catch (Exception e) { Log.w(TAG, e); if (session != null) session.abandon(); setSessionState(sessionId, new SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLATION_FAILED).appTempName(appTempName).error(e.getLocalizedMessage(), Utils.throwableToString(e)).build()); } finally { if (session != null) session.close(); } }