Merge "TIF: Minor code improvement" into mnc-dev

This commit is contained in:
Jae Seo
2015-06-22 01:18:04 +00:00
committed by Android (Google) Code Review
9 changed files with 81 additions and 91 deletions

View File

@@ -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<String> 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.
*
* <p>This is a required field if the channel cannot be uniquely identified by a 2-tuple

View File

@@ -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;
}
/**

View File

@@ -1932,7 +1932,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

View File

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

View File

@@ -191,7 +191,7 @@ public class TvView extends ViewGroup {
* the active source.
*
* <p>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
*/

View File

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

View File

@@ -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<Message> mPendingMessageQueue = new LinkedList<Message>();
private final Queue<Message> mPendingMessageQueue = new LinkedList<>();
@Override
public boolean handleMessage(Message msg) {

View File

@@ -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<TvStreamConfig> getAvailableTvStreamConfigList(String inputId, int callingUid,
int resolvedUserId) {
List<TvStreamConfig> configsList = new ArrayList<TvStreamConfig>();
List<TvStreamConfig> 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<AudioDevicePort> sinks) {
sinks.clear();
ArrayList<AudioDevicePort> devicePorts = new ArrayList<AudioDevicePort>();
ArrayList<AudioDevicePort> 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<AudioDevicePort> devicePorts = new ArrayList<AudioDevicePort>();
ArrayList<AudioDevicePort> 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());
}

View File

@@ -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<UserState> mUserStates = new SparseArray<UserState>();
private final SparseArray<UserState> mUserStates = new SparseArray<>();
private final WatchLogHandler mWatchLogHandler;
@@ -231,8 +231,7 @@ public final class TvInputManagerService extends SystemService {
}
}
ArrayList<ContentProviderOperation> operations =
new ArrayList<ContentProviderOperation>();
ArrayList<ContentProviderOperation> 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<TvInputInfo> inputList = new ArrayList<TvInputInfo>();
List<TvInputInfo> 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<String, TvInputState> inputMap = new HashMap<String, TvInputState>();
Map<String, TvInputState> 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<TvInputInfo> inputList = new ArrayList<TvInputInfo>();
List<TvInputInfo> 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<String> ratings = new ArrayList<String>();
List<String> 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<String, TvInputState> inputMap = new HashMap<String, TvInputState>();
private Map<String, TvInputState> inputMap = new HashMap<>();
// A set of all TV input packages.
private final Set<String> packageSet = new HashSet<String>();
private final Set<String> packageSet = new HashSet<>();
// A list of all TV content rating systems defined.
private final List<TvContentRatingSystemInfo>
contentRatingSystemList = new ArrayList<TvContentRatingSystemInfo>();
contentRatingSystemList = new ArrayList<>();
// A mapping from the token of a client to its state.
private final Map<IBinder, ClientState> clientStateMap =
new HashMap<IBinder, ClientState>();
private final Map<IBinder, ClientState> clientStateMap = new HashMap<>();
// A mapping from the name of a TV input service to its state.
private final Map<ComponentName, ServiceState> serviceStateMap =
new HashMap<ComponentName, ServiceState>();
private final Map<ComponentName, ServiceState> serviceStateMap = new HashMap<>();
// A mapping from the token of a TV input session to its state.
private final Map<IBinder, SessionState> sessionStateMap =
new HashMap<IBinder, SessionState>();
private final Map<IBinder, SessionState> sessionStateMap = new HashMap<>();
// A set of callbacks.
private final Set<ITvInputManagerCallback> callbackSet =
new HashSet<ITvInputManagerCallback>();
private final Set<ITvInputManagerCallback> 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<IBinder> sessionTokens = new ArrayList<IBinder>();
private final List<IBinder> 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<IBinder> sessionTokens = new ArrayList<IBinder>();
private final List<IBinder> sessionTokens = new ArrayList<>();
private final ServiceConnection connection;
private final ComponentName component;
private final boolean isHardware;
private final List<TvInputInfo> inputList = new ArrayList<TvInputInfo>();
private final List<TvInputInfo> 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);
}
}
}