Search in sources :

Example 16 with ErrnoException

use of android.system.ErrnoException in project platform_frameworks_base by android.

the class PackageInstallerService method prepareStageDir.

static void prepareStageDir(File stageDir) throws IOException {
    if (stageDir.exists()) {
        throw new IOException("Session dir already exists: " + stageDir);
    }
    try {
        Os.mkdir(stageDir.getAbsolutePath(), 0755);
        Os.chmod(stageDir.getAbsolutePath(), 0755);
    } catch (ErrnoException e) {
        // This purposefully throws if directory already exists
        throw new IOException("Failed to prepare session dir: " + stageDir, e);
    }
    if (!SELinux.restorecon(stageDir)) {
        throw new IOException("Failed to restorecon session dir: " + stageDir);
    }
}
Also used : ErrnoException(android.system.ErrnoException) IOException(java.io.IOException)

Example 17 with ErrnoException

use of android.system.ErrnoException in project platform_frameworks_base by android.

the class PackageInstallerSession method openReadInternal.

private ParcelFileDescriptor openReadInternal(String name) throws IOException {
    assertPreparedAndNotSealed("openRead");
    try {
        if (!FileUtils.isValidExtFilename(name)) {
            throw new IllegalArgumentException("Invalid name: " + name);
        }
        final File target = new File(resolveStageDir(), name);
        final FileDescriptor targetFd = Libcore.os.open(target.getAbsolutePath(), O_RDONLY, 0);
        return new ParcelFileDescriptor(targetFd);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) ParcelFileDescriptor(android.os.ParcelFileDescriptor) File(java.io.File) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptor(java.io.FileDescriptor)

Example 18 with ErrnoException

use of android.system.ErrnoException in project platform_frameworks_base by android.

the class PackageInstallerSession method createRemoveSplitMarker.

private void createRemoveSplitMarker(String splitName) throws IOException {
    try {
        final String markerName = splitName + REMOVE_SPLIT_MARKER_EXTENSION;
        if (!FileUtils.isValidExtFilename(markerName)) {
            throw new IllegalArgumentException("Invalid marker: " + markerName);
        }
        final File target = new File(resolveStageDir(), markerName);
        target.createNewFile();
        Os.chmod(target.getAbsolutePath(), 0);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) File(java.io.File)

Example 19 with ErrnoException

use of android.system.ErrnoException in project platform_frameworks_base by android.

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 20 with ErrnoException

use of android.system.ErrnoException in project platform_frameworks_base by android.

the class ApfFilter method maybeStartFilter.

/**
     * Attempt to start listening for RAs and, if RAs are received, generating and installing
     * filters to ignore useless RAs.
     */
@VisibleForTesting
void maybeStartFilter() {
    FileDescriptor socket;
    try {
        mHardwareAddress = mNetworkInterface.getHardwareAddress();
        synchronized (this) {
            // Install basic filters
            installNewProgramLocked();
        }
        socket = Os.socket(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
        PacketSocketAddress addr = new PacketSocketAddress((short) ETH_P_IPV6, mNetworkInterface.getIndex());
        Os.bind(socket, addr);
        NetworkUtils.attachRaFilter(socket, mApfCapabilities.apfPacketFormat);
    } catch (SocketException | ErrnoException e) {
        Log.e(TAG, "Error starting filter", e);
        return;
    }
    mReceiveThread = new ReceiveThread(socket);
    mReceiveThread.start();
}
Also used : SocketException(java.net.SocketException) PacketSocketAddress(android.system.PacketSocketAddress) ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

ErrnoException (android.system.ErrnoException)215 IOException (java.io.IOException)99 FileDescriptor (java.io.FileDescriptor)95 File (java.io.File)74 StructStat (android.system.StructStat)45 FileInputStream (java.io.FileInputStream)40 FileOutputStream (java.io.FileOutputStream)29 ParcelFileDescriptor (android.os.ParcelFileDescriptor)17 SocketException (java.net.SocketException)17 BufferedInputStream (java.io.BufferedInputStream)15 InputStream (java.io.InputStream)11 AssetFileDescriptor (android.content.res.AssetFileDescriptor)10 ExifInterface (android.media.ExifInterface)10 StructLinger (android.system.StructLinger)10 StructTimeval (android.system.StructTimeval)10 FileNotFoundException (java.io.FileNotFoundException)10 StructPollfd (android.system.StructPollfd)9 InterruptedIOException (java.io.InterruptedIOException)9 PacketSocketAddress (android.system.PacketSocketAddress)8 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)8