From aa5605ffee270ef8802c5d9dc8df8ce71e377f55 Mon Sep 17 00:00:00 2001 From: Jae Seo Date: Sat, 13 Feb 2016 01:38:08 -0800 Subject: [PATCH] TIF: Rename setTvInputInfo to updateTvInputInfo As TvInputInfo includes many complex objects as fields, it is not practical to check whether an existing TvInputInfo has actually "changed" by using simple comparisons when a new TvInputInfo object is set by a TV input service. This code change renames - setTvInputInfo to updateTvInputInfo - onTvInputInfoChanged to onTvInputInfoUpdated to indicate that the callback is mechanically invoked whenever updateTvInputInfo method is called. Change-Id: Ia351b3591d0ed9da962311546f0ba51158e6478e --- api/current.txt | 4 +-- api/system-current.txt | 4 +-- api/test-current.txt | 4 +-- .../android/media/tv/ITvInputManager.aidl | 2 +- .../media/tv/ITvInputManagerCallback.aidl | 4 +-- .../java/android/media/tv/TvInputManager.java | 30 +++++++++++-------- .../java/android/media/tv/TvInputService.java | 28 ++++++++++------- .../server/tv/TvInputManagerService.java | 17 +++++------ 8 files changed, 51 insertions(+), 42 deletions(-) diff --git a/api/current.txt b/api/current.txt index 7fdd5db96f765..ebd26dfc249ff 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22977,7 +22977,7 @@ package android.media.tv { method public void onInputRemoved(java.lang.String); method public void onInputStateChanged(java.lang.String, int); method public void onInputUpdated(java.lang.String); - method public void onTvInputInfoChanged(android.media.tv.TvInputInfo); + method public void onTvInputInfoUpdated(android.media.tv.TvInputInfo); } public abstract class TvInputService extends android.app.Service { @@ -22985,7 +22985,7 @@ package android.media.tv { method public final android.os.IBinder onBind(android.content.Intent); method public android.media.tv.TvInputService.RecordingSession onCreateRecordingSession(java.lang.String); method public abstract android.media.tv.TvInputService.Session onCreateSession(java.lang.String); - method public static final void setTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); + method public static final void updateTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); 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"; } diff --git a/api/system-current.txt b/api/system-current.txt index 266900f917e97..4ffa1536b34a9 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24720,7 +24720,7 @@ package android.media.tv { method public void onInputRemoved(java.lang.String); method public void onInputStateChanged(java.lang.String, int); method public void onInputUpdated(java.lang.String); - method public void onTvInputInfoChanged(android.media.tv.TvInputInfo); + method public void onTvInputInfoUpdated(android.media.tv.TvInputInfo); } public abstract class TvInputService extends android.app.Service { @@ -24732,7 +24732,7 @@ package android.media.tv { method public java.lang.String onHardwareRemoved(android.media.tv.TvInputHardwareInfo); method public android.media.tv.TvInputInfo onHdmiDeviceAdded(android.hardware.hdmi.HdmiDeviceInfo); method public java.lang.String onHdmiDeviceRemoved(android.hardware.hdmi.HdmiDeviceInfo); - method public static final void setTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); + method public static final void updateTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); 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"; } diff --git a/api/test-current.txt b/api/test-current.txt index e940378f12ca0..017971b6b73fa 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -22986,7 +22986,7 @@ package android.media.tv { method public void onInputRemoved(java.lang.String); method public void onInputStateChanged(java.lang.String, int); method public void onInputUpdated(java.lang.String); - method public void onTvInputInfoChanged(android.media.tv.TvInputInfo); + method public void onTvInputInfoUpdated(android.media.tv.TvInputInfo); } public abstract class TvInputService extends android.app.Service { @@ -22994,7 +22994,7 @@ package android.media.tv { method public final android.os.IBinder onBind(android.content.Intent); method public android.media.tv.TvInputService.RecordingSession onCreateRecordingSession(java.lang.String); method public abstract android.media.tv.TvInputService.Session onCreateSession(java.lang.String); - method public static final void setTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); + method public static final void updateTvInputInfo(android.content.Context, android.media.tv.TvInputInfo); 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"; } diff --git a/media/java/android/media/tv/ITvInputManager.aidl b/media/java/android/media/tv/ITvInputManager.aidl index 09d8b64e8dd45..3ec7656dd3f23 100644 --- a/media/java/android/media/tv/ITvInputManager.aidl +++ b/media/java/android/media/tv/ITvInputManager.aidl @@ -41,7 +41,7 @@ import android.view.Surface; interface ITvInputManager { List getTvInputList(int userId); TvInputInfo getTvInputInfo(in String inputId, int userId); - void setTvInputInfo(in TvInputInfo inputInfo, int userId); + void updateTvInputInfo(in TvInputInfo inputInfo, int userId); int getTvInputState(in String inputId, int userId); List getTvContentRatingSystemList(int userId); diff --git a/media/java/android/media/tv/ITvInputManagerCallback.aidl b/media/java/android/media/tv/ITvInputManagerCallback.aidl index 395c9f3b384ed..0f8bf2fb3a1d4 100644 --- a/media/java/android/media/tv/ITvInputManagerCallback.aidl +++ b/media/java/android/media/tv/ITvInputManagerCallback.aidl @@ -26,8 +26,6 @@ oneway interface ITvInputManagerCallback { void onInputAdded(in String inputId); void onInputRemoved(in String inputId); void onInputUpdated(in String inputId); - void onInputStateChanged(in String inputId, int state); - - void onTvInputInfoChanged(in TvInputInfo TvInputInfo); + void onTvInputInfoUpdated(in TvInputInfo TvInputInfo); } diff --git a/media/java/android/media/tv/TvInputManager.java b/media/java/android/media/tv/TvInputManager.java index 00083e6503140..51aae9083fade 100644 --- a/media/java/android/media/tv/TvInputManager.java +++ b/media/java/android/media/tv/TvInputManager.java @@ -727,11 +727,17 @@ public final class TvInputManager { } /** - * This is called when the information about a given TV input has been changed. + * This is called when the information about an existing TV input has been updated. * - * @param inputInfo TvInputInfo object that contains the information about the TV input. + *

Because the system automatically creates a TvInputInfo object for each TV + * input based on the information collected from the AndroidManifest.xml, this + * method is only called back when such information has changed dynamically or when the TV + * input service implementation wants to pass additional information that is not specified + * by the manifest file, such as ability to record and tuner count. + * + * @param inputInfo The TvInputInfo object that contains new information. */ - public void onTvInputInfoChanged(TvInputInfo inputInfo) { + public void onTvInputInfoUpdated(TvInputInfo inputInfo) { } } @@ -784,11 +790,11 @@ public final class TvInputManager { }); } - public void postTvInputInfoChanged(final TvInputInfo inputInfo) { + public void postTvInputInfoUpdated(final TvInputInfo inputInfo) { mHandler.post(new Runnable() { @Override public void run() { - mCallback.onTvInputInfoChanged(inputInfo); + mCallback.onTvInputInfoUpdated(inputInfo); } }); } @@ -1077,10 +1083,10 @@ public final class TvInputManager { } @Override - public void onTvInputInfoChanged(TvInputInfo inputInfo) { + public void onTvInputInfoUpdated(TvInputInfo inputInfo) { synchronized (mLock) { for (TvInputCallbackRecord record : mCallbackRecords) { - record.postTvInputInfoChanged(inputInfo); + record.postTvInputInfoUpdated(inputInfo); } } } @@ -1131,19 +1137,19 @@ public final class TvInputManager { } /** - * Sets a new TvInputInfo object for a given input. + * Updates information about an existing TV input. * *

This is called internally only by {@link TvInputService}. * - * @param inputInfo The TvInputInfo object to set. + * @param inputInfo The TvInputInfo object that contains new information. * @throws IllegalArgumentException if the argument is {@code null}. */ - void setTvInputInfo(@NonNull TvInputInfo inputInfo) { + void updateTvInputInfo(@NonNull TvInputInfo inputInfo) { Preconditions.checkNotNull(inputInfo); try { - mService.setTvInputInfo(inputInfo, mUserId); + mService.updateTvInputInfo(inputInfo, mUserId); } catch (RemoteException e) { - throw new RuntimeException("Error trying to set " + inputInfo, e); + throw new RuntimeException("Error trying to update " + inputInfo, e); } } diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java index 4ebd0fccc5c84..16e1c5c2f64fe 100644 --- a/media/java/android/media/tv/TvInputService.java +++ b/media/java/android/media/tv/TvInputService.java @@ -255,23 +255,31 @@ public abstract class TvInputService extends Service { return null; } - /** - * Sets the TvInputInfo for this TV input. + * Updates the TvInputInfo for an existing TV input. A TV input service + * implementation may call this method to pass the application and system an up-to-date + * TvInputInfo object that describes itself. * - *

The system service automatically creates the TvInputInfo for each TV input based on - * information collected from the AndroidManifest.xml, thus it is not necessary to call this - * method unless the TV input has additional information to pass such as ability to record and - * tuner count. Attempting to change information about a TV input that the calling package does - * not own does nothing. + *

The system automatically creates a TvInputInfo object for each TV input, + * based on the information collected from the AndroidManifest.xml, thus it is not + * necessary to call this method unless such information has changed dynamically. This may be + * also used to pass additional information that is not specified by the manifest file, such as + * ability to record and tuner count. Use {@link TvInputInfo.Builder} to build a new + * TvInputInfo object. + * + *

Attempting to change information about a TV input that the calling package does not own + * does nothing. * * @param context The application context. - * @param inputInfo The TvInputInfo object that contains that new information. + * @param inputInfo The TvInputInfo object that contains new information. + * @see TvInputManager.TvInputCallback#onTvInputInfoUpdated(TvInputInfo) */ - public static final void setTvInputInfo(Context context, TvInputInfo inputInfo) { + public static final void updateTvInputInfo(Context context, TvInputInfo inputInfo) { TvInputManager manager = (TvInputManager) context.getSystemService( Context.TV_INPUT_SERVICE); - manager.setTvInputInfo(inputInfo); + if (manager != null) { + manager.updateTvInputInfo(inputInfo); + } } private boolean isPassthroughInput(String inputId) { diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index c0b4e69adad14..628c6270f1d62 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -769,9 +769,9 @@ public final class TvInputManagerService extends SystemService { } } - private void setTvInputInfoLocked(UserState userState, TvInputInfo inputInfo) { + private void updateTvInputInfoLocked(UserState userState, TvInputInfo inputInfo) { if (DEBUG) { - Slog.d(TAG, "setTvInputInfoLocked(inputInfo=" + inputInfo + ")"); + Slog.d(TAG, "updateTvInputInfoLocked(inputInfo=" + inputInfo + ")"); } String inputId = inputInfo.getId(); TvInputState inputState = userState.inputMap.get(inputId); @@ -779,16 +779,13 @@ public final class TvInputManagerService extends SystemService { Slog.e(TAG, "failed to set input info - unknown input id " + inputId); return; } - if (inputState.info.equals(inputInfo)) { - return; - } inputState.info = inputInfo; for (ITvInputManagerCallback callback : userState.callbackSet) { try { - callback.onTvInputInfoChanged(inputInfo); + callback.onTvInputInfoUpdated(inputInfo); } catch (RemoteException e) { - Slog.e(TAG, "failed to report changed input info to callback", e); + Slog.e(TAG, "failed to report updated input info to callback", e); } } } @@ -845,7 +842,7 @@ public final class TvInputManagerService extends SystemService { } } - public void setTvInputInfo(TvInputInfo inputInfo, int userId) { + public void updateTvInputInfo(TvInputInfo inputInfo, int userId) { String inputInfoPackageName = inputInfo.getServiceInfo().packageName; String callingPackageName = getCallingPackageName(); if (!TextUtils.equals(inputInfoPackageName, callingPackageName)) { @@ -854,12 +851,12 @@ public final class TvInputManagerService extends SystemService { } final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), - Binder.getCallingUid(), userId, "setTvInputInfo"); + Binder.getCallingUid(), userId, "updateTvInputInfo"); final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { UserState userState = getOrCreateUserStateLocked(resolvedUserId); - setTvInputInfoLocked(userState, inputInfo); + updateTvInputInfoLocked(userState, inputInfo); } } finally { Binder.restoreCallingIdentity(identity);