• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016, 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.managedprovisioning.task;
18 
19 import static com.android.internal.util.Preconditions.checkNotNull;
20 
21 import android.annotation.IntDef;
22 import android.content.IntentFilter;
23 
24 import com.android.internal.annotations.Immutable;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * Representation of a cross-profile intent filter.
31  */
32 @Immutable
33 final class CrossProfileIntentFilter {
34 
35     @IntDef({
36             Direction.TO_PARENT,
37             Direction.TO_PROFILE
38     })
39     @Retention(RetentionPolicy.SOURCE)
40     @interface Direction {
41         int TO_PARENT = 0;
42         int TO_PROFILE = 1;
43     }
44 
45     /** The intent filter that's used */
46     public final IntentFilter filter;
47 
48     /**
49      * The flags related to the forwarding, e.g.
50      * {@link android.content.pm.PackageManager#SKIP_CURRENT_PROFILE} or
51      * {@link android.content.pm.PackageManager#ONLY_IF_NO_MATCH_FOUND}.
52      */
53     public final int flags;
54 
55     /**
56      * The direction of forwarding, can be either {@link Direction#TO_PARENT} or
57      * {@link Direction#TO_PROFILE}.
58      */
59     public final @Direction int direction;
60 
CrossProfileIntentFilter(IntentFilter filter, int flags, @Direction int direction)61     private CrossProfileIntentFilter(IntentFilter filter, int flags, @Direction int direction) {
62         this.filter = checkNotNull(filter);
63         this.flags = flags;
64         this.direction = direction;
65     }
66 
67     static final class Builder {
68         private IntentFilter mFilter = new IntentFilter();
69         private int mFlags = 0;
70         private @Direction int mDirection;
71 
Builder(@irection int direction, int flags)72         public Builder(@Direction int direction, int flags) {
73             mDirection = direction;
74             mFlags = flags;
75         }
76 
addAction(String action)77         Builder addAction(String action) {
78             mFilter.addAction(action);
79             return this;
80         }
81 
addCategory(String category)82         Builder addCategory(String category) {
83             mFilter.addCategory(category);
84             return this;
85         }
86 
addDataType(String type)87         Builder addDataType(String type) {
88             try {
89                 mFilter.addDataType(type);
90             } catch (IntentFilter.MalformedMimeTypeException e) {
91                 // ignore
92             }
93             return this;
94         }
95 
addDataScheme(String scheme)96         Builder addDataScheme(String scheme) {
97             mFilter.addDataScheme(scheme);
98             return this;
99         }
100 
build()101         CrossProfileIntentFilter build() {
102             return new CrossProfileIntentFilter(mFilter, mFlags, mDirection);
103         }
104     }
105 }
106