Search in sources :

Example 11 with FileBridge

use of android.os.FileBridge in project android_frameworks_base by AOSPA.

the class PackageInstallerSession method commit.

@Override
public void commit(IntentSender statusReceiver) {
    Preconditions.checkNotNull(statusReceiver);
    final boolean wasSealed;
    synchronized (mLock) {
        wasSealed = mSealed;
        if (!mSealed) {
            // Verify that all writers are hands-off
            for (FileBridge bridge : mBridges) {
                if (!bridge.isClosed()) {
                    throw new SecurityException("Files still open");
                }
            }
            mSealed = true;
        }
        // Client staging is fully done at this point
        mClientProgress = 1f;
        computeProgressLocked(true);
    }
    if (!wasSealed) {
        // Persist the fact that we've sealed ourselves to prevent
        // mutations of any hard links we create. We do this without holding
        // the session lock, since otherwise it's a lock inversion.
        mCallback.onSessionSealedBlocking(this);
    }
    // This ongoing commit should keep session active, even though client
    // will probably close their end.
    mActiveCount.incrementAndGet();
    final PackageInstallObserverAdapter adapter = new PackageInstallObserverAdapter(mContext, statusReceiver, sessionId, mIsInstallerDeviceOwner, userId);
    mHandler.obtainMessage(MSG_COMMIT, adapter.getBinder()).sendToTarget();
}
Also used : PackageInstallObserverAdapter(com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter) FileBridge(android.os.FileBridge)

Example 12 with FileBridge

use of android.os.FileBridge in project android_frameworks_base by DirtyUnicorns.

the class PackageInstallerSession method openWriteInternal.

private ParcelFileDescriptor openWriteInternal(String name, long offsetBytes, long lengthBytes) throws IOException {
    // Quick sanity check of state, and allocate a pipe for ourselves. We
    // then do heavy disk allocation outside the lock, but this open pipe
    // will block any attempted install transitions.
    final FileBridge bridge;
    synchronized (mLock) {
        assertPreparedAndNotSealed("openWrite");
        bridge = new FileBridge();
        mBridges.add(bridge);
    }
    try {
        // Use installer provided name for now; we always rename later
        if (!FileUtils.isValidExtFilename(name)) {
            throw new IllegalArgumentException("Invalid name: " + name);
        }
        final File target;
        final long identity = Binder.clearCallingIdentity();
        try {
            target = new File(resolveStageDir(), name);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
        // TODO: this should delegate to DCS so the system process avoids
        // holding open FDs into containers.
        final FileDescriptor targetFd = Libcore.os.open(target.getAbsolutePath(), O_CREAT | O_WRONLY, 0644);
        Os.chmod(target.getAbsolutePath(), 0644);
        // cache space to grow, if needed.
        if (lengthBytes > 0) {
            final StructStat stat = Libcore.os.fstat(targetFd);
            final long deltaBytes = lengthBytes - stat.st_size;
            // Only need to free up space when writing to internal stage
            if (stageDir != null && deltaBytes > 0) {
                mPm.freeStorage(params.volumeUuid, deltaBytes);
            }
            Libcore.os.posix_fallocate(targetFd, 0, lengthBytes);
        }
        if (offsetBytes > 0) {
            Libcore.os.lseek(targetFd, offsetBytes, OsConstants.SEEK_SET);
        }
        bridge.setTargetFile(targetFd);
        bridge.start();
        return new ParcelFileDescriptor(bridge.getClientSocket());
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : StructStat(android.system.StructStat) ErrnoException(android.system.ErrnoException) FileBridge(android.os.FileBridge) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 13 with FileBridge

use of android.os.FileBridge in project android_frameworks_base by DirtyUnicorns.

the class PackageInstallerSession method destroyInternal.

private void destroyInternal() {
    synchronized (mLock) {
        mSealed = true;
        mDestroyed = true;
        // Force shut down all bridges
        for (FileBridge bridge : mBridges) {
            bridge.forceClose();
        }
    }
    if (stageDir != null) {
        try {
            mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath());
        } catch (InstallerException ignored) {
        }
    }
    if (stageCid != null) {
        PackageHelper.destroySdDir(stageCid);
    }
}
Also used : FileBridge(android.os.FileBridge) InstallerException(com.android.internal.os.InstallerConnection.InstallerException)

Example 14 with FileBridge

use of android.os.FileBridge in project android_frameworks_base by ResurrectionRemix.

the class PackageInstallerSession method commit.

@Override
public void commit(IntentSender statusReceiver) {
    Preconditions.checkNotNull(statusReceiver);
    final boolean wasSealed;
    synchronized (mLock) {
        wasSealed = mSealed;
        if (!mSealed) {
            // Verify that all writers are hands-off
            for (FileBridge bridge : mBridges) {
                if (!bridge.isClosed()) {
                    throw new SecurityException("Files still open");
                }
            }
            mSealed = true;
        }
        // Client staging is fully done at this point
        mClientProgress = 1f;
        computeProgressLocked(true);
    }
    if (!wasSealed) {
        // Persist the fact that we've sealed ourselves to prevent
        // mutations of any hard links we create. We do this without holding
        // the session lock, since otherwise it's a lock inversion.
        mCallback.onSessionSealedBlocking(this);
    }
    // This ongoing commit should keep session active, even though client
    // will probably close their end.
    mActiveCount.incrementAndGet();
    final PackageInstallObserverAdapter adapter = new PackageInstallObserverAdapter(mContext, statusReceiver, sessionId, mIsInstallerDeviceOwner, userId);
    mHandler.obtainMessage(MSG_COMMIT, adapter.getBinder()).sendToTarget();
}
Also used : PackageInstallObserverAdapter(com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter) FileBridge(android.os.FileBridge)

Example 15 with FileBridge

use of android.os.FileBridge in project android_frameworks_base by ResurrectionRemix.

the class PackageInstallerSession method destroyInternal.

private void destroyInternal() {
    synchronized (mLock) {
        mSealed = true;
        mDestroyed = true;
        // Force shut down all bridges
        for (FileBridge bridge : mBridges) {
            bridge.forceClose();
        }
    }
    if (stageDir != null) {
        try {
            mPm.mInstaller.rmPackageDir(stageDir.getAbsolutePath());
        } catch (InstallerException ignored) {
        }
    }
    if (stageCid != null) {
        PackageHelper.destroySdDir(stageCid);
    }
}
Also used : FileBridge(android.os.FileBridge) InstallerException(com.android.internal.os.InstallerConnection.InstallerException)

Aggregations

FileBridge (android.os.FileBridge)15 ParcelFileDescriptor (android.os.ParcelFileDescriptor)5 ErrnoException (android.system.ErrnoException)5 StructStat (android.system.StructStat)5 PackageInstallObserverAdapter (com.android.server.pm.PackageInstallerService.PackageInstallObserverAdapter)5 File (java.io.File)5 FileDescriptor (java.io.FileDescriptor)5 InstallerException (com.android.internal.os.InstallerConnection.InstallerException)4 InstallerException (com.android.server.pm.Installer.InstallerException)1