From 786cbcacd2efbd94476eb05a4d5b77211f20d434 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 16 Aug 2012 11:10:58 -0700 Subject: Use Libcore.os.stat instead of FileUtils PackageManagerService just needed to know the owner for this file, so just use stat instead so we can remove the old JNI code. This is the last user of FileUtils#getPermissions so just remove the FileUtils method as well. Change-Id: I953057cd6b9de4410f33b6f22e4bddff02fe2988 --- .../android/server/pm/PackageManagerService.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'services/java') diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 8c5a0908c9b5..7390cbe2030f 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -144,6 +144,7 @@ import java.util.Set; import libcore.io.ErrnoException; import libcore.io.IoUtils; import libcore.io.Libcore; +import libcore.io.StructStat; /** * Keep track of all those .apks everywhere. @@ -294,8 +295,6 @@ public class PackageManagerService extends IPackageManager.Stub { File mScanningPath; int mLastScanError; - final int[] mOutPermissions = new int[3]; - // ---------------------------------------------------------------- // Keys are String (package name), values are Package. This also serves @@ -3762,14 +3761,18 @@ public class PackageManagerService extends IPackageManager.Stub { boolean uidError = false; if (dataPath.exists()) { - // XXX should really do this check for each user. - mOutPermissions[1] = 0; - FileUtils.getPermissions(dataPath.getPath(), mOutPermissions); + int currentUid = 0; + try { + StructStat stat = Libcore.os.stat(dataPath.getPath()); + currentUid = stat.st_uid; + } catch (ErrnoException e) { + Slog.e(TAG, "Couldn't stat path " + dataPath.getPath(), e); + } // If we have mismatched owners for the data path, we have a problem. - if (mOutPermissions[1] != pkg.applicationInfo.uid) { + if (currentUid != pkg.applicationInfo.uid) { boolean recovered = false; - if (mOutPermissions[1] == 0) { + if (currentUid == 0) { // The directory somehow became owned by root. Wow. // This is probably because the system was stopped while // installd was in the middle of messing with its libs @@ -3798,7 +3801,7 @@ public class PackageManagerService extends IPackageManager.Stub { ? "System package " : "Third party package "; String msg = prefix + pkg.packageName + " has changed from uid: " - + mOutPermissions[1] + " to " + + currentUid + " to " + pkg.applicationInfo.uid + "; old data erased"; reportSettingsProblem(Log.WARN, msg); recovered = true; @@ -3830,11 +3833,11 @@ public class PackageManagerService extends IPackageManager.Stub { if (!recovered) { pkg.applicationInfo.dataDir = "/mismatched_uid/settings_" + pkg.applicationInfo.uid + "/fs_" - + mOutPermissions[1]; + + currentUid; pkg.applicationInfo.nativeLibraryDir = pkg.applicationInfo.dataDir; String msg = "Package " + pkg.packageName + " has mismatched uid: " - + mOutPermissions[1] + " on disk, " + + currentUid + " on disk, " + pkg.applicationInfo.uid + " in settings"; // writer synchronized (mPackages) { -- cgit v1.2.3-59-g8ed1b