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.statementservice.utils 18 19 import android.content.ComponentName 20 import android.content.Context 21 import android.content.pm.PackageManager 22 import android.content.pm.verify.domain.DomainVerificationInfo 23 import android.content.pm.verify.domain.DomainVerificationRequest 24 import android.content.pm.verify.domain.DomainVerificationUserState 25 import com.android.statementservice.domain.DomainVerificationReceiverV1 26 import com.android.statementservice.domain.DomainVerificationReceiverV2 27 28 // Top level extensions for models to allow Kotlin deconstructing declarations 29 component1null30operator fun DomainVerificationRequest.component1() = packageNames 31 32 operator fun DomainVerificationInfo.component1() = identifier 33 operator fun DomainVerificationInfo.component2() = packageName 34 operator fun DomainVerificationInfo.component3() = hostToStateMap 35 36 operator fun DomainVerificationUserState.component1() = identifier 37 operator fun DomainVerificationUserState.component2() = packageName 38 operator fun DomainVerificationUserState.component3() = user 39 operator fun DomainVerificationUserState.component4() = isLinkHandlingAllowed 40 operator fun DomainVerificationUserState.component5() = hostToStateMap 41 42 object AndroidUtils { 43 44 fun isReceiverV1Enabled(context: Context): Boolean { 45 val receiver = ComponentName(context, DomainVerificationReceiverV1::class.java) 46 return when (context.packageManager.getComponentEnabledSetting(receiver)) { 47 // Must change this if the manifest ever changes 48 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT -> true 49 PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> true 50 else -> false 51 } 52 } 53 54 fun isReceiverV2Enabled(context: Context): Boolean { 55 val receiver = ComponentName(context, DomainVerificationReceiverV2::class.java) 56 return when (context.packageManager.getComponentEnabledSetting(receiver)) { 57 // Must change this if the manifest ever changes 58 PackageManager.COMPONENT_ENABLED_STATE_DEFAULT -> false 59 PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> true 60 else -> false 61 } 62 } 63 } 64