Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7bb7d6b authored by Chulwoo Lee's avatar Chulwoo Lee
Browse files

Add a way to get the class name of SetupActivity and SettingsActivity

Now, there can be only one SetupActivity and one SettingsActivity for
one TIS apk though one TIS apk can contain several services. Each TIS
need to be able to have its own SetupActivity and SettingsActivity.

BUG: 15177340
Change-Id: I2d944e3ef35c3a981483ba643fd27b15925bab16
parent 0bec6388
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -708,7 +708,6 @@ package android {
    field public static final int l_resource_pad24 = 16843769; // 0x10103f9
    field public static final int l_resource_pad25 = 16843768; // 0x10103f8
    field public static final int l_resource_pad26 = 16843767; // 0x10103f7
    field public static final int l_resource_pad27 = 16843766; // 0x10103f6
    field public static final int l_resource_pad3 = 16843790; // 0x101040e
    field public static final int l_resource_pad4 = 16843789; // 0x101040d
    field public static final int l_resource_pad5 = 16843788; // 0x101040c
@@ -1020,6 +1019,7 @@ package android {
    field public static final int selectedWeekBackgroundColor = 16843586; // 0x1010342
    field public static final int sessionService = 16843841; // 0x1010441
    field public static final int settingsActivity = 16843301; // 0x1010225
    field public static final int setupActivity = 16843766; // 0x10103f6
    field public static final int shadowColor = 16843105; // 0x1010161
    field public static final int shadowDx = 16843106; // 0x1010162
    field public static final int shadowDy = 16843107; // 0x1010163
@@ -15934,10 +15934,13 @@ package android.media.tv {
    method public int describeContents();
    method public android.content.ComponentName getComponent();
    method public java.lang.String getId();
    method public android.content.Intent getIntentForSettingsActivity();
    method public android.content.Intent getIntentForSetupActivity();
    method public java.lang.String getPackageName();
    method public java.lang.String getServiceName();
    method public java.lang.CharSequence loadLabel(android.content.pm.PackageManager);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final java.lang.String EXTRA_SERVICE_NAME = "serviceName";
  }
  public final class TvInputManager {
@@ -15971,6 +15974,7 @@ package android.media.tv {
    method public abstract android.media.tv.TvInputService.TvInputSessionImpl onCreateSession();
    method public final void setAvailable(boolean);
    field public static final java.lang.String SERVICE_INTERFACE = "android.media.tv.TvInputService";
    field public static final java.lang.String SERVICE_META_DATA = "android.media.tv.input";
  }
  public abstract class TvInputService.TvInputSessionImpl implements android.view.KeyEvent.Callback {
+13 −0
Original line number Diff line number Diff line
@@ -6694,4 +6694,17 @@
    <declare-styleable name="EdgeEffect">
        <attr name="colorPrimaryLight" />
    </declare-styleable>

    <!-- Use <code>tv-input</code> as the root tag of the XML resource that describes an
         {@link android.media.tv.TvInputService}, which is referenced from its
         {@link android.media.tv.TvInputService#SERVICE_META_DATA} meta-data entry.
         Described here are the attributes that can be included in that tag. -->
    <declare-styleable name="TvInputService">
        <!-- Component name of an activity for setup of this service.
             The setup includes scanning channels and registering EPG data. -->
        <attr name="setupActivity" format="string" />
        <!-- Component name of an activity that allows the user to modify
             the settings for this service. -->
        <attr name="settingsActivity" />
    </declare-styleable>
</resources>
+1 −0
Original line number Diff line number Diff line
@@ -2096,6 +2096,7 @@
  <public type="attr" name="windowSwipeToDismiss" id="0x10103f3" />
  <public type="attr" name="isGame" id="0x10103f4" />
  <public type="attr" name="allowEmbedded" id="0x10103f5" />
  <public type="attr" name="setupActivity" id="0x10103f6"/>

<!-- ===============================================================
     Resources added in version 21 of the platform
+118 −1
Original line number Diff line number Diff line
@@ -17,26 +17,113 @@
package android.media.tv;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

/**
 * This class is used to specify meta information of a TV input.
 */
public final class TvInputInfo implements Parcelable {
    private static final boolean DEBUG = false;
    private static final String TAG = "TvInputInfo";

    /**
     * The name of the TV input service to provide to the setup activity and settings activity.
     */
    public static final String EXTRA_SERVICE_NAME = "serviceName";

    private static final String XML_START_TAG_NAME = "tv-input";

    private final ResolveInfo mService;
    private final String mId;

    // Attributes from XML meta data.
    private String mSetupActivity;
    private String mSettingsActivity;

    /**
     * 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 */
    public static TvInputInfo createTvInputInfo(Context context, ResolveInfo service)
            throws XmlPullParserException, IOException {
        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(context, service);
            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);
            }
            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();

            return input;
        } catch (NameNotFoundException e) {
            throw new XmlPullParserException("Unable to create context for: " + si.packageName);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
    }

    /**
     * Constructor.
     *
     * @param service The ResolveInfo returned from the package manager about this TV input service.
     * @hide
     */
    public TvInputInfo(ResolveInfo service) {
    private TvInputInfo(Context context, ResolveInfo service) {
        mService = service;
        ServiceInfo si = service.serviceInfo;
        mId = generateInputIdForComponentName(new ComponentName(si.packageName, si.name));
@@ -71,6 +158,32 @@ public final class TvInputInfo implements Parcelable {
        return new ComponentName(mService.serviceInfo.packageName, mService.serviceInfo.name);
    }

    /**
     * Returns an intent to start the setup activity for this TV input service.
     */
    public Intent getIntentForSetupActivity() {
        if (!TextUtils.isEmpty(mSetupActivity)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(getPackageName(), mSetupActivity);
            intent.putExtra(EXTRA_SERVICE_NAME, getServiceName());
            return intent;
        }
        return null;
    }

    /**
     * Returns an intent to start the settings activity for this TV input service.
     */
    public Intent getIntentForSettingsActivity() {
        if (!TextUtils.isEmpty(mSettingsActivity)) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(getPackageName(), mSettingsActivity);
            intent.putExtra(EXTRA_SERVICE_NAME, getServiceName());
            return intent;
        }
        return null;
    }

    /**
     * Loads the user-displayed label for this TV input service.
     *
@@ -125,6 +238,8 @@ public final class TvInputInfo implements Parcelable {
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mId);
        mService.writeToParcel(dest, flags);
        dest.writeString(mSetupActivity);
        dest.writeString(mSettingsActivity);
    }

    /**
@@ -159,5 +274,7 @@ public final class TvInputInfo implements Parcelable {
    private TvInputInfo(Parcel in) {
        mId = in.readString();
        mService = ResolveInfo.CREATOR.createFromParcel(in);
        mSetupActivity = in.readString();
        mSettingsActivity = in.readString();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -62,6 +62,14 @@ public abstract class TvInputService extends Service {
     */
    public static final String SERVICE_INTERFACE = "android.media.tv.TvInputService";

    /**
     * Name under which a TvInputService component publishes information about itself.
     * This meta-data must reference an XML resource containing an
     * <code>&lt;{@link android.R.styleable#TvInputService tv-input}&gt;</code>
     * tag.
     */
    public static final String SERVICE_META_DATA = "android.media.tv.input";

    private String mId;
    private final Handler mHandler = new ServiceHandler();
    private final RemoteCallbackList<ITvInputServiceCallback> mCallbacks =
Loading