1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.pm.test.verify.domain; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.UserIdInt; 22 import android.content.pm.PackageManager; 23 import android.content.pm.verify.domain.DomainOwner; 24 import android.content.pm.verify.domain.DomainVerificationManager; 25 26 import com.android.server.pm.verify.domain.DomainVerificationService; 27 28 import java.util.List; 29 import java.util.Set; 30 import java.util.SortedSet; 31 import java.util.UUID; 32 33 /** 34 * Proxies Kotlin calls to the Java layer such that null values can be passed for {@link NonNull} 35 * marked parameters, as Kotlin disallows this at the compiler leveling, preventing the null error 36 * codes from being tested. 37 */ 38 class DomainVerificationJavaUtil { 39 setStatusForceNullable(@onNull DomainVerificationService service, @Nullable UUID domainSetId, @Nullable Set<String> domains, int state)40 static int setStatusForceNullable(@NonNull DomainVerificationService service, 41 @Nullable UUID domainSetId, @Nullable Set<String> domains, int state) 42 throws PackageManager.NameNotFoundException { 43 return service.setDomainVerificationStatus(domainSetId, domains, state); 44 } 45 setUserSelectionForceNullable(@onNull DomainVerificationService service, @Nullable UUID domainSetId, @Nullable Set<String> domains, boolean enabled, @UserIdInt int userId)46 static int setUserSelectionForceNullable(@NonNull DomainVerificationService service, 47 @Nullable UUID domainSetId, @Nullable Set<String> domains, boolean enabled, 48 @UserIdInt int userId) 49 throws PackageManager.NameNotFoundException { 50 return service.setDomainVerificationUserSelection(domainSetId, domains, enabled, userId); 51 } 52 setStatusForceNullable(@onNull DomainVerificationManager manager, @Nullable UUID domainSetId, @Nullable Set<String> domains, int state)53 static int setStatusForceNullable(@NonNull DomainVerificationManager manager, 54 @Nullable UUID domainSetId, @Nullable Set<String> domains, int state) 55 throws PackageManager.NameNotFoundException { 56 return manager.setDomainVerificationStatus(domainSetId, domains, state); 57 } 58 setUserSelectionForceNullable(@onNull DomainVerificationManager manager, @Nullable UUID domainSetId, @Nullable Set<String> domains, boolean enabled)59 static int setUserSelectionForceNullable(@NonNull DomainVerificationManager manager, 60 @Nullable UUID domainSetId, @Nullable Set<String> domains, boolean enabled) 61 throws PackageManager.NameNotFoundException { 62 return manager.setDomainVerificationUserSelection(domainSetId, domains, enabled); 63 } 64 getOwnersForDomain(@onNull DomainVerificationManager manager, @Nullable String domain)65 static SortedSet<DomainOwner> getOwnersForDomain(@NonNull DomainVerificationManager manager, 66 @Nullable String domain) { 67 return manager.getOwnersForDomain(domain); 68 } 69 getOwnersForDomain(@onNull DomainVerificationService service, @Nullable String domain, @UserIdInt int userId)70 static List<DomainOwner> getOwnersForDomain(@NonNull DomainVerificationService service, 71 @Nullable String domain, @UserIdInt int userId) { 72 return service.getOwnersForDomain(domain, userId); 73 } 74 } 75