• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.verify.domain.proxy;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.util.Slog;
24 
25 import com.android.server.DeviceIdleInternal;
26 import com.android.server.pm.verify.domain.DomainVerificationCollector;
27 import com.android.server.pm.verify.domain.DomainVerificationDebug;
28 import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
29 import com.android.server.pm.verify.domain.DomainVerificationMessageCodes;
30 
31 import java.util.Objects;
32 import java.util.Set;
33 
34 public interface DomainVerificationProxy {
35 
36     String TAG = "DomainVerificationProxy";
37 
38     boolean DEBUG_PROXIES = DomainVerificationDebug.DEBUG_PROXIES;
39 
40     static <ConnectionType extends DomainVerificationProxyV1.Connection
makeProxy( @ullable ComponentName componentV1, @Nullable ComponentName componentV2, @NonNull Context context, @NonNull DomainVerificationManagerInternal manager, @NonNull DomainVerificationCollector collector, @NonNull ConnectionType connection)41             & DomainVerificationProxyV2.Connection> DomainVerificationProxy makeProxy(
42             @Nullable ComponentName componentV1, @Nullable ComponentName componentV2,
43             @NonNull Context context, @NonNull DomainVerificationManagerInternal manager,
44             @NonNull DomainVerificationCollector collector, @NonNull ConnectionType connection) {
45         if (DEBUG_PROXIES) {
46             Slog.d(TAG, "Intent filter verification agent: " + componentV1);
47             Slog.d(TAG, "Domain verification agent: " + componentV2);
48         }
49 
50         if (componentV2 != null && componentV1 != null
51                 && !Objects.equals(componentV2.getPackageName(), componentV1.getPackageName())) {
52             // Only allow a legacy verifier if it's in the same package as the v2 verifier
53             componentV1 = null;
54         }
55 
56         DomainVerificationProxy proxyV1 = null;
57         DomainVerificationProxy proxyV2 = null;
58 
59         if (componentV1 != null) {
60             proxyV1 = new DomainVerificationProxyV1(context, manager, collector, connection,
61                     componentV1);
62         }
63 
64         if (componentV2 != null) {
65             proxyV2 = new DomainVerificationProxyV2(context, connection, componentV2);
66         }
67 
68         if (proxyV1 != null && proxyV2 != null) {
69             return new DomainVerificationProxyCombined(proxyV1, proxyV2);
70         }
71 
72         if (proxyV1 != null) {
73             return proxyV1;
74         }
75 
76         if (proxyV2 != null) {
77             return proxyV2;
78         }
79 
80         return new DomainVerificationProxyUnavailable();
81     }
82 
sendBroadcastForPackages(@onNull Set<String> packageNames)83     void sendBroadcastForPackages(@NonNull Set<String> packageNames);
84 
85     /**
86      * Runs a message on the caller's Handler as a result of {@link BaseConnection#schedule(int,
87      * Object)}. Abstracts the actual scheduling/running from the manager class. This is also
88      * necessary so that different what codes can be used depending on the verifier proxy on device,
89      * to allow backporting v1. The backport proxy may schedule more or less messages than the v2
90      * proxy.
91      *
92      * @param messageCode One of the values in {@link DomainVerificationMessageCodes}.
93      * @param object      Arbitrary object that was originally included.
94      */
runMessage(int messageCode, Object object)95     boolean runMessage(int messageCode, Object object);
96 
isCallerVerifier(int callingUid)97     boolean isCallerVerifier(int callingUid);
98 
99     @Nullable
getComponentName()100     ComponentName getComponentName();
101 
102     interface BaseConnection {
103 
104         /**
105          * Schedule something to be run later. The implementation is left up to the caller.
106          *
107          * @param code   One of the values in {@link DomainVerificationMessageCodes}.
108          * @param object Arbitrary object to include with the message.
109          */
schedule(int code, @Nullable Object object)110         void schedule(int code, @Nullable Object object);
111 
getPowerSaveTempWhitelistAppDuration()112         long getPowerSaveTempWhitelistAppDuration();
113 
getDeviceIdleInternal()114         DeviceIdleInternal getDeviceIdleInternal();
115 
isCallerPackage(int callingUid, @NonNull String packageName)116         boolean isCallerPackage(int callingUid, @NonNull String packageName);
117     }
118 }
119