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

Commit fa57a2e0 authored by Wilson Wu's avatar Wilson Wu
Browse files

Add null check for IInputMethodPrivilegedOperations

InputMethodManagerService should not initialize null
IInputMethodPrivilegedOperations to InputMethodService.

Add null check when setting the IInputMethodPrivilegedOperations
parameter to improve code readability.

Bug: 183992652
Test: atest CtsInputMethodTestCases
Change-Id: Ie4a8dff268177c5219c7c5495a2de6bc69b0ee25
parent 0abe7327
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.internal.inputmethod;

import android.annotation.AnyThread;
import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.Uri;
import android.os.IBinder;
@@ -28,6 +29,8 @@ import android.view.inputmethod.InputMethodSubtype;

import com.android.internal.annotations.GuardedBy;

import java.util.Objects;

/**
 * A utility class to take care of boilerplate code around IPCs.
 */
@@ -47,7 +50,7 @@ public final class InputMethodPrivilegedOperations {
         * @param privOps Binder interface to be set
         */
        @AnyThread
        public synchronized void set(IInputMethodPrivilegedOperations privOps) {
        public synchronized void set(@NonNull IInputMethodPrivilegedOperations privOps) {
            if (mPrivOps != null) {
                throw new IllegalStateException(
                        "IInputMethodPrivilegedOperations must be set at most once."
@@ -90,7 +93,8 @@ public final class InputMethodPrivilegedOperations {
     * @param privOps Binder interface to be set
     */
    @AnyThread
    public void set(IInputMethodPrivilegedOperations privOps) {
    public void set(@NonNull IInputMethodPrivilegedOperations privOps) {
        Objects.requireNonNull(privOps, "privOps must not be null");
        mOps.set(privOps);
    }