Java Code Examples for android.content.pm.PackageManager#INSTALL_SUCCEEDED

The following examples show how to use android.content.pm.PackageManager#INSTALL_SUCCEEDED . 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: PackageInstallerSession.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static void extractNativeLibraries(File packageDir, String abiOverride, boolean inherit)
        throws PackageManagerException {
    final File libDir = new File(packageDir, NativeLibraryHelper.LIB_DIR_NAME);
    if (!inherit) {
        // Start from a clean slate
        NativeLibraryHelper.removeNativeBinariesFromDirLI(libDir, true);
    }

    NativeLibraryHelper.Handle handle = null;
    try {
        handle = NativeLibraryHelper.Handle.create(packageDir);
        final int res = NativeLibraryHelper.copyNativeBinariesWithOverride(handle, libDir,
                abiOverride);
        if (res != PackageManager.INSTALL_SUCCEEDED) {
            throw new PackageManagerException(res,
                    "Failed to extract native libraries, res=" + res);
        }
    } catch (IOException e) {
        throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
                "Failed to extract native libraries", e);
    } finally {
        IoUtils.closeQuietly(handle);
    }
}
 
Example 2
Source File: PackageManagerServiceUtils.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static int decompressFile(File srcFile, File dstFile) throws ErrnoException {
    if (DEBUG_COMPRESSION) {
        Slog.i(TAG, "Decompress file"
                + "; src: " + srcFile.getAbsolutePath()
                + ", dst: " + dstFile.getAbsolutePath());
    }
    try (
            InputStream fileIn = new GZIPInputStream(new FileInputStream(srcFile));
            OutputStream fileOut = new FileOutputStream(dstFile, false /*append*/);
    ) {
        FileUtils.copy(fileIn, fileOut);
        Os.chmod(dstFile.getAbsolutePath(), 0644);
        return PackageManager.INSTALL_SUCCEEDED;
    } catch (IOException e) {
        logCriticalInfo(Log.ERROR, "Failed to decompress file"
                + "; src: " + srcFile.getAbsolutePath()
                + ", dst: " + dstFile.getAbsolutePath());
    }
    return PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
}
 
Example 3
Source File: PackageInstallerSession.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void dispatchSessionFinished(int returnCode, String msg, Bundle extras) {
    final IPackageInstallObserver2 observer;
    final String packageName;
    synchronized (mLock) {
        mFinalStatus = returnCode;
        mFinalMessage = msg;

        observer = mRemoteObserver;
        packageName = mPackageName;
    }

    if (observer != null) {
        // Execute observer.onPackageInstalled on different tread as we don't want callers
        // inside the system server have to worry about catching the callbacks while they are
        // calling into the session
        final SomeArgs args = SomeArgs.obtain();
        args.arg1 = packageName;
        args.arg2 = msg;
        args.arg3 = extras;
        args.arg4 = observer;
        args.argi1 = returnCode;

        mHandler.obtainMessage(MSG_ON_PACKAGE_INSTALLED, args).sendToTarget();
    }

    final boolean success = (returnCode == PackageManager.INSTALL_SUCCEEDED);

    // Send broadcast to default launcher only if it's a new install
    final boolean isNewInstall = extras == null || !extras.getBoolean(Intent.EXTRA_REPLACING);
    if (success && isNewInstall) {
        mPm.sendSessionCommitBroadcast(generateInfo(), userId);
    }

    mCallback.onSessionFinished(this, success);
}
 
Example 4
Source File: PackageInstallerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onPackageInstalled(String basePackageName, int returnCode, String msg,
        Bundle extras) {
    if (PackageManager.INSTALL_SUCCEEDED == returnCode && mShowNotification) {
        boolean update = (extras != null) && extras.getBoolean(Intent.EXTRA_REPLACING);
        Notification notification = buildSuccessNotification(mContext,
                mContext.getResources()
                        .getString(update ? R.string.package_updated_device_owner :
                                R.string.package_installed_device_owner),
                basePackageName,
                mUserId);
        if (notification != null) {
            NotificationManager notificationManager = (NotificationManager)
                    mContext.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(basePackageName,
                    SystemMessage.NOTE_PACKAGE_STATE,
                    notification);
        }
    }
    final Intent fillIn = new Intent();
    fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, basePackageName);
    fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID, mSessionId);
    fillIn.putExtra(PackageInstaller.EXTRA_STATUS,
            PackageManager.installStatusToPublicStatus(returnCode));
    fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE,
            PackageManager.installStatusToString(returnCode, msg));
    fillIn.putExtra(PackageInstaller.EXTRA_LEGACY_STATUS, returnCode);
    if (extras != null) {
        final String existing = extras.getString(
                PackageManager.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 (SendIntentException ignored) {
    }
}