@Override public void onProgressChanged(int sessionId, float progress) { SessionInfo session = mInstaller.getSessionInfo(sessionId); if (session != null) { mPendingReplays.put(sessionId, session); replayUpdates(null); } }
protected void installPackage(String packageLocation) throws Exception { PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL); int sessionId = mPackageInstaller.createSession(params); mSession = mPackageInstaller.openSession(sessionId); File file = new File(packageLocation); InputStream in = new FileInputStream(file); OutputStream out = mSession.openWrite("SilentPackageInstallerTest", 0, file.length()); byte[] buffer = new byte[65536]; int c; while ((c = in.read(buffer)) != -1) { out.write(buffer, 0, c); } mSession.fsync(out); out.close(); mSession.commit(getCommitCallback(sessionId)); mSession.close(); }
private void pushSessionBadgeToLauncher(int sessionId) { SessionInfo session = mInstaller.getSessionInfo(sessionId); if (session != null) { addSessionInfoToCahce(session, UserHandleCompat.myUserHandle()); if (session.getAppPackageName() != null) { mPendingBadgeUpdates.add(session.getAppPackageName()); } mPendingReplays.put(sessionId, session); replayUpdates(null); } }
@Override public HashSet<String> updateAndGetActiveSessionCache() { HashSet<String> activePackages = new HashSet<String>(); UserHandleCompat user = UserHandleCompat.myUserHandle(); for (SessionInfo info : mInstaller.getAllSessions()) { addSessionInfoToCahce(info, user); if (info.getAppPackageName() != null) { activePackages.add(info.getAppPackageName()); } } return activePackages; }
@Override public void onFinished(int sessionId, boolean success) { mPendingReplays.remove(sessionId); SessionInfo session = mInstaller.getSessionInfo(sessionId); if ((session != null) && (session.getAppPackageName() != null)) { mPendingBadgeUpdates.remove(session.getAppPackageName()); // Replay all updates with a one time update for this installed package. No // need to store this record for future updates, as the app list will get // refreshed on resume. replayUpdates( new PackageInstallInfo( session.getAppPackageName(), success ? STATUS_INSTALLED : STATUS_FAILED, 0)); } }
protected boolean tryUninstallPackage() throws Exception { assertTrue(isPackageInstalled(TEST_APP_PKG)); synchronized (mPackageInstallerTimeoutLock) { mCallbackReceived = false; mCallbackStatus = PACKAGE_INSTALLER_STATUS_UNDEFINED; } mPackageInstaller.uninstall(TEST_APP_PKG, getCommitCallback(0)); synchronized (mPackageInstallerTimeoutLock) { try { mPackageInstallerTimeoutLock.wait(PACKAGE_INSTALLER_TIMEOUT_MS); } catch (InterruptedException e) { } assertTrue(mCallbackReceived); return mCallbackStatus == PackageInstaller.STATUS_SUCCESS; } }
PackageInstallerCompatVL(Context context) { mInstaller = context.getPackageManager().getPackageInstaller(); LauncherAppState.setApplicationContext(context.getApplicationContext()); mCache = LauncherAppState.getInstance().getIconCache(); mWorker = new Handler(); mResumed = false; mBound = false; mInstaller.registerSessionCallback(mCallback, mWorker); // On start, send updates for all active sessions mWorker.post( new Runnable() { @Override public void run() { for (SessionInfo info : mInstaller.getAllSessions()) { mPendingReplays.append(info.getSessionId(), info); } } }); }
@Override public void onStop() { mInstaller.unregisterSessionCallback(mCallback); }