1 /* 2 * Copyright (C) 2015 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 android.car.content.pm; 18 19 import static com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport.BOILERPLATE_CODE; 20 21 import android.annotation.SystemApi; 22 import android.car.builtin.os.ParcelHelper; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 26 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 27 28 import java.util.Arrays; 29 30 /** 31 * Contains application blocking policy 32 * @hide 33 */ 34 @SystemApi 35 public final class CarAppBlockingPolicy implements Parcelable { 36 private static final String TAG = CarAppBlockingPolicy.class.getSimpleName(); 37 38 public final AppBlockingPackageInfo[] whitelists; 39 public final AppBlockingPackageInfo[] blacklists; 40 CarAppBlockingPolicy(AppBlockingPackageInfo[] whitelists, AppBlockingPackageInfo[] blacklists)41 public CarAppBlockingPolicy(AppBlockingPackageInfo[] whitelists, 42 AppBlockingPackageInfo[] blacklists) { 43 this.whitelists = whitelists; 44 this.blacklists = blacklists; 45 } 46 CarAppBlockingPolicy(Parcel in)47 public CarAppBlockingPolicy(Parcel in) { 48 byte[] payload = ParcelHelper.readBlob(in); 49 Parcel payloadParcel = Parcel.obtain(); 50 payloadParcel.unmarshall(payload, 0, payload.length); 51 // reset to initial position to read 52 payloadParcel.setDataPosition(0); 53 whitelists = payloadParcel.createTypedArray(AppBlockingPackageInfo.CREATOR); 54 blacklists = payloadParcel.createTypedArray(AppBlockingPackageInfo.CREATOR); 55 payloadParcel.recycle(); 56 } 57 58 @Override 59 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) describeContents()60 public int describeContents() { 61 return 0; 62 } 63 64 @Override writeToParcel(Parcel dest, int flags)65 public void writeToParcel(Parcel dest, int flags) { 66 Parcel payloadParcel = Parcel.obtain(); 67 payloadParcel.writeTypedArray(whitelists, 0); 68 payloadParcel.writeTypedArray(blacklists, 0); 69 byte[] payload = payloadParcel.marshall(); 70 ParcelHelper.writeBlob(dest, payload); 71 payloadParcel.recycle(); 72 } 73 74 public static final Parcelable.Creator<CarAppBlockingPolicy> CREATOR = 75 new Parcelable.Creator<CarAppBlockingPolicy>() { 76 77 @Override 78 public CarAppBlockingPolicy createFromParcel(Parcel in) { 79 return new CarAppBlockingPolicy(in); 80 } 81 82 @Override 83 public CarAppBlockingPolicy[] newArray(int size) { 84 return new CarAppBlockingPolicy[size]; 85 } 86 }; 87 88 @Override hashCode()89 public int hashCode() { 90 final int prime = 31; 91 int result = 1; 92 result = prime * result + Arrays.hashCode(blacklists); 93 result = prime * result + Arrays.hashCode(whitelists); 94 return result; 95 } 96 97 @Override equals(Object obj)98 public boolean equals(Object obj) { 99 if (this == obj) { 100 return true; 101 } 102 if (obj == null) { 103 return false; 104 } 105 if (getClass() != obj.getClass()) { 106 return false; 107 } 108 CarAppBlockingPolicy other = (CarAppBlockingPolicy) obj; 109 if (!Arrays.equals(blacklists, other.blacklists)) { 110 return false; 111 } 112 if (!Arrays.equals(whitelists, other.whitelists)) { 113 return false; 114 } 115 return true; 116 } 117 118 @Override toString()119 public String toString() { 120 return "CarAppBlockingPolicy [whitelists=" + Arrays.toString(whitelists) + ", blacklists=" 121 + Arrays.toString(blacklists) + "]"; 122 } 123 } 124