Merge "Add a way to get the class name of SetupActivity and SettingsActivity" into lmp-preview-dev

This commit is contained in:
Chulwoo Lee
2014-06-02 23:59:55 +00:00
committed by Android (Google) Code Review
6 changed files with 158 additions and 6 deletions

View File

@@ -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
@@ -15929,10 +15929,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 {
@@ -15966,6 +15969,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 {

View File

@@ -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>

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -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 =

View File

@@ -63,6 +63,10 @@ import com.android.internal.os.SomeArgs;
import com.android.server.IoThread;
import com.android.server.SystemService;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -145,7 +149,8 @@ public final class TvInputManagerService extends SystemService {
if (DEBUG) Slog.d(TAG, "buildTvInputList");
PackageManager pm = mContext.getPackageManager();
List<ResolveInfo> services = pm.queryIntentServices(
new Intent(TvInputService.SERVICE_INTERFACE), PackageManager.GET_SERVICES);
new Intent(TvInputService.SERVICE_INTERFACE),
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
for (ResolveInfo ri : services) {
ServiceInfo si = ri.serviceInfo;
if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) {
@@ -153,9 +158,13 @@ public final class TvInputManagerService extends SystemService {
+ android.Manifest.permission.BIND_TV_INPUT);
continue;
}
TvInputInfo info = new TvInputInfo(ri);
if (DEBUG) Slog.d(TAG, "add " + info.getId());
userState.inputMap.put(info.getId(), info);
try {
TvInputInfo info = TvInputInfo.createTvInputInfo(mContext, ri);
if (DEBUG) Slog.d(TAG, "add " + info.getId());
userState.inputMap.put(info.getId(), info);
} catch (IOException | XmlPullParserException e) {
Slog.e(TAG, "Can't load TV input " + si.name, e);
}
}
}