public final class

HostInfo

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.HostInfo

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.2.0-rc01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.2.0-rc01

Artifact androidx.car.app:app:1.2.0-rc01 it located at Google repository (https://maven.google.com/)

Overview

Container class for information about the host the app is connected to.

Apps can use this information to determine how they will respond to the host. For example, a host which is not recognized could receive a message screen while an authorized host could receive full access to the app's capabilities.

The package name and uid can used to query the system package manager for a signature or to determine if the host has a system signature.

The host API level can be used to adjust the models exchanged with the host to those valid for the specific host version the app is connected to.

Summary

Constructors
publicHostInfo(java.lang.String packageName, int uid)

Constructs an instance of the HostInfo from the required package name, UID and API level.

Methods
public java.lang.StringgetPackageName()

Returns the package name of the host.

public intgetUid()

Returns the UID of the host.

public java.lang.StringtoString()

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

Constructors

public HostInfo(java.lang.String packageName, int uid)

Constructs an instance of the HostInfo from the required package name, UID and API level.

Methods

public java.lang.String getPackageName()

Returns the package name of the host.

public int getUid()

Returns the UID of the host.

public java.lang.String toString()

Source

/*
 * 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.car.app;

import static java.util.Objects.requireNonNull;

import androidx.annotation.NonNull;

/**
 * Container class for information about the host the app is connected to.
 *
 * <p>Apps can use this information to determine how they will respond to the host. For example, a
 * host which is not recognized could receive a message screen while an authorized host could
 * receive full access to the app's capabilities.
 *
 * <p>The package name and uid can used to query the system package manager for a signature or to
 * determine if the host has a system signature.
 *
 * <p>The host API level can be used to adjust the models exchanged with the host to those valid
 * for the specific host version the app is connected to.
 */
public final class HostInfo {
    @NonNull
    private final String mPackageName;
    private final int mUid;

    /**
     * Constructs an instance of the HostInfo from the required package name, UID and API level.
     */
    public HostInfo(@NonNull String packageName, int uid) {
        mPackageName = requireNonNull(packageName);
        mUid = uid;
    }

    /** Returns the package name of the host. */
    @NonNull
    public String getPackageName() {
        return mPackageName;
    }

    /** Returns the UID of the host. */
    public int getUid() {
        return mUid;
    }

    @NonNull
    @Override
    public String toString() {
        return mPackageName + ", uid: " + mUid;
    }
}