DO NOT MERGE Ensure package names read from config are system packages.

Bug: 145981139
Test: manually tested ensureSystemPackageName() returns null for non-system app
Change-Id: I1d23910cbd282f6702785c9dfb059d7be6b0e895
(cherry picked from commit 6a56247200)
This commit is contained in:
Hai Zhang
2019-12-10 17:34:18 -08:00
parent 835e3a52bb
commit 584d73a0b0

View File

@@ -20710,7 +20710,29 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
@Override
public String getSystemTextClassifierPackageName() {
return mContext.getString(R.string.config_defaultTextClassifierPackage);
return ensureSystemPackageName(mContext.getString(
R.string.config_defaultTextClassifierPackage));
}
@Nullable
private String ensureSystemPackageName(@Nullable String packageName) {
if (packageName == null) {
return null;
}
long token = Binder.clearCallingIdentity();
try {
if (getPackageInfo(packageName, MATCH_FACTORY_ONLY, UserHandle.USER_SYSTEM) == null) {
PackageInfo packageInfo = getPackageInfo(packageName, 0, UserHandle.USER_SYSTEM);
if (packageInfo != null) {
EventLog.writeEvent(0x534e4554, "145981139", packageInfo.applicationInfo.uid,
"");
}
return null;
}
} finally {
Binder.restoreCallingIdentity(token);
}
return packageName;
}
@Override