Search in sources :

Example 66 with ErrnoException

use of android.system.ErrnoException in project android_frameworks_base by DirtyUnicorns.

the class ParcelFileDescriptor method createCommSocketPair.

private static FileDescriptor[] createCommSocketPair() throws IOException {
    try {
        // Use SOCK_SEQPACKET so that we have a guarantee that the status
        // is written and read atomically as one unit and is not split
        // across multiple IO operations.
        final FileDescriptor comm1 = new FileDescriptor();
        final FileDescriptor comm2 = new FileDescriptor();
        Os.socketpair(AF_UNIX, SOCK_SEQPACKET, 0, comm1, comm2);
        IoUtils.setBlocking(comm1, false);
        IoUtils.setBlocking(comm2, false);
        return new FileDescriptor[] { comm1, comm2 };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor)

Example 67 with ErrnoException

use of android.system.ErrnoException in project android_frameworks_base by DirtyUnicorns.

the class ParcelFileDescriptor method createSocketPair.

/**
     * @hide
     */
public static ParcelFileDescriptor[] createSocketPair(int type) throws IOException {
    try {
        final FileDescriptor fd0 = new FileDescriptor();
        final FileDescriptor fd1 = new FileDescriptor();
        Os.socketpair(AF_UNIX, type, 0, fd0, fd1);
        return new ParcelFileDescriptor[] { new ParcelFileDescriptor(fd0), new ParcelFileDescriptor(fd1) };
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor)

Example 68 with ErrnoException

use of android.system.ErrnoException in project android_frameworks_base by DirtyUnicorns.

the class FileUtils method copyPermissions.

public static void copyPermissions(File from, File to) throws IOException {
    try {
        final StructStat stat = Os.stat(from.getAbsolutePath());
        Os.chmod(to.getAbsolutePath(), stat.st_mode);
        Os.chown(to.getAbsolutePath(), stat.st_uid, stat.st_gid);
    } catch (ErrnoException e) {
        throw e.rethrowAsIOException();
    }
}
Also used : StructStat(android.system.StructStat) ErrnoException(android.system.ErrnoException)

Example 69 with ErrnoException

use of android.system.ErrnoException in project android_frameworks_base by DirtyUnicorns.

the class PackageManagerService method maybeRenameForeignDexMarkers.

private void maybeRenameForeignDexMarkers(PackageParser.Package existing, PackageParser.Package update, UserHandle user) {
    if (existing.applicationInfo == null || update.applicationInfo == null) {
        // This isn't due to an app installation.
        return;
    }
    final File oldCodePath = new File(existing.applicationInfo.getCodePath());
    final File newCodePath = new File(update.applicationInfo.getCodePath());
    // The codePath hasn't changed, so there's nothing for us to do.
    if (Objects.equals(oldCodePath, newCodePath)) {
        return;
    }
    File canonicalNewCodePath;
    try {
        canonicalNewCodePath = new File(PackageManagerServiceUtils.realpath(newCodePath));
    } catch (IOException e) {
        Slog.w(TAG, "Failed to get canonical path.", e);
        return;
    }
    // This is a bit of a hack. The oldCodePath doesn't exist at this point (because
    // we've already renamed / deleted it) so we cannot call realpath on it. Here we assume
    // that the last component of the path (i.e, the name) doesn't need canonicalization
    // (i.e, that it isn't ".", ".." or a symbolic link). This is a valid assumption for now
    // but may change in the future. Hopefully this function won't exist at that point.
    final File canonicalOldCodePath = new File(canonicalNewCodePath.getParentFile(), oldCodePath.getName());
    // Calculate the prefixes of the markers. These are just the paths with "/" replaced
    // with "@".
    String oldMarkerPrefix = canonicalOldCodePath.getAbsolutePath().replace('/', '@');
    if (!oldMarkerPrefix.endsWith("@")) {
        oldMarkerPrefix += "@";
    }
    String newMarkerPrefix = canonicalNewCodePath.getAbsolutePath().replace('/', '@');
    if (!newMarkerPrefix.endsWith("@")) {
        newMarkerPrefix += "@";
    }
    List<String> updatedPaths = update.getAllCodePathsExcludingResourceOnly();
    List<String> markerSuffixes = new ArrayList<String>(updatedPaths.size());
    for (String updatedPath : updatedPaths) {
        String updatedPathName = new File(updatedPath).getName();
        markerSuffixes.add(updatedPathName.replace('/', '@'));
    }
    for (int userId : resolveUserIds(user.getIdentifier())) {
        File profileDir = Environment.getDataProfilesDeForeignDexDirectory(userId);
        for (String markerSuffix : markerSuffixes) {
            File oldForeignUseMark = new File(profileDir, oldMarkerPrefix + markerSuffix);
            File newForeignUseMark = new File(profileDir, newMarkerPrefix + markerSuffix);
            if (oldForeignUseMark.exists()) {
                try {
                    Os.rename(oldForeignUseMark.getAbsolutePath(), newForeignUseMark.getAbsolutePath());
                } catch (ErrnoException e) {
                    Slog.w(TAG, "Failed to rename foreign use marker", e);
                    oldForeignUseMark.delete();
                }
            }
        }
    }
}
Also used : ErrnoException(android.system.ErrnoException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PackageParser.isApkFile(android.content.pm.PackageParser.isApkFile) File(java.io.File) DexFile(dalvik.system.DexFile) StrictJarFile(android.util.jar.StrictJarFile)

Example 70 with ErrnoException

use of android.system.ErrnoException in project android_frameworks_base by DirtyUnicorns.

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)

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