1 /* 2 * Copyright (C) 2017 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.example.android.autofill.service.model; 18 19 import static com.example.android.autofill.service.data.source.local.DigitalAssetLinksRepository.getCanonicalDomain; 20 21 public class DalInfo { 22 private final String mWebDomain; 23 private final String mPackageName; 24 25 public DalInfo(String webDomain, String packageName) { 26 String canonicalDomain = getCanonicalDomain(webDomain); 27 final String fullDomain; 28 if (!webDomain.startsWith("http:") && !webDomain.startsWith("https:")) { 29 // Unfortunately AssistStructure.ViewNode does not tell what the domain is, so let's 30 // assume it's https 31 fullDomain = "https://" + canonicalDomain; 32 } else { 33 fullDomain = canonicalDomain; 34 } 35 mWebDomain = fullDomain; 36 mPackageName = packageName; 37 } 38 39 public String getWebDomain() { 40 return mWebDomain; 41 } 42 43 public String getPackageName() { 44 return mPackageName; 45 } 46 47 @Override 48 public boolean equals(Object o) { 49 if (this == o) return true; 50 if (o == null || getClass() != o.getClass()) return false; 51 52 DalInfo dalInfo = (DalInfo) o; 53 54 if (mWebDomain != null ? !mWebDomain.equals(dalInfo.mWebDomain) : 55 dalInfo.mWebDomain != null) 56 return false; 57 return mPackageName != null ? mPackageName.equals(dalInfo.mPackageName) : 58 dalInfo.mPackageName == null; 59 } 60 61 @Override 62 public int hashCode() { 63 int result = mWebDomain != null ? mWebDomain.hashCode() : 0; 64 result = 31 * result + (mPackageName != null ? mPackageName.hashCode() : 0); 65 return result; 66 } 67 } 68