public final class

PackageInfoBuilder

extends java.lang.Object

 java.lang.Object

↳androidx.test.core.content.pm.PackageInfoBuilder

Gradle dependencies

compile group: 'androidx.test', name: 'core', version: '1.4.1-alpha06'

  • groupId: androidx.test
  • artifactId: core
  • version: 1.4.1-alpha06

Artifact androidx.test:core:1.4.1-alpha06 it located at Google repository (https://maven.google.com/)

Overview

Builder for .

Summary

Methods
public PackageInfobuild()

Returns a with the provided data.

public static PackageInfoBuildernewBuilder()

Start building a new .

public PackageInfoBuildersetApplicationInfo(ApplicationInfo applicationInfo)

Sets the application info.

public PackageInfoBuildersetPackageName(java.lang.String packageName)

Sets the package name.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static PackageInfoBuilder newBuilder()

Start building a new .

Returns:

a new instance of PackageInfoBuilder.

public PackageInfoBuilder setPackageName(java.lang.String packageName)

Sets the package name.

Default is null.

See also:

public PackageInfoBuilder setApplicationInfo(ApplicationInfo applicationInfo)

Sets the application info.

Default is null

See also:

public PackageInfo build()

Returns a with the provided data.

Source

/*
 * Copyright (C) 2018 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.test.core.content.pm;

import static androidx.test.internal.util.Checks.checkNotNull;
import static androidx.test.internal.util.Checks.checkState;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import androidx.annotation.Nullable;

/** Builder for {@link PackageInfo}. */
public final class PackageInfoBuilder {
  @Nullable private String packageName;
  @Nullable private ApplicationInfo applicationInfo;

  private PackageInfoBuilder() {}

  /**
   * Start building a new {@link PackageInfo}.
   *
   * @return a new instance of {@link PackageInfoBuilder}.
   */
  public static PackageInfoBuilder newBuilder() {
    return new PackageInfoBuilder();
  }

  /**
   * Sets the package name.
   *
   * <p>Default is {@code null}.
   *
   * @see PackageInfo#packageName
   */
  public PackageInfoBuilder setPackageName(String packageName) {
    this.packageName = packageName;
    return this;
  }

  /**
   * Sets the application info.
   *
   * <p>Default is {@code null}
   *
   * @see PackageInfo#applicationInfo
   */
  public PackageInfoBuilder setApplicationInfo(ApplicationInfo applicationInfo) {
    this.applicationInfo = applicationInfo;
    return this;
  }

  /** Returns a {@link PackageInfo} with the provided data. */
  public PackageInfo build() {
    // Check mandatory fields and correctness.
    checkNotNull(packageName, "Mandatory field 'packageName' missing.");

    PackageInfo packageInfo = new PackageInfo();
    packageInfo.packageName = packageName;

    if (applicationInfo == null) {
      applicationInfo = ApplicationInfoBuilder.newBuilder().setPackageName(packageName).build();
    }
    packageInfo.applicationInfo = applicationInfo;

    checkState(
        packageInfo.packageName.equals(packageInfo.applicationInfo.packageName),
        "Field 'packageName' must match field 'applicationInfo.packageName'");

    return packageInfo;
  }
}