From 6e4cbfd2e5ffb739269e5e4affc2b6894bc4090e Mon Sep 17 00:00:00 2001 From: Jae Seo Date: Sun, 21 Jun 2015 16:40:34 -0700 Subject: [PATCH] TIF: Minor code improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Removed unnecessary 'final' keywords for private methods - Removed unnecessary interface modifiers - Added a missing ‘final’ keyword - Simplified if statements - Removed Javadoc links pointing to itself - Removed redundant conditional expressions - Removed unnecessary return statements - Replaced explicit types with <> - Removed an unnecessary unboxing - Removed a redundant initializer - Fixed typos Change-Id: I1d137fda70192b33dd00e92ab01396519135ab39 --- media/java/android/media/tv/TvContract.java | 6 +- media/java/android/media/tv/TvInputInfo.java | 12 ++-- .../java/android/media/tv/TvInputManager.java | 2 +- .../java/android/media/tv/TvInputService.java | 19 +++--- media/java/android/media/tv/TvView.java | 2 +- .../server/tv/PersistentDataStore.java | 4 +- .../com/android/server/tv/TvInputHal.java | 11 ++- .../server/tv/TvInputHardwareManager.java | 68 +++++++++---------- .../server/tv/TvInputManagerService.java | 48 ++++++------- 9 files changed, 81 insertions(+), 91 deletions(-) diff --git a/media/java/android/media/tv/TvContract.java b/media/java/android/media/tv/TvContract.java index a06f8483b7c6c..da5f33e4352c6 100644 --- a/media/java/android/media/tv/TvContract.java +++ b/media/java/android/media/tv/TvContract.java @@ -282,12 +282,12 @@ public final class TvContract { return ContentUris.withAppendedId(WatchedPrograms.CONTENT_URI, watchedProgramId); } - private static final boolean isTvUri(Uri uri) { + private static boolean isTvUri(Uri uri) { return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && AUTHORITY.equals(uri.getAuthority()); } - private static final boolean isTwoSegmentUriStartingWith(Uri uri, String pathSegment) { + private static boolean isTwoSegmentUriStartingWith(Uri uri, String pathSegment) { List pathSegments = uri.getPathSegments(); return pathSegments.size() == 2 && pathSegment.equals(pathSegments.get(0)); } @@ -565,7 +565,7 @@ public final class TvContract { * defined there (e.g. ETSI EN 300 468/TR 101 211 and ARIB STD-B10). If channels cannot be * globally identified by 2-tuple {{@link #COLUMN_TRANSPORT_STREAM_ID}, * {@link #COLUMN_SERVICE_ID}}, one must carefully assign a value to this field to form a - * unique 3-tuple identification {{@link #COLUMN_ORIGINAL_NETWORK_ID}, + * unique 3-tuple identification {{@code COLUMN_ORIGINAL_NETWORK_ID}, * {@link #COLUMN_TRANSPORT_STREAM_ID}, {@link #COLUMN_SERVICE_ID}} for its channels. * *

This is a required field if the channel cannot be uniquely identified by a 2-tuple diff --git a/media/java/android/media/tv/TvInputInfo.java b/media/java/android/media/tv/TvInputInfo.java index 5d1aa149aa647..ce72c2fa4a25d 100644 --- a/media/java/android/media/tv/TvInputInfo.java +++ b/media/java/android/media/tv/TvInputInfo.java @@ -106,7 +106,7 @@ public final class TvInputInfo implements Parcelable { */ public static final String EXTRA_INPUT_ID = "android.media.tv.extra.INPUT_ID"; - private static SparseIntArray sHardwareTypeToTvInputType = new SparseIntArray(); + private static final SparseIntArray sHardwareTypeToTvInputType = new SparseIntArray(); private static final String XML_START_TAG_NAME = "tv-input"; private static final String DELIMITER_INFO_IN_ID = "/"; @@ -594,7 +594,7 @@ public final class TvInputInfo implements Parcelable { * @param name the component name for generating an input id. * @return the generated input id for the given {@code name}. */ - private static final String generateInputIdForComponentName(ComponentName name) { + private static String generateInputIdForComponentName(ComponentName name) { return name.flattenToShortString(); } @@ -605,7 +605,7 @@ public final class TvInputInfo implements Parcelable { * @param deviceInfo HdmiDeviceInfo describing this TV input. * @return the generated input id for the given {@code name} and {@code deviceInfo}. */ - private static final String generateInputIdForHdmiDevice( + private static String generateInputIdForHdmiDevice( ComponentName name, HdmiDeviceInfo deviceInfo) { // Example of the format : "/HDMI%04X%02X" String format = DELIMITER_INFO_IN_ID + PREFIX_HDMI_DEVICE @@ -622,7 +622,7 @@ public final class TvInputInfo implements Parcelable { * @param hardwareInfo TvInputHardwareInfo describing this TV input. * @return the generated input id for the given {@code name} and {@code hardwareInfo}. */ - private static final String generateInputIdForHardware( + private static String generateInputIdForHardware( ComponentName name, TvInputHardwareInfo hardwareInfo) { return name.flattenToShortString() + DELIMITER_INFO_IN_ID + PREFIX_HARDWARE_DEVICE + hardwareInfo.getDeviceId(); @@ -648,13 +648,13 @@ public final class TvInputInfo implements Parcelable { mSetupActivity = in.readString(); mSettingsActivity = in.readString(); mType = in.readInt(); - mIsHardwareInput = in.readByte() == 1 ? true : false; + mIsHardwareInput = in.readByte() == 1; mHdmiDeviceInfo = in.readParcelable(null); mIcon = in.readParcelable(null); mIconUri = in.readParcelable(null); mLabelRes = in.readInt(); mLabel = in.readString(); - mIsConnectedToHdmiSwitch = in.readByte() == 1 ? true : false; + mIsConnectedToHdmiSwitch = in.readByte() == 1; } /** diff --git a/media/java/android/media/tv/TvInputManager.java b/media/java/android/media/tv/TvInputManager.java index 38f2d04763ee3..eea607cfe70e6 100644 --- a/media/java/android/media/tv/TvInputManager.java +++ b/media/java/android/media/tv/TvInputManager.java @@ -1929,7 +1929,7 @@ public final class TvInputManager { * @param handled {@code true} if the dispatched input event was handled properly. * {@code false} otherwise. */ - public void onFinishedInputEvent(Object token, boolean handled); + void onFinishedInputEvent(Object token, boolean handled); } // Must be called on the main looper diff --git a/media/java/android/media/tv/TvInputService.java b/media/java/android/media/tv/TvInputService.java index f52ccc9bb334a..35037bbe18f4b 100644 --- a/media/java/android/media/tv/TvInputService.java +++ b/media/java/android/media/tv/TvInputService.java @@ -233,10 +233,7 @@ public abstract class TvInputService extends Service { mTvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE); } TvInputInfo info = mTvInputManager.getTvInputInfo(inputId); - if (info != null && info.isPassthroughInput()) { - return true; - } - return false; + return info != null && info.isPassthroughInput(); } /** @@ -1383,7 +1380,7 @@ public abstract class TvInputService extends Service { } } - private final void executeOrPostRunnable(Runnable action) { + private void executeOrPostRunnable(Runnable action) { synchronized(mLock) { if (mSessionCallback == null) { // The session is not initialized yet. @@ -1651,13 +1648,13 @@ public abstract class TvInputService extends Service { if (sessionImpl instanceof HardwareSession) { HardwareSession proxySession = ((HardwareSession) sessionImpl); - String harewareInputId = proxySession.getHardwareInputId(); - if (TextUtils.isEmpty(harewareInputId) || - !isPassthroughInput(harewareInputId)) { - if (TextUtils.isEmpty(harewareInputId)) { + String hardwareInputId = proxySession.getHardwareInputId(); + if (TextUtils.isEmpty(hardwareInputId) || + !isPassthroughInput(hardwareInputId)) { + if (TextUtils.isEmpty(hardwareInputId)) { Log.w(TAG, "Hardware input id is not setup yet."); } else { - Log.w(TAG, "Invalid hardware input id : " + harewareInputId); + Log.w(TAG, "Invalid hardware input id : " + hardwareInputId); } sessionImpl.onRelease(); try { @@ -1672,7 +1669,7 @@ public abstract class TvInputService extends Service { proxySession.mServiceHandler = mServiceHandler; TvInputManager manager = (TvInputManager) getSystemService( Context.TV_INPUT_SERVICE); - manager.createSession(harewareInputId, + manager.createSession(hardwareInputId, proxySession.mHardwareSessionCallback, mServiceHandler); } else { SomeArgs someArgs = SomeArgs.obtain(); diff --git a/media/java/android/media/tv/TvView.java b/media/java/android/media/tv/TvView.java index d8d0bdc8a44eb..64333ad6e8f95 100644 --- a/media/java/android/media/tv/TvView.java +++ b/media/java/android/media/tv/TvView.java @@ -191,7 +191,7 @@ public class TvView extends ViewGroup { * the active source. * *

First tuned {@link TvView} becomes main automatically, and keeps to be main until either - * {@link #reset} is called for the main {@link TvView} or {@link #setMain} is called for other + * {@link #reset} is called for the main {@link TvView} or {@code setMain()} is called for other * {@link TvView}. * @hide */ diff --git a/services/core/java/com/android/server/tv/PersistentDataStore.java b/services/core/java/com/android/server/tv/PersistentDataStore.java index f9b5b9a4440d2..f6b17059b9349 100644 --- a/services/core/java/com/android/server/tv/PersistentDataStore.java +++ b/services/core/java/com/android/server/tv/PersistentDataStore.java @@ -111,8 +111,8 @@ final class PersistentDataStore { public boolean isRatingBlocked(TvContentRating rating) { loadIfNeeded(); synchronized (mBlockedRatings) { - for (TvContentRating blcokedRating : mBlockedRatings) { - if (rating.contains(blcokedRating)) { + for (TvContentRating blockedRating : mBlockedRatings) { + if (rating.contains(blockedRating)) { return true; } } diff --git a/services/core/java/com/android/server/tv/TvInputHal.java b/services/core/java/com/android/server/tv/TvInputHal.java index de271b8fffa47..a035826c770d1 100644 --- a/services/core/java/com/android/server/tv/TvInputHal.java +++ b/services/core/java/com/android/server/tv/TvInputHal.java @@ -47,11 +47,10 @@ final class TvInputHal implements Handler.Callback { public static final int EVENT_FIRST_FRAME_CAPTURED = 4; public interface Callback { - public void onDeviceAvailable( - TvInputHardwareInfo info, TvStreamConfig[] configs); - public void onDeviceUnavailable(int deviceId); - public void onStreamConfigurationChanged(int deviceId, TvStreamConfig[] configs); - public void onFirstFrameCaptured(int deviceId, int streamId); + void onDeviceAvailable(TvInputHardwareInfo info, TvStreamConfig[] configs); + void onDeviceUnavailable(int deviceId); + void onStreamConfigurationChanged(int deviceId, TvStreamConfig[] configs); + void onFirstFrameCaptured(int deviceId, int streamId); } private native long nativeOpen(MessageQueue queue); @@ -152,7 +151,7 @@ final class TvInputHal implements Handler.Callback { // Handler.Callback implementation - private final Queue mPendingMessageQueue = new LinkedList(); + private final Queue mPendingMessageQueue = new LinkedList<>(); @Override public boolean handleMessage(Message msg) { diff --git a/services/core/java/com/android/server/tv/TvInputHardwareManager.java b/services/core/java/com/android/server/tv/TvInputHardwareManager.java index 8d2ff35b7b477..7f4c42b5c6867 100644 --- a/services/core/java/com/android/server/tv/TvInputHardwareManager.java +++ b/services/core/java/com/android/server/tv/TvInputHardwareManager.java @@ -252,13 +252,8 @@ class TvInputHardwareManager implements TvInputHal.Callback { Connection connection, int callingUid, int resolvedUserId) { Integer connectionCallingUid = connection.getCallingUidLocked(); Integer connectionResolvedUserId = connection.getResolvedUserIdLocked(); - if (connectionCallingUid == null || connectionResolvedUserId == null) { - return true; - } - if (connectionCallingUid != callingUid || connectionResolvedUserId != resolvedUserId) { - return true; - } - return false; + return connectionCallingUid == null || connectionResolvedUserId == null + || connectionCallingUid != callingUid || connectionResolvedUserId != resolvedUserId; } private int convertConnectedToState(boolean connected) { @@ -303,7 +298,6 @@ class TvInputHardwareManager implements TvInputHal.Callback { mHandler.obtainMessage(ListenerHandler.STATE_CHANGED, convertConnectedToState(connection.getConfigsLocked().length > 0), 0, info.getId()).sendToTarget(); - return; } } } @@ -435,7 +429,7 @@ class TvInputHardwareManager implements TvInputHal.Callback { */ public List getAvailableTvStreamConfigList(String inputId, int callingUid, int resolvedUserId) { - List configsList = new ArrayList(); + List configsList = new ArrayList<>(); synchronized (mLock) { int deviceId = findDeviceIdForInputIdLocked(inputId); if (deviceId < 0) { @@ -508,25 +502,31 @@ class TvInputHardwareManager implements TvInputHal.Callback { private void handleVolumeChange(Context context, Intent intent) { String action = intent.getAction(); - if (action.equals(AudioManager.VOLUME_CHANGED_ACTION)) { - int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); - if (streamType != AudioManager.STREAM_MUSIC) { - return; + switch (action) { + case AudioManager.VOLUME_CHANGED_ACTION: { + int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); + if (streamType != AudioManager.STREAM_MUSIC) { + return; + } + int index = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); + if (index == mCurrentIndex) { + return; + } + mCurrentIndex = index; + break; } - int index = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0); - if (index == mCurrentIndex) { - return; + case AudioManager.STREAM_MUTE_CHANGED_ACTION: { + int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); + if (streamType != AudioManager.STREAM_MUSIC) { + return; + } + // volume index will be updated at onMediaStreamVolumeChanged() through + // updateVolume(). + break; } - mCurrentIndex = index; - } else if (action.equals(AudioManager.STREAM_MUTE_CHANGED_ACTION)) { - int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1); - if (streamType != AudioManager.STREAM_MUSIC) { + default: + Slog.w(TAG, "Unrecognized intent: " + intent); return; - } - // volume index will be updated at onMediaStreamVolumeChanged() through updateVolume(). - } else { - Slog.w(TAG, "Unrecognized intent: " + intent); - return; } synchronized (mLock) { for (int i = 0; i < mConnections.size(); ++i) { @@ -691,7 +691,7 @@ class TvInputHardwareManager implements TvInputHal.Callback { private void findAudioSinkFromAudioPolicy(List sinks) { sinks.clear(); - ArrayList devicePorts = new ArrayList(); + ArrayList devicePorts = new ArrayList<>(); if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { return; } @@ -707,7 +707,7 @@ class TvInputHardwareManager implements TvInputHal.Callback { if (type == AudioManager.DEVICE_NONE) { return null; } - ArrayList devicePorts = new ArrayList(); + ArrayList devicePorts = new ArrayList<>(); if (mAudioManager.listAudioDevicePorts(devicePorts) != AudioManager.SUCCESS) { return null; } @@ -1027,12 +1027,12 @@ class TvInputHardwareManager implements TvInputHal.Callback { } interface Listener { - public void onStateChanged(String inputId, int state); - public void onHardwareDeviceAdded(TvInputHardwareInfo info); - public void onHardwareDeviceRemoved(TvInputHardwareInfo info); - public void onHdmiDeviceAdded(HdmiDeviceInfo device); - public void onHdmiDeviceRemoved(HdmiDeviceInfo device); - public void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo device); + void onStateChanged(String inputId, int state); + void onHardwareDeviceAdded(TvInputHardwareInfo info); + void onHardwareDeviceRemoved(TvInputHardwareInfo info); + void onHdmiDeviceAdded(HdmiDeviceInfo device); + void onHdmiDeviceRemoved(HdmiDeviceInfo device); + void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo device); } private class ListenerHandler extends Handler { @@ -1074,7 +1074,7 @@ class TvInputHardwareManager implements TvInputHal.Callback { } case HDMI_DEVICE_UPDATED: { HdmiDeviceInfo info = (HdmiDeviceInfo) msg.obj; - String inputId = null; + String inputId; synchronized (mLock) { inputId = mHdmiInputIdMap.get(info.getId()); } diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java index 8f32510896918..f5c5861a0ebd8 100644 --- a/services/core/java/com/android/server/tv/TvInputManagerService.java +++ b/services/core/java/com/android/server/tv/TvInputManagerService.java @@ -121,7 +121,7 @@ public final class TvInputManagerService extends SystemService { private int mCurrentUserId = UserHandle.USER_OWNER; // A map from user id to UserState. - private final SparseArray mUserStates = new SparseArray(); + private final SparseArray mUserStates = new SparseArray<>(); private final WatchLogHandler mWatchLogHandler; @@ -231,8 +231,7 @@ public final class TvInputManagerService extends SystemService { } } - ArrayList operations = - new ArrayList(); + ArrayList operations = new ArrayList<>(); String selection = TvContract.BaseTvColumns.COLUMN_PACKAGE_NAME + "=?"; String[] selectionArgs = { packageName }; @@ -292,7 +291,7 @@ public final class TvInputManagerService extends SystemService { new Intent(TvInputService.SERVICE_INTERFACE), PackageManager.GET_SERVICES | PackageManager.GET_META_DATA, userId); - List inputList = new ArrayList(); + List inputList = new ArrayList<>(); for (ResolveInfo ri : services) { ServiceInfo si = ri.serviceInfo; if (!android.Manifest.permission.BIND_TV_INPUT.equals(si.permission)) { @@ -325,7 +324,7 @@ public final class TvInputManagerService extends SystemService { userState.packageSet.add(si.packageName); } - Map inputMap = new HashMap(); + Map inputMap = new HashMap<>(); for (TvInputInfo info : inputList) { if (DEBUG) { Slog.d(TAG, "add " + info.getId()); @@ -777,7 +776,7 @@ public final class TvInputManagerService extends SystemService { try { synchronized (mLock) { UserState userState = getUserStateLocked(resolvedUserId); - List inputList = new ArrayList(); + List inputList = new ArrayList<>(); for (TvInputState state : userState.inputMap.values()) { inputList.add(state.info); } @@ -934,7 +933,7 @@ public final class TvInputManagerService extends SystemService { try { synchronized (mLock) { UserState userState = getUserStateLocked(resolvedUserId); - List ratings = new ArrayList(); + List ratings = new ArrayList<>(); for (TvContentRating rating : userState.persistentDataStore.getBlockedRatings()) { ratings.add(rating.flattenToString()); @@ -1012,7 +1011,7 @@ public final class TvInputManagerService extends SystemService { userState.serviceStateMap.put(info.getComponent(), serviceState); } // Send a null token immediately while reconnecting. - if (serviceState.reconnecting == true) { + if (serviceState.reconnecting) { sendSessionTokenToClientLocked(client, inputId, null, null, seq); return; } @@ -1210,7 +1209,6 @@ public final class TvInputManagerService extends SystemService { .sendToTarget(); } catch (RemoteException | SessionNotFoundException e) { Slog.e(TAG, "error in tune", e); - return; } } } finally { @@ -1799,30 +1797,26 @@ public final class TvInputManagerService extends SystemService { private static final class UserState { // A mapping from the TV input id to its TvInputState. - private Map inputMap = new HashMap(); + private Map inputMap = new HashMap<>(); // A set of all TV input packages. - private final Set packageSet = new HashSet(); + private final Set packageSet = new HashSet<>(); // A list of all TV content rating systems defined. private final List - contentRatingSystemList = new ArrayList(); + contentRatingSystemList = new ArrayList<>(); // A mapping from the token of a client to its state. - private final Map clientStateMap = - new HashMap(); + private final Map clientStateMap = new HashMap<>(); // A mapping from the name of a TV input service to its state. - private final Map serviceStateMap = - new HashMap(); + private final Map serviceStateMap = new HashMap<>(); // A mapping from the token of a TV input session to its state. - private final Map sessionStateMap = - new HashMap(); + private final Map sessionStateMap = new HashMap<>(); // A set of callbacks. - private final Set callbackSet = - new HashSet(); + private final Set callbackSet = new HashSet<>(); // The token of a "main" TV input session. private IBinder mainSessionToken = null; @@ -1837,7 +1831,7 @@ public final class TvInputManagerService extends SystemService { } private final class ClientState implements IBinder.DeathRecipient { - private final List sessionTokens = new ArrayList(); + private final List sessionTokens = new ArrayList<>(); private IBinder clientToken; private final int userId; @@ -1870,11 +1864,11 @@ public final class TvInputManagerService extends SystemService { } private final class ServiceState { - private final List sessionTokens = new ArrayList(); + private final List sessionTokens = new ArrayList<>(); private final ServiceConnection connection; private final ComponentName component; private final boolean isHardware; - private final List inputList = new ArrayList(); + private final List inputList = new ArrayList<>(); private ITvInputService service; private ServiceCallback callback; @@ -2124,13 +2118,13 @@ public final class TvInputManagerService extends SystemService { } @Override - public void onSessionCreated(ITvInputSession session, IBinder harewareSessionToken) { + public void onSessionCreated(ITvInputSession session, IBinder hardwareSessionToken) { if (DEBUG) { Slog.d(TAG, "onSessionCreated(inputId=" + mSessionState.info.getId() + ")"); } synchronized (mLock) { mSessionState.session = session; - mSessionState.hardwareSessionToken = harewareSessionToken; + mSessionState.hardwareSessionToken = hardwareSessionToken; if (session != null && addSessionTokenToClientStateLocked(session)) { sendSessionTokenToClientLocked(mSessionState.client, mSessionState.info.getId(), mSessionState.sessionToken, mChannels[0], @@ -2558,7 +2552,7 @@ public final class TvInputManagerService extends SystemService { @Override public void onHdmiDeviceUpdated(String inputId, HdmiDeviceInfo deviceInfo) { synchronized (mLock) { - Integer state = null; + Integer state; switch (deviceInfo.getDevicePowerStatus()) { case HdmiControlManager.POWER_STATUS_ON: state = INPUT_STATE_CONNECTED; @@ -2574,7 +2568,7 @@ public final class TvInputManagerService extends SystemService { break; } if (state != null) { - setStateLocked(inputId, state.intValue(), mCurrentUserId); + setStateLocked(inputId, state, mCurrentUserId); } } }