Fix the translation doesn't work

The problem may be caused by package visibility. We should clear
calling identity to make sure using system to query package status.

Bug: 262807108
Test: manual. Use issue chat apps to verify before and after fix.
Test: atest atest CtsTranslationTestCases

Change-Id: I13799314eb52087f47757d8b523c419f1fb472b8
This commit is contained in:
Joanne Chung
2023-03-15 16:20:30 +08:00
parent 5eb022a23b
commit 3cf6c66fdd

View File

@@ -37,6 +37,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IRemoteCallback;
@@ -160,11 +161,20 @@ final class TranslationManagerServiceImpl extends
return null;
}
final ComponentName serviceComponent = ComponentName.unflattenFromString(serviceName);
if (!isServiceAvailableForUser(serviceComponent)) {
boolean isServiceAvailableForUser;
final long identity = Binder.clearCallingIdentity();
try {
isServiceAvailableForUser = isServiceAvailableForUser(serviceComponent);
if (mMaster.verbose) {
Slog.v(TAG, "ensureRemoteServiceLocked(): " + serviceComponent
+ " is not available,");
Slog.v(TAG, "ensureRemoteServiceLocked(): isServiceAvailableForUser="
+ isServiceAvailableForUser);
}
} finally {
Binder.restoreCallingIdentity(identity);
}
if (!isServiceAvailableForUser) {
Slog.w(TAG, "ensureRemoteServiceLocked(): " + serviceComponent
+ " is not available,");
return null;
}
mRemoteTranslationService = new RemoteTranslationService(getContext(), serviceComponent,