Fix Android O: AccountManager API not working in managed profile.

Bug: 64577509
Test: NONE
Change-Id: I25650b2002d392ef9b7f4f4732106b22bc0eaae2
This commit is contained in:
sunjian
2017-08-14 15:45:04 -07:00
committed by Jian Sun
parent 21f3489653
commit 9ae597b6f2

View File

@@ -5289,16 +5289,14 @@ public class AccountManagerService
long identityToken = Binder.clearCallingIdentity(); long identityToken = Binder.clearCallingIdentity();
try { try {
packages = mPackageManager.getPackagesForUid(callingUid); packages = mPackageManager.getPackagesForUid(callingUid);
} finally {
Binder.restoreCallingIdentity(identityToken);
}
if (packages == null) { if (packages == null) {
Log.d(TAG, "No packages for callingUid " + callingUid); Log.d(TAG, "No packages for callingUid " + callingUid);
return false; return false;
} }
for (String name : packages) { for (String name : packages) {
try { try {
PackageInfo packageInfo = mPackageManager.getPackageInfo(name, 0 /* flags */); PackageInfo packageInfo =
mPackageManager.getPackageInfo(name, 0 /* flags */);
if (packageInfo != null if (packageInfo != null
&& (packageInfo.applicationInfo.privateFlags && (packageInfo.applicationInfo.privateFlags
& ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) { & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
@@ -5306,9 +5304,11 @@ public class AccountManagerService
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, "Package not found " + e.getMessage()); Log.d(TAG, "Package not found " + e.getMessage());
return false;
} }
} }
} finally {
Binder.restoreCallingIdentity(identityToken);
}
return false; return false;
} }