public static boolean installPackage(Context context, InputStream in, String packageName) throws IOException { PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); PackageInstaller.SessionParams params = new PackageInstaller.SessionParams( PackageInstaller.SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(packageName); // set params int sessionId = packageInstaller.createSession(params); PackageInstaller.Session session = packageInstaller.openSession(sessionId); OutputStream out = session.openWrite("COSU", 0, -1); 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(createIntentSender(context, sessionId)); return true; }
@Override public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException { boolean success = VAppManagerService.get().uninstallPackage(packageName); if (statusReceiver != null) { final Intent fillIn = new Intent(); fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName); fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE); fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success)); fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1); try { statusReceiver.sendIntent(mContext, 0, fillIn, null, null); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } } }
@Override public void onPackageInstalled(String basePackageName, int returnCode, String msg, Bundle extras) { final Intent fillIn = new Intent(); fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, basePackageName); fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId); fillIn.putExtra(PackageInstaller.EXTRA_STATUS, installStatusToPublicStatus(returnCode)); fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, installStatusToString(returnCode, msg)); fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", returnCode); if (extras != null) { final String existing = extras.getString("android.content.pm.extra.FAILURE_EXISTING_PACKAGE"); if (!TextUtils.isEmpty(existing)) { fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME, existing); } } try { mTarget.sendIntent(mContext, 0, fillIn, null, null); } catch (IntentSender.SendIntentException ignored) { } }
public void testPendingWidget_notRestored_activeInstall() throws Exception { // A widget which is being installed is not removed LauncherAppWidgetInfo item = getInvalidWidgetInfo(); item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID | LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY; // Create an active installer session SessionParams params = new SessionParams(SessionParams.MODE_FULL_INSTALL); params.setAppPackageName(item.providerName.getPackageName()); PackageInstaller installer = mTargetContext.getPackageManager().getPackageInstaller(); mSessionId = installer.createSession(params); setupAndVerifyContents(item, PendingAppWidgetHostView.class, null); // Verify item still exists in db waitUntilLoaderIdle(); mCursor = mResolver.query(LauncherSettings.Favorites.getContentUri(item.id), null, null, null, null, null); assertEquals(1, mCursor.getCount()); // Widget still has an invalid id. mCursor.moveToNext(); assertEquals(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID, mCursor.getInt(mCursor.getColumnIndex(LauncherSettings.Favorites.RESTORED)) & LauncherAppWidgetInfo.FLAG_ID_NOT_VALID); }
@Override public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException { boolean success = VAppManagerService.get().uninstallApp(packageName); if (statusReceiver != null) { final Intent fillIn = new Intent(); fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName); fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE); fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success)); fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1); try { statusReceiver.sendIntent(mContext, 0, fillIn, null, null); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } } }
public PackageInstallerImpl(Context paramContext) { this.mContext = paramContext; this.mPackageInstaller = this.mContext.getPackageManager().getPackageInstaller(); this.mSessionInfoMap = new HashMap(); Iterator localIterator = this.mPackageInstaller.getMySessions().iterator(); while (localIterator.hasNext()) { PackageInstaller.SessionInfo localSessionInfo1 = (PackageInstaller.SessionInfo)localIterator.next(); String str = localSessionInfo1.getAppPackageName(); PackageInstaller.SessionInfo localSessionInfo2 = (PackageInstaller.SessionInfo)this.mSessionInfoMap.put(str, localSessionInfo1); if (localSessionInfo2 != null) { Object[] arrayOfObject = new Object[3]; arrayOfObject[0] = str; arrayOfObject[1] = Integer.valueOf(localSessionInfo2.getSessionId()); arrayOfObject[2] = Integer.valueOf(localSessionInfo1.getSessionId()); FinskyLog.w("Multiple sessions for %s found. Removing %d & keeping %d.", arrayOfObject); } } this.mOpenSessionMap = new HashMap(); }
private static boolean a(Context paramContext, String paramString) { if (Build.VERSION.SDK_INT >= 21) {} for (int i = 1; i != 0; i = 0) { Iterator localIterator = paramContext.getPackageManager().getPackageInstaller().getAllSessions().iterator(); do { if (!localIterator.hasNext()) { break; } } while (!paramString.equals(((PackageInstaller.SessionInfo)localIterator.next()).getAppPackageName())); return true; } PackageManager localPackageManager = paramContext.getPackageManager(); try { boolean bool = localPackageManager.getApplicationInfo(paramString, 8192).enabled; if (bool) { return true; } } catch (PackageManager.NameNotFoundException localNameNotFoundException) {} return false; }
@Override public void onUserActionRequired(Intent intent) { final Intent fillIn = new Intent(); fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId); fillIn.putExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_PENDING_USER_ACTION); fillIn.putExtra(Intent.EXTRA_INTENT, intent); try { mTarget.sendIntent(mContext, 0, fillIn, null, null); } catch (IntentSender.SendIntentException ignored) { } }
public final OutputStream getStream(String paramString1, String paramString2, long paramLong) throws IOException { PackageInstaller.Session localSession = getSession(paramString1); if (localSession == null) { FinskyLog.e("Can't open session for %s", new Object[] { paramString1 }); throw new IOException(); } return new SessionStreamWrapper(localSession.openWrite(paramString2, 0L, paramLong), localSession); }
@Override public void onReceive(Context context, Intent intent) { if (!CosuUtils.ACTION_INSTALL_COMPLETE.equals(intent.getAction())) { return; } int result = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE); String packageName = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME); if (CosuUtils.DEBUG) Log.d(CosuUtils.TAG, "PackageInstallerCallback: result=" + result + " packageName=" + packageName); switch (result) { case PackageInstaller.STATUS_PENDING_USER_ACTION: { // this should not happen in M, but will happen in L and L-MR1 startActivity((Intent) intent.getParcelableExtra(Intent.EXTRA_INTENT)); } break; case PackageInstaller.STATUS_SUCCESS: { mHandler.sendMessage(mHandler.obtainMessage(CosuUtils.MSG_INSTALL_COMPLETE, packageName)); } break; default: { Log.e(CosuUtils.TAG, "Install failed."); finishWithFailure(); return; } } }
@RequiresApi(LOLLIPOP) @Override @NonNull public PackageInstaller getPackageInstaller() { return mBase.getPackageInstaller(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public PackageInstaller getPackageInstaller() { return this.mHostPackageManager.getPackageInstaller(); }
@RequiresApi(LOLLIPOP) public @NonNull PackageInstaller getPackageInstaller() { throw new UnsupportedOperationException("PackageManager.getPackageInstaller() is not yet supported by Project Condom. " + "If it causes trouble, please file an issue on GitHub."); }
/** {@hide} */ public static int installStatusToPublicStatus(int status) { switch (status) { case INSTALL_SUCCEEDED: return PackageInstaller.STATUS_SUCCESS; case INSTALL_FAILED_ALREADY_EXISTS: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_INVALID_APK: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_INVALID_URI: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_INSUFFICIENT_STORAGE: return PackageInstaller.STATUS_FAILURE_STORAGE; case INSTALL_FAILED_DUPLICATE_PACKAGE: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_NO_SHARED_USER: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_UPDATE_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_MISSING_SHARED_LIBRARY: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_REPLACE_COULDNT_DELETE: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_DEXOPT: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_OLDER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_CONFLICTING_PROVIDER: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_NEWER_SDK: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_TEST_ONLY: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_CPU_ABI_INCOMPATIBLE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_MISSING_FEATURE: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_CONTAINER_ERROR: return PackageInstaller.STATUS_FAILURE_STORAGE; case INSTALL_FAILED_INVALID_INSTALL_LOCATION: return PackageInstaller.STATUS_FAILURE_STORAGE; case INSTALL_FAILED_MEDIA_UNAVAILABLE: return PackageInstaller.STATUS_FAILURE_STORAGE; case INSTALL_FAILED_VERIFICATION_TIMEOUT: return PackageInstaller.STATUS_FAILURE_ABORTED; case INSTALL_FAILED_VERIFICATION_FAILURE: return PackageInstaller.STATUS_FAILURE_ABORTED; case INSTALL_FAILED_PACKAGE_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_UID_CHANGED: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_VERSION_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_PERMISSION_MODEL_DOWNGRADE: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_NOT_APK: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_BAD_MANIFEST: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_NO_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_PARSE_FAILED_MANIFEST_EMPTY: return PackageInstaller.STATUS_FAILURE_INVALID; case INSTALL_FAILED_INTERNAL_ERROR: return PackageInstaller.STATUS_FAILURE; case INSTALL_FAILED_USER_RESTRICTED: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_DUPLICATE_PERMISSION: return PackageInstaller.STATUS_FAILURE_CONFLICT; case INSTALL_FAILED_NO_MATCHING_ABIS: return PackageInstaller.STATUS_FAILURE_INCOMPATIBLE; case INSTALL_FAILED_ABORTED: return PackageInstaller.STATUS_FAILURE_ABORTED; default: return PackageInstaller.STATUS_FAILURE; } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @NonNull @Override public PackageInstaller getPackageInstaller() { return mBase.getPackageInstaller(); }
static boolean zzi(Context paramContext, String paramString) { boolean bool1 = true; if (zzq.zzdC(21)) { Iterator localIterator = paramContext.getPackageManager().getPackageInstaller().getAllSessions().iterator(); while (localIterator.hasNext()) { if (paramString.equals(((PackageInstaller.SessionInfo)localIterator.next()).getAppPackageName())) { return bool1; } } } if (zzq.zzdC(18)) { Bundle localBundle = ((UserManager)paramContext.getSystemService("user")).getApplicationRestrictions(paramContext.getPackageName()); if ((localBundle == null) || (!"true".equals(localBundle.getString("restricted_profile")))) {} } while (bool1) { return false; bool1 = false; } PackageManager localPackageManager = paramContext.getPackageManager(); try { boolean bool2 = localPackageManager.getApplicationInfo(paramString, 8192).enabled; return bool2; } catch (PackageManager.NameNotFoundException localNameNotFoundException) {} return false; }
public SessionStreamWrapper(OutputStream paramOutputStream, PackageInstaller.Session paramSession) { super(); this.stream = paramOutputStream; this.session = paramSession; }
@Override public PackageInstaller getPackageInstaller() { return packageManager.getPackageInstaller(); }
@Override public PackageInstaller getPackageInstaller() { return mProxy.getPackageInstaller(); }
@Override public PackageInstaller getPackageInstaller() { notSupported(); return null; }
@NonNull @Override public PackageInstaller getPackageInstaller() { return null; }