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();
}
}
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();
}
}
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();
}
}
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();
}
}
}
}
}
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();
}
}
Aggregations