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 61 /** 62 * Whether this cross profile intent filter would allow personal data to be shared into 63 * the work profile. If this is {@code true}, this intent filter should be only added to 64 * the profile if the admin does not enable 65 * {@link android.os.UserManager#DISALLOW_SHARE_INTO_MANAGED_PROFILE}. 66 */ 67 public final boolean letsPersonalDataIntoProfile; 68 CrossProfileIntentFilter(IntentFilter filter, int flags, @Direction int direction, boolean letsPersonalDataIntoProfile)69 private CrossProfileIntentFilter(IntentFilter filter, int flags, @Direction int direction, 70 boolean letsPersonalDataIntoProfile) { 71 this.filter = checkNotNull(filter); 72 this.flags = flags; 73 this.direction = direction; 74 this.letsPersonalDataIntoProfile = letsPersonalDataIntoProfile; 75 } 76 77 static final class Builder { 78 private IntentFilter mFilter = new IntentFilter(); 79 private int mFlags = 0; 80 private @Direction int mDirection; 81 public boolean mLetsPersonalDataIntoProfile; 82 Builder(@irection int direction, int flags, boolean letsPersonalDataIntoProfile)83 public Builder(@Direction int direction, int flags, boolean letsPersonalDataIntoProfile) { 84 mDirection = direction; 85 mFlags = flags; 86 mLetsPersonalDataIntoProfile = letsPersonalDataIntoProfile; 87 } 88 addAction(String action)89 Builder addAction(String action) { 90 mFilter.addAction(action); 91 return this; 92 } 93 addCategory(String category)94 Builder addCategory(String category) { 95 mFilter.addCategory(category); 96 return this; 97 } 98 addDataType(String type)99 Builder addDataType(String type) { 100 try { 101 mFilter.addDataType(type); 102 } catch (IntentFilter.MalformedMimeTypeException e) { 103 // ignore 104 } 105 return this; 106 } 107 addDataScheme(String scheme)108 Builder addDataScheme(String scheme) { 109 mFilter.addDataScheme(scheme); 110 return this; 111 } 112 build()113 CrossProfileIntentFilter build() { 114 return new CrossProfileIntentFilter(mFilter, mFlags, mDirection, 115 mLetsPersonalDataIntoProfile); 116 } 117 } 118 } 119