android.content.pm.PackageInstaller Java Examples
The following examples show how to use
android.content.pm.PackageInstaller.
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: InstallerPrivilegedSession.java From YalpStore with GNU General Public License v2.0 | 6 votes |
private void writeFileToSession(File file, PackageInstaller.Session session) throws IOException { InputStream in = context.getContentResolver().openInputStream(FileProvider.getUriForFile( context, BuildConfig.APPLICATION_ID + ".fileprovider", file )); OutputStream out = session.openWrite(file.getName(), 0, file.length()); try { int c; byte[] buffer = new byte[65536]; while ((c = in.read(buffer)) != -1) { out.write(buffer, 0, c); } session.fsync(out); } finally { com.github.yeriomin.yalpstore.Util.closeSilently(in); com.github.yeriomin.yalpstore.Util.closeSilently(out); } }
Example #2
Source File: DummyActivity.java From Shelter with Do What The F*ck You Want To Public License | 6 votes |
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent.getAction().equals(PACKAGEINSTALLER_CALLBACK)) { int status = intent.getExtras().getInt(PackageInstaller.EXTRA_STATUS); switch (status) { case PackageInstaller.STATUS_PENDING_USER_ACTION: startActivity((Intent) intent.getExtras().get(Intent.EXTRA_INTENT)); break; case PackageInstaller.STATUS_SUCCESS: appInstallFinished(Activity.RESULT_OK); break; default: appInstallFinished(Activity.RESULT_CANCELED); break; } } }
Example #3
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 #4
Source File: RootlessSaiPiBroadcastReceiver.java From SAI with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999); switch (status) { case PackageInstaller.STATUS_PENDING_USER_ACTION: Log.d(TAG, "Requesting user confirmation for installation"); dispatchOnConfirmationPending(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)); Intent confirmationIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT); ConfirmationIntentWrapperActivity2.start(context, intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), confirmationIntent); break; case PackageInstaller.STATUS_SUCCESS: Log.d(TAG, "Installation succeed"); dispatchOnInstallationSucceeded(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)); break; default: Log.d(TAG, "Installation failed"); dispatchOnInstallationFailed(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), parseError(intent), getRawError(intent), null); break; } }
Example #5
Source File: RootlessSAIPIService.java From SAI with GNU General Public License v3.0 | 6 votes |
@Override public int onStartCommand(Intent intent, int flags, int startId) { int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999); switch (status) { case PackageInstaller.STATUS_PENDING_USER_ACTION: Log.d(TAG, "Requesting user confirmation for installation"); sendStatusChangeBroadcast(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), STATUS_CONFIRMATION_PENDING, intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)); Intent confirmationIntent = intent.getParcelableExtra(Intent.EXTRA_INTENT); ConfirmationIntentWrapperActivity.start(this, intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), confirmationIntent); break; case PackageInstaller.STATUS_SUCCESS: Log.d(TAG, "Installation succeed"); sendStatusChangeBroadcast(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), STATUS_SUCCESS, intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)); break; default: Log.d(TAG, "Installation failed"); sendErrorBroadcast(intent.getIntExtra(PackageInstaller.EXTRA_SESSION_ID, -1), getErrorString(status, intent.getStringExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME))); break; } stopSelf(); return START_NOT_STICKY; }
Example #6
Source File: RootlessSaiPiBroadcastReceiver.java From SAI with GNU General Public License v3.0 | 6 votes |
private String parseError(Intent intent) { int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, -999); String otherPackage = intent.getStringExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME); String error = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE); int errorCode = intent.getIntExtra(ANDROID_PM_EXTRA_LEGACY_STATUS, AndroidPackageInstallerError.UNKNOWN.getLegacyErrorCode()); if (status == STATUS_BAD_ROM) { return mContext.getString(R.string.installer_error_lidl_rom); } AndroidPackageInstallerError androidPackageInstallerError = getAndroidPmError(errorCode, error); if (androidPackageInstallerError != AndroidPackageInstallerError.UNKNOWN) { return androidPackageInstallerError.getDescription(mContext); } return getSimplifiedErrorDescription(status, otherPackage); }
Example #7
Source File: VPackageInstallerService.java From container with GNU General Public License v3.0 | 6 votes |
@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(); } } }
Example #8
Source File: VPackageInstallerService.java From container with GNU General Public License v3.0 | 6 votes |
@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) { } }
Example #9
Source File: PackageInstallerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void onPackageDeleted(String basePackageName, int returnCode, String msg) { if (PackageManager.DELETE_SUCCEEDED == returnCode && mNotification != null) { NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(basePackageName, SystemMessage.NOTE_PACKAGE_STATE, mNotification); } final Intent fillIn = new Intent(); fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, mPackageName); fillIn.putExtra(PackageInstaller.EXTRA_STATUS, PackageManager.deleteStatusToPublicStatus(returnCode)); fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageManager.deleteStatusToString(returnCode, msg)); fillIn.putExtra(PackageInstaller.EXTRA_LEGACY_STATUS, returnCode); try { mTarget.sendIntent(mContext, 0, fillIn, null, null); } catch (SendIntentException ignored) { } }
Example #10
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 #11
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 #12
Source File: PackageManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private int doRemoveSplit(int sessionId, String splitName, boolean logSuccess) throws RemoteException { final PrintWriter pw = getOutPrintWriter(); PackageInstaller.Session session = null; try { session = new PackageInstaller.Session( mInterface.getPackageInstaller().openSession(sessionId)); session.removeSplit(splitName); if (logSuccess) { pw.println("Success"); } return 0; } catch (IOException e) { pw.println("Error: failed to remove split; " + e.getMessage()); return 1; } finally { IoUtils.closeQuietly(session); } }
Example #13
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 #14
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 #15
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 #16
Source File: MainActivity.java From splitapkinstall with Apache License 2.0 | 6 votes |
private int doCommitSession(int sessionId, boolean logSuccess) throws RemoteException { PackageInstaller.Session session = null; try { try { session = packageInstaller.openSession(sessionId); } catch (IOException e) { e.printStackTrace(); } Intent callbackIntent = new Intent(getApplicationContext(), APKInstallService.class); PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), 0, callbackIntent, 0); session.commit(pendingIntent.getIntentSender()); session.close(); System.out.println("install request sent"); Log.d(TAG, "doCommitSession: " + packageInstaller.getMySessions()); Log.d(TAG, "doCommitSession: after session commit "); return 1; } finally { session.close(); } }
Example #17
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 #18
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 #19
Source File: PackageManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private int doAbandonSession(int sessionId, boolean logSuccess) throws RemoteException { final PrintWriter pw = getOutPrintWriter(); PackageInstaller.Session session = null; try { session = new PackageInstaller.Session( mInterface.getPackageInstaller().openSession(sessionId)); session.abandon(); if (logSuccess) { pw.println("Success"); } return 0; } finally { IoUtils.closeQuietly(session); } }
Example #20
Source File: RootlessSAIPackageInstaller.java From SAI with GNU General Public License v3.0 | 5 votes |
private void cleanOldSessions() { int cleanedSessions = 0; long start = System.currentTimeMillis(); for (PackageInstaller.SessionInfo sessionInfo : mPackageInstaller.getMySessions()) { try { mPackageInstaller.abandonSession(sessionInfo.getSessionId()); cleanedSessions++; } catch (Exception e) { Log.w(TAG, "Unable to abandon session", e); } } Log.d(TAG, String.format("Cleaned %d sessions in %d ms.", cleanedSessions, (System.currentTimeMillis() - start))); }
Example #21
Source File: PackageInstallerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@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 (SendIntentException ignored) { } }
Example #22
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 #23
Source File: RootlessSAIPIService.java From SAI with GNU General Public License v3.0 | 5 votes |
public String getErrorString(int status, String blockingPackage) { switch (status) { case PackageInstaller.STATUS_FAILURE_ABORTED: return getString(R.string.installer_error_aborted); case PackageInstaller.STATUS_FAILURE_BLOCKED: String blocker = getString(R.string.installer_error_blocked_device); if (blockingPackage != null) { String appLabel = Utils.getAppLabel(getApplicationContext(), blockingPackage); if (appLabel != null) blocker = appLabel; } return getString(R.string.installer_error_blocked, blocker); case PackageInstaller.STATUS_FAILURE_CONFLICT: return getString(R.string.installer_error_conflict); case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE: return getString(R.string.installer_error_incompatible); case PackageInstaller.STATUS_FAILURE_INVALID: return getString(R.string.installer_error_bad_apks); case PackageInstaller.STATUS_FAILURE_STORAGE: return getString(R.string.installer_error_storage); } return getString(R.string.installer_error_generic); }
Example #24
Source File: DummyActivity.java From Shelter with Do What The F*ck You Want To Public License | 5 votes |
private void doInstallPackageQ(Uri uri, PackageInstaller.Session session, Runnable callback) { new Thread(() -> { try (InputStream is = getContentResolver().openInputStream(uri); OutputStream os = session.openWrite(UUID.randomUUID().toString(), 0, is.available()) ) { Utility.pipe(is, os); session.fsync(os); } catch (IOException e) { } runOnUiThread(callback); }).start(); }
Example #25
Source File: DummyActivity.java From Shelter with Do What The F*ck You Want To Public License | 5 votes |
private void actionUninstallPackageQ() { PackageInstaller pi = getPackageManager().getPackageInstaller(); Intent intent = new Intent(this, DummyActivity.class); intent.setAction(PACKAGEINSTALLER_CALLBACK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); pi.uninstall(getIntent().getStringExtra("package"), pendingIntent.getIntentSender()); }
Example #26
Source File: InstallationProgressListener.java From Shelter with Do What The F*ck You Want To Public License | 5 votes |
public InstallationProgressListener(Activity activity, PackageInstaller pi, int sessionId) { mPi = pi; ViewGroup layout = (ViewGroup) LayoutInflater.from(activity) .inflate(R.layout.progress_dialog, (ViewGroup) activity.getWindow().getDecorView(), false); mProgress = layout.findViewById(R.id.progress); mDialog = new AlertDialog.Builder(activity) .setCancelable(false) .setTitle(R.string.app_installing) .setView(layout) .create(); mDialog.show(); }
Example #27
Source File: VPackageInstallerService.java From container with GNU General Public License v3.0 | 5 votes |
@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) { } }
Example #28
Source File: InstallerPrivilegedSession.java From YalpStore with GNU General Public License v2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); processResult( InstalledAppsTask.getInstalledApp(context.getPackageManager(), intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)), intent.getIntExtra(EXTRA_LEGACY_STATUS, PackageInstaller.STATUS_FAILURE) ); }
Example #29
Source File: InstallResultReceiver.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null && INSTALL_SESSION_API_COMPLETE_ACTION.equals(intent.getAction())) { int status = extras.getInt(PackageInstaller.EXTRA_STATUS); String message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE); String packageName = extras.getString(PackageInstaller.EXTRA_PACKAGE_NAME); switch (status) { case PackageInstaller.STATUS_PENDING_USER_ACTION: packageInstallerResultCallback.onPendingUserAction(extras); break; case PackageInstaller.STATUS_SUCCESS: packageInstallerResultCallback.onInstallationResult( new InstallStatus(InstallStatus.Status.SUCCESS, "Install succeeded", packageName)); break; case PackageInstaller.STATUS_FAILURE: case PackageInstaller.STATUS_FAILURE_BLOCKED: case PackageInstaller.STATUS_FAILURE_CONFLICT: case PackageInstaller.STATUS_FAILURE_INCOMPATIBLE: case PackageInstaller.STATUS_FAILURE_INVALID: case PackageInstaller.STATUS_FAILURE_STORAGE: packageInstallerResultCallback.onInstallationResult( new InstallStatus(InstallStatus.Status.FAIL, "Install failed " + status + ", " + message, packageName)); break; case PackageInstaller.STATUS_FAILURE_ABORTED: packageInstallerResultCallback.onInstallationResult( new InstallStatus(InstallStatus.Status.CANCELED, "Install failed " + status + ", " + message, packageName)); default: packageInstallerResultCallback.onInstallationResult( new InstallStatus(InstallStatus.Status.UNKNOWN_ERROR, "Unrecognized status received from installer", packageName)); } } }
Example #30
Source File: EnableCosuActivity.java From android-testdpc with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (!PackageInstallationUtils.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; } } }