FileDocCategorySizeDatePackage
TvInputInfo.javaAPI DocAndroid 5.1 API27691Thu Mar 12 22:22:30 GMT 2015android.media.tv

TvInputInfo

public final class TvInputInfo extends Object implements android.os.Parcelable
This class is used to specify meta information of a TV input.

Fields Summary
private static final boolean
DEBUG
private static final String
TAG
public static final int
TYPE_TUNER
TV input type: the TV input service is a tuner which provides channels.
public static final int
TYPE_OTHER
TV input type: a generic hardware TV input type.
public static final int
TYPE_COMPOSITE
TV input type: the TV input service represents a composite port.
public static final int
TYPE_SVIDEO
TV input type: the TV input service represents a SVIDEO port.
public static final int
TYPE_SCART
TV input type: the TV input service represents a SCART port.
public static final int
TYPE_COMPONENT
TV input type: the TV input service represents a component port.
public static final int
TYPE_VGA
TV input type: the TV input service represents a VGA port.
public static final int
TYPE_DVI
TV input type: the TV input service represents a DVI port.
public static final int
TYPE_HDMI
TV input type: the TV input service is HDMI. (e.g. HDMI 1)
public static final int
TYPE_DISPLAY_PORT
TV input type: the TV input service represents a display port.
public static final String
EXTRA_INPUT_ID
The ID of the TV input to provide to the setup activity and settings activity.
private static android.util.SparseIntArray
sHardwareTypeToTvInputType
private static final String
XML_START_TAG_NAME
private static final String
DELIMITER_INFO_IN_ID
private static final String
PREFIX_HDMI_DEVICE
private static final String
PREFIX_HARDWARE_DEVICE
private static final int
LENGTH_HDMI_PHYSICAL_ADDRESS
private static final int
LENGTH_HDMI_DEVICE_ID
private final android.content.pm.ResolveInfo
mService
private final String
mId
private final String
mParentId
private String
mSetupActivity
private String
mSettingsActivity
private int
mType
private android.hardware.hdmi.HdmiDeviceInfo
mHdmiDeviceInfo
private String
mLabel
private android.net.Uri
mIconUri
private boolean
mIsConnectedToHdmiSwitch
public static final Parcelable.Creator
CREATOR
Constructors Summary
private TvInputInfo(android.os.Parcel in)


       
        mId = in.readString();
        mParentId = in.readString();
        mService = ResolveInfo.CREATOR.createFromParcel(in);
        mSetupActivity = in.readString();
        mSettingsActivity = in.readString();
        mType = in.readInt();
        mHdmiDeviceInfo = in.readParcelable(null);
        mIconUri = in.readParcelable(null);
        mLabel = in.readString();
        mIsConnectedToHdmiSwitch = in.readByte() == 1 ? true : false;
    
private TvInputInfo(android.content.pm.ResolveInfo service, String id, String parentId, int type)
Constructor.

param
service The ResolveInfo returned from the package manager about this TV input service.
param
id ID of this TV input. Should be generated via generateInputId*().
param
parentId ID of this TV input's parent input. {@code null} if none exists.
param
type The type of this TV input service.

        mService = service;
        mId = id;
        mParentId = parentId;
        mType = type;
    
Methods Summary
public android.content.IntentcreateSettingsIntent()
Returns an intent to start the settings activity for this TV input.

        if (!TextUtils.isEmpty(mSettingsActivity)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(mService.serviceInfo.packageName, mSettingsActivity);
            intent.putExtra(EXTRA_INPUT_ID, getId());
            return intent;
        }
        return null;
    
public android.content.IntentcreateSetupIntent()
Returns an intent to start the setup activity for this TV input.

        if (!TextUtils.isEmpty(mSetupActivity)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(mService.serviceInfo.packageName, mSetupActivity);
            intent.putExtra(EXTRA_INPUT_ID, getId());
            return intent;
        }
        return null;
    
public static android.media.tv.TvInputInfocreateTvInputInfo(android.content.Context context, android.content.pm.ResolveInfo service)
Create a new instance of the TvInputInfo class, instantiating it from the given Context and ResolveInfo.

param
service The ResolveInfo returned from the package manager about this TV input service.
hide


     
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_OTHER_HARDWARE,
                TYPE_OTHER);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_TUNER, TYPE_TUNER);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_COMPOSITE, TYPE_COMPOSITE);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_SVIDEO, TYPE_SVIDEO);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_SCART, TYPE_SCART);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_COMPONENT, TYPE_COMPONENT);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_VGA, TYPE_VGA);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_DVI, TYPE_DVI);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_HDMI, TYPE_HDMI);
        sHardwareTypeToTvInputType.put(TvInputHardwareInfo.TV_INPUT_TYPE_DISPLAY_PORT,
                TYPE_DISPLAY_PORT);
    
        return createTvInputInfo(context, service, generateInputIdForComponentName(
                new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name)),
                null, TYPE_TUNER, null, null, false);
    
public static android.media.tv.TvInputInfocreateTvInputInfo(android.content.Context context, android.content.pm.ResolveInfo service, android.hardware.hdmi.HdmiDeviceInfo hdmiDeviceInfo, java.lang.String parentId, java.lang.String label, android.net.Uri iconUri)
Create a new instance of the TvInputInfo class, instantiating it from the given Context, ResolveInfo, and HdmiDeviceInfo.

param
service The ResolveInfo returned from the package manager about this TV input service.
param
hdmiDeviceInfo The HdmiDeviceInfo for a HDMI CEC logical device.
param
parentId The ID of this TV input's parent input. {@code null} if none exists.
param
iconUri The {@link android.net.Uri} to load the icon image. See {@link android.content.ContentResolver#openInputStream}. If it is {@code null}, the application icon of {@code service} will be loaded.
param
label The label of this TvInputInfo. If it is {@code null} or empty, {@code service} label will be loaded.
hide

        boolean isConnectedToHdmiSwitch = (hdmiDeviceInfo.getPhysicalAddress() & 0x0FFF) != 0;
        TvInputInfo input = createTvInputInfo(context, service, generateInputIdForHdmiDevice(
                new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name),
                hdmiDeviceInfo), parentId, TYPE_HDMI, label, iconUri, isConnectedToHdmiSwitch);
        input.mHdmiDeviceInfo = hdmiDeviceInfo;
        return input;
    
public static android.media.tv.TvInputInfocreateTvInputInfo(android.content.Context context, android.content.pm.ResolveInfo service, TvInputHardwareInfo hardwareInfo, java.lang.String label, android.net.Uri iconUri)
Create a new instance of the TvInputInfo class, instantiating it from the given Context, ResolveInfo, and TvInputHardwareInfo.

param
service The ResolveInfo returned from the package manager about this TV input service.
param
hardwareInfo The TvInputHardwareInfo for a TV input hardware device.
param
iconUri The {@link android.net.Uri} to load the icon image. See {@link android.content.ContentResolver#openInputStream}. If it is {@code null}, the application icon of {@code service} will be loaded.
param
label The label of this TvInputInfo. If it is {@code null} or empty, {@code service} label will be loaded.
hide

        int inputType = sHardwareTypeToTvInputType.get(hardwareInfo.getType(), TYPE_TUNER);
        return createTvInputInfo(context, service, generateInputIdForHardware(
                new ComponentName(service.serviceInfo.packageName, service.serviceInfo.name),
                hardwareInfo), null, inputType, label, iconUri, false);
    
private static android.media.tv.TvInputInfocreateTvInputInfo(android.content.Context context, android.content.pm.ResolveInfo service, java.lang.String id, java.lang.String parentId, int inputType, java.lang.String label, android.net.Uri iconUri, boolean isConnectedToHdmiSwitch)

        ServiceInfo si = service.serviceInfo;
        PackageManager pm = context.getPackageManager();
        XmlResourceParser parser = null;
        try {
            parser = si.loadXmlMetaData(pm, TvInputService.SERVICE_META_DATA);
            if (parser == null) {
                throw new XmlPullParserException("No " + TvInputService.SERVICE_META_DATA
                        + " meta-data for " + si.name);
            }

            Resources res = pm.getResourcesForApplication(si.applicationInfo);
            AttributeSet attrs = Xml.asAttributeSet(parser);

            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                    && type != XmlPullParser.START_TAG) {
            }

            String nodeName = parser.getName();
            if (!XML_START_TAG_NAME.equals(nodeName)) {
                throw new XmlPullParserException(
                        "Meta-data does not start with tv-input-service tag in " + si.name);
            }

            TvInputInfo input = new TvInputInfo(service, id, parentId, inputType);
            TypedArray sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.TvInputService);
            input.mSetupActivity = sa.getString(
                    com.android.internal.R.styleable.TvInputService_setupActivity);
            if (DEBUG) {
                Log.d(TAG, "Setup activity loaded. [" + input.mSetupActivity + "] for " + si.name);
            }
            if (inputType == TYPE_TUNER && TextUtils.isEmpty(input.mSetupActivity)) {
                throw new XmlPullParserException("Setup activity not found in " + si.name);
            }
            input.mSettingsActivity = sa.getString(
                    com.android.internal.R.styleable.TvInputService_settingsActivity);
            if (DEBUG) {
                Log.d(TAG, "Settings activity loaded. [" + input.mSettingsActivity + "] for "
                        + si.name);
            }
            sa.recycle();

            input.mLabel = label;
            input.mIconUri = iconUri;
            input.mIsConnectedToHdmiSwitch = isConnectedToHdmiSwitch;
            return input;
        } catch (NameNotFoundException e) {
            throw new XmlPullParserException("Unable to create context for: " + si.packageName);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
    
public intdescribeContents()

        return 0;
    
public booleanequals(java.lang.Object o)

        if (o == this) {
            return true;
        }

        if (!(o instanceof TvInputInfo)) {
            return false;
        }

        TvInputInfo obj = (TvInputInfo) o;
        return mId.equals(obj.mId);
    
private static final java.lang.StringgenerateInputIdForComponentName(android.content.ComponentName name)
Used to generate an input id from a ComponentName.

param
name the component name for generating an input id.
return
the generated input id for the given {@code name}.

        return name.flattenToShortString();
    
private static final java.lang.StringgenerateInputIdForHardware(android.content.ComponentName name, TvInputHardwareInfo hardwareInfo)
Used to generate an input id from a ComponentName and TvInputHardwareInfo

param
name the component name for generating an input id.
param
hardwareInfo TvInputHardwareInfo describing this TV input.
return
the generated input id for the given {@code name} and {@code hardwareInfo}.

        return name.flattenToShortString() + String.format("%s%s%d",
                DELIMITER_INFO_IN_ID, PREFIX_HARDWARE_DEVICE, hardwareInfo.getDeviceId());
    
private static final java.lang.StringgenerateInputIdForHdmiDevice(android.content.ComponentName name, android.hardware.hdmi.HdmiDeviceInfo deviceInfo)
Used to generate an input id from a ComponentName and HdmiDeviceInfo.

param
name the component name for generating an input id.
param
deviceInfo HdmiDeviceInfo describing this TV input.
return
the generated input id for the given {@code name} and {@code deviceInfo}.

        // Example of the format : "/HDMI%04X%02X"
        String format = String.format("%s%s%%0%sX%%0%sX", DELIMITER_INFO_IN_ID, PREFIX_HDMI_DEVICE,
                LENGTH_HDMI_PHYSICAL_ADDRESS, LENGTH_HDMI_DEVICE_ID);
        return name.flattenToShortString() + String.format(format,
                deviceInfo.getPhysicalAddress(), deviceInfo.getId());
    
public android.content.ComponentNamegetComponent()
Returns the component of the service that implements this TV input.

hide

        return new ComponentName(mService.serviceInfo.packageName, mService.serviceInfo.name);
    
public android.hardware.hdmi.HdmiDeviceInfogetHdmiDeviceInfo()
Returns the HDMI device information of this TV input.

hide

        if (mType == TYPE_HDMI) {
            return mHdmiDeviceInfo;
        }
        return null;
    
public java.lang.StringgetId()
Returns a unique ID for this TV input. The ID is generated from the package and class name implementing the TV input service.

        return mId;
    
public java.lang.StringgetParentId()
Returns the parent input ID.

A TV input may have a parent input if the TV input is actually a logical representation of a device behind the hardware port represented by the parent input. For example, a HDMI CEC logical device, connected to a HDMI port, appears as another TV input. In this case, the parent input of this logical device is the HDMI port.

Applications may group inputs by parent input ID to provide an easier access to inputs sharing the same physical port. In the example of HDMI CEC, logical HDMI CEC devices behind the same HDMI port have the same parent ID, which is the ID representing the port. Thus applications can group the hardware HDMI port and the logical HDMI CEC devices behind it together using this method.

return
the ID of the parent input, if exists. Returns {@code null} if the parent input is not specified.

        return mParentId;
    
public android.content.pm.ServiceInfogetServiceInfo()
Returns the information of the service that implements this TV input.

        return mService.serviceInfo;
    
public intgetType()
Returns the type of this TV input.

        return mType;
    
public inthashCode()

        return mId.hashCode();
    
public booleanisConnectedToHdmiSwitch()
Returns {@code true}, if a CEC device for this TV input is connected to an HDMI switch, i.e., the device isn't directly connected to a HDMI port.

hide

        return mIsConnectedToHdmiSwitch;
    
public booleanisHidden(android.content.Context context)
Checks if this TV input is marked hidden by the user in the settings.

param
context Supplies a {@link Context} used to check if this TV input is hidden.
return
{@code true} if the user marked this TV input hidden in settings. {@code false} otherwise.
hide

        return TvInputSettings.isHidden(context, mId, UserHandle.myUserId());
    
public booleanisPassthroughInput()
Returns {@code true} if this TV input is pass-though which does not have any real channels in TvProvider. {@code false} otherwise.

see
TvContract#buildChannelUriForPassthroughInput(String)

        return mType != TYPE_TUNER;
    
public java.lang.CharSequenceloadCustomLabel(android.content.Context context)
Loads the custom label set by user in settings.

param
context Supplies a {@link Context} used to load the custom label.
return
a CharSequence containing the TV input's custom label. {@code null} if there is no custom label.
hide

        return TvInputSettings.getCustomLabel(context, mId, UserHandle.myUserId());
    
public android.graphics.drawable.DrawableloadIcon(android.content.Context context)
Loads the user-displayed icon for this TV input.

param
context Supplies a {@link Context} used to load the icon.
return
a Drawable containing the TV input's icon. If the TV input does not have an icon, application's icon is returned. If it's unavailable too, {@code null} is returned.

        if (mIconUri == null) {
            return loadServiceIcon(context);
        }
        try (InputStream is = context.getContentResolver().openInputStream(mIconUri)) {
            Drawable drawable = Drawable.createFromStream(is, null);
            if (drawable == null) {
                return loadServiceIcon(context);
            }
            return drawable;
        } catch (IOException e) {
            Log.w(TAG, "Loading the default icon due to a failure on loading " + mIconUri, e);
            return loadServiceIcon(context);
        }
    
public java.lang.CharSequenceloadLabel(android.content.Context context)
Loads the user-displayed label for this TV input.

param
context Supplies a {@link Context} used to load the label.
return
a CharSequence containing the TV input's label. If the TV input does not have a label, its name is returned.

        if (TextUtils.isEmpty(mLabel)) {
            return mService.loadLabel(context.getPackageManager());
        } else {
            return mLabel;
        }
    
private android.graphics.drawable.DrawableloadServiceIcon(android.content.Context context)

        if (mService.serviceInfo.icon == 0
                && mService.serviceInfo.applicationInfo.icon == 0) {
            return null;
        }
        return mService.serviceInfo.loadIcon(context.getPackageManager());
    
public java.lang.StringtoString()

        return "TvInputInfo{id=" + mId
                + ", pkg=" + mService.serviceInfo.packageName
                + ", service=" + mService.serviceInfo.name + "}";
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Used to package this object into a {@link Parcel}.

param
dest The {@link Parcel} to be written.
param
flags The flags used for parceling.

        dest.writeString(mId);
        dest.writeString(mParentId);
        mService.writeToParcel(dest, flags);
        dest.writeString(mSetupActivity);
        dest.writeString(mSettingsActivity);
        dest.writeInt(mType);
        dest.writeParcelable(mHdmiDeviceInfo, flags);
        dest.writeParcelable(mIconUri, flags);
        dest.writeString(mLabel);
        dest.writeByte(mIsConnectedToHdmiSwitch ? (byte) 1 : 0);