/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appsearch.app;

import androidx.annotation.NonNull;
import androidx.core.util.ObjectsCompat;
import androidx.core.util.Preconditions;

import java.util.Arrays;

/** This class represents a uniquely identifiable package. */
public class PackageIdentifier {
    private final String mPackageName;
    private final byte[] mSha256Certificate;

    /**
     * Creates a unique identifier for a package.
     *
     * @param packageName Name of the package.
     * @param sha256Certificate SHA256 certificate digest of the package.
     */
    public PackageIdentifier(@NonNull String packageName, @NonNull byte[] sha256Certificate) {
        mPackageName = Preconditions.checkNotNull(packageName);
        mSha256Certificate = Preconditions.checkNotNull(sha256Certificate);
    }

    @NonNull
    public String getPackageName() {
        return mPackageName;
    }

    @NonNull
    public byte[] getSha256Certificate() {
        return mSha256Certificate;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || !(obj instanceof PackageIdentifier)) {
            return false;
        }
        final PackageIdentifier other = (PackageIdentifier) obj;
        return this.mPackageName.equals(other.mPackageName)
                && Arrays.equals(this.mSha256Certificate, other.mSha256Certificate);
    }

    @Override
    public int hashCode() {
        return ObjectsCompat.hash(mPackageName, Arrays.hashCode(mSha256Certificate));
    }
}

@@ -643,16 +643,43 @@
 h.app;%0A%0A
+import android.os.Bundle;%0A%0A
 import a
@@ -726,31 +726,72 @@
 idx.
-core.util.ObjectsCompat
+annotation.RestrictTo;%0Aimport androidx.appsearch.util.BundleUtil
 ;%0Aim
@@ -834,34 +834,8 @@
 s;%0A%0A
-import java.util.Arrays;%0A%0A
 /** 
@@ -933,24 +933,31 @@
     private 
+static 
 final String
@@ -957,18 +957,39 @@
  String 
-m
 P
+ACKAGE_NAME_FIELD = %22p
 ackageNa
@@ -986,24 +986,25 @@
 %22packageName
+%22
 ;%0A    privat
@@ -1009,38 +1009,108 @@
 ate 
-final byte%5B%5D mSha256Certificat
+static final String SHA256_CERTIFICATE_FIELD = %22sha256Certificate%22;%0A%0A    private final Bundle mBundl
 e;%0A%0A
@@ -1411,137 +1411,486 @@
    m
-PackageName = Preconditions.checkNotNull(packageName);%0A        mSha256Certificate = Preconditions.checkNotNull(sha256Certificate)
+Bundle = new Bundle();%0A        mBundle.putString(PACKAGE_NAME_FIELD, packageName);%0A        mBundle.putByteArray(SHA256_CERTIFICATE_FIELD, sha256Certificate);%0A    %7D%0A%0A    /** @hide */%0A    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)%0A    public PackageIdentifier(@NonNull Bundle bundle) %7B%0A        mBundle = Preconditions.checkNotNull(bundle);%0A    %7D%0A%0A    /** @hide */%0A    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)%0A    @NonNull%0A    public Bundle getBundle() %7B%0A        return mBundle
 ;%0A  
@@ -1959,28 +1959,81 @@
  return 
-mPackageName
+Preconditions.checkNotNull(mBundle.getString(PACKAGE_NAME_FIELD))
 ;%0A    %7D%0A
@@ -2104,34 +2104,90 @@
  return 
-mSha256Certificate
+Preconditions.checkNotNull(mBundle.getByteArray(SHA256_CERTIFICATE_FIELD))
 ;%0A    %7D%0A
@@ -2489,270 +2489,150 @@
 urn 
-this.mPackageName.equals(other.mPackageName)%0A                && Arrays.equals(this.mSha256Certificate, other.mSha256Certificate);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return ObjectsCompat.hash(mPackageName, Arrays.hashCode(mSha256Certificate)
+BundleUtil.deepEquals(mBundle, other.mBundle);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return BundleUtil.deepHashCode(mBundle
 );%0A 

Make PackageIdentifier bundle-based.