Extract setting current method uid

Bug: 205676419
Test: make
Change-Id: I440fb05b347744620e485f7f63c419864db80a6a
This commit is contained in:
Nikolas Havrikov
2021-11-11 14:08:06 +01:00
parent db9b881680
commit c6fcc92444

View File

@@ -35,6 +35,7 @@ import android.util.ArrayMap;
import android.util.Slog;
import android.view.inputmethod.InputMethodInfo;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.UnbindReason;
import com.android.internal.view.IInputMethod;
import com.android.server.inputmethod.InputMethodManagerService.ClientState;
@@ -253,15 +254,7 @@ final class InputMethodBindingController {
synchronized (mMethodMap) {
if (mCurIntent != null && name.equals(mCurIntent.getComponent())) {
mCurMethod = IInputMethod.Stub.asInterface(service);
final String curMethodPackage = mCurIntent.getComponent().getPackageName();
final int curMethodUid = mPackageManagerInternal.getPackageUid(
curMethodPackage, 0 /* flags */, mSettings.getCurrentUserId());
if (curMethodUid < 0) {
Slog.e(TAG, "Failed to get UID for package=" + curMethodPackage);
mCurMethodUid = Process.INVALID_UID;
} else {
mCurMethodUid = curMethodUid;
}
updateCurrentMethodUidLocked();
if (mCurToken == null) {
Slog.w(TAG, "Service connected without a token!");
mService.unbindCurrentMethodLocked();
@@ -285,6 +278,19 @@ final class InputMethodBindingController {
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
}
@GuardedBy("mMethodMap")
private void updateCurrentMethodUidLocked() {
final String curMethodPackage = mCurIntent.getComponent().getPackageName();
final int curMethodUid = mPackageManagerInternal.getPackageUid(
curMethodPackage, 0 /* flags */, mSettings.getCurrentUserId());
if (curMethodUid < 0) {
Slog.e(TAG, "Failed to get UID for package=" + curMethodPackage);
mCurMethodUid = Process.INVALID_UID;
} else {
mCurMethodUid = curMethodUid;
}
}
@Override
public void onServiceDisconnected(@NonNull ComponentName name) {
// Note that mContext.unbindService(this) does not trigger this. Hence if we are