Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3cf6c66f authored by Joanne Chung's avatar Joanne Chung
Browse files

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
parent 5eb022a2
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -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,