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

Commit 536a84cb authored by Daulet Zhanguzin's avatar Daulet Zhanguzin
Browse files

Replace com.android.internal.util.Preconditions.checkNotNull with

java.util.Objects.requireNonNull

Bug: 126528330

Test: Treehugger
Change-Id: I360b60c4a134210f44c3391364bd95c23854c7d7
parent 856ce4a1
Loading
Loading
Loading
Loading
+3 −2
Original line number Original line Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.server.SystemService;
import java.util.HashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HashSet;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Set;


/**
/**
@@ -179,8 +180,8 @@ public class SoundTriggerMiddlewareService extends ISoundTriggerMiddlewareServic
        // Permission check.
        // Permission check.
        checkPermissions();
        checkPermissions();
        // Input validation.
        // Input validation.
        Preconditions.checkNotNull(callback);
        Objects.requireNonNull(callback);
        Preconditions.checkNotNull(callback.asBinder());
        Objects.requireNonNull(callback.asBinder());


        synchronized (this) {
        synchronized (this) {
            // State validation.
            // State validation.
+16 −15
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.media.soundtrigger_middleware.SoundModelType;


import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;


import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;


@@ -42,7 +43,7 @@ import java.util.regex.Pattern;
 */
 */
public class ValidationUtil {
public class ValidationUtil {
    static void validateUuid(@Nullable String uuid) {
    static void validateUuid(@Nullable String uuid) {
        Preconditions.checkNotNull(uuid);
        Objects.requireNonNull(uuid);
        Matcher matcher = UuidUtil.PATTERN.matcher(uuid);
        Matcher matcher = UuidUtil.PATTERN.matcher(uuid);
        if (!matcher.matches()) {
        if (!matcher.matches()) {
            throw new IllegalArgumentException(
            throw new IllegalArgumentException(
@@ -55,37 +56,37 @@ public class ValidationUtil {
    }
    }


    static void validateModel(@Nullable SoundModel model, int expectedType) {
    static void validateModel(@Nullable SoundModel model, int expectedType) {
        Preconditions.checkNotNull(model);
        Objects.requireNonNull(model);
        if (model.type != expectedType) {
        if (model.type != expectedType) {
            throw new IllegalArgumentException("Invalid type");
            throw new IllegalArgumentException("Invalid type");
        }
        }
        validateUuid(model.uuid);
        validateUuid(model.uuid);
        validateUuid(model.vendorUuid);
        validateUuid(model.vendorUuid);
        Preconditions.checkNotNull(model.data);
        Objects.requireNonNull(model.data);
    }
    }


    static void validatePhraseModel(@Nullable PhraseSoundModel model) {
    static void validatePhraseModel(@Nullable PhraseSoundModel model) {
        Preconditions.checkNotNull(model);
        Objects.requireNonNull(model);
        validateModel(model.common, SoundModelType.KEYPHRASE);
        validateModel(model.common, SoundModelType.KEYPHRASE);
        Preconditions.checkNotNull(model.phrases);
        Objects.requireNonNull(model.phrases);
        for (Phrase phrase : model.phrases) {
        for (Phrase phrase : model.phrases) {
            Preconditions.checkNotNull(phrase);
            Objects.requireNonNull(phrase);
            if ((phrase.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER
            if ((phrase.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER
                    | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION
                    | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION
                    | RecognitionMode.GENERIC_TRIGGER)) != 0) {
                    | RecognitionMode.GENERIC_TRIGGER)) != 0) {
                throw new IllegalArgumentException("Invalid recognitionModes");
                throw new IllegalArgumentException("Invalid recognitionModes");
            }
            }
            Preconditions.checkNotNull(phrase.users);
            Objects.requireNonNull(phrase.users);
            Preconditions.checkNotNull(phrase.locale);
            Objects.requireNonNull(phrase.locale);
            Preconditions.checkNotNull(phrase.text);
            Objects.requireNonNull(phrase.text);
        }
        }
    }
    }


    static void validateRecognitionConfig(@Nullable RecognitionConfig config) {
    static void validateRecognitionConfig(@Nullable RecognitionConfig config) {
        Preconditions.checkNotNull(config);
        Objects.requireNonNull(config);
        Preconditions.checkNotNull(config.phraseRecognitionExtras);
        Objects.requireNonNull(config.phraseRecognitionExtras);
        for (PhraseRecognitionExtra extra : config.phraseRecognitionExtras) {
        for (PhraseRecognitionExtra extra : config.phraseRecognitionExtras) {
            Preconditions.checkNotNull(extra);
            Objects.requireNonNull(extra);
            if ((extra.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER
            if ((extra.recognitionModes & ~(RecognitionMode.VOICE_TRIGGER
                    | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION
                    | RecognitionMode.USER_IDENTIFICATION | RecognitionMode.USER_AUTHENTICATION
                    | RecognitionMode.GENERIC_TRIGGER)) != 0) {
                    | RecognitionMode.GENERIC_TRIGGER)) != 0) {
@@ -94,15 +95,15 @@ public class ValidationUtil {
            if (extra.confidenceLevel < 0 || extra.confidenceLevel > 100) {
            if (extra.confidenceLevel < 0 || extra.confidenceLevel > 100) {
                throw new IllegalArgumentException("Invalid confidenceLevel");
                throw new IllegalArgumentException("Invalid confidenceLevel");
            }
            }
            Preconditions.checkNotNull(extra.levels);
            Objects.requireNonNull(extra.levels);
            for (ConfidenceLevel level : extra.levels) {
            for (ConfidenceLevel level : extra.levels) {
                Preconditions.checkNotNull(level);
                Objects.requireNonNull(level);
                if (level.levelPercent < 0 || level.levelPercent > 100) {
                if (level.levelPercent < 0 || level.levelPercent > 100) {
                    throw new IllegalArgumentException("Invalid confidenceLevel");
                    throw new IllegalArgumentException("Invalid confidenceLevel");
                }
                }
            }
            }
        }
        }
        Preconditions.checkNotNull(config.data);
        Objects.requireNonNull(config.data);
    }
    }


    static void validateModelParameter(int modelParam) {
    static void validateModelParameter(int modelParam) {