android.media.tv.TvInputInfo Java Examples

The following examples show how to use android.media.tv.TvInputInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public List<TvInputInfo> getTvInputList(int userId) {
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(),
            Binder.getCallingUid(), userId, "getTvInputList");
    final long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            UserState userState = getOrCreateUserStateLocked(resolvedUserId);
            List<TvInputInfo> inputList = new ArrayList<>();
            for (TvInputState state : userState.inputMap.values()) {
                inputList.add(state.info);
            }
            return inputList;
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #2
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void updateTvInputInfo(TvInputInfo inputInfo, int userId) {
    String inputInfoPackageName = inputInfo.getServiceInfo().packageName;
    String callingPackageName = getCallingPackageName();
    if (!TextUtils.equals(inputInfoPackageName, callingPackageName)
            && mContext.checkCallingPermission(
                    android.Manifest.permission.WRITE_SECURE_SETTINGS)
                            != PackageManager.PERMISSION_GRANTED) {
        // Only the app owning the input and system settings are allowed to update info.
        throw new IllegalArgumentException("calling package " + callingPackageName
                + " is not allowed to change TvInputInfo for " + inputInfoPackageName);
    }

    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(),
            Binder.getCallingUid(), userId, "updateTvInputInfo");
    final long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            UserState userState = getOrCreateUserStateLocked(resolvedUserId);
            updateTvInputInfoLocked(userState, inputInfo);
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #3
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public ITvInputHardware acquireTvInputHardware(int deviceId,
        ITvInputHardwareCallback callback, TvInputInfo info, int userId)
        throws RemoteException {
    if (mContext.checkCallingPermission(android.Manifest.permission.TV_INPUT_HARDWARE)
            != PackageManager.PERMISSION_GRANTED) {
        return null;
    }

    final long identity = Binder.clearCallingIdentity();
    final int callingUid = Binder.getCallingUid();
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
            userId, "acquireTvInputHardware");
    try {
        return mTvInputHardwareManager.acquireHardware(
                deviceId, callback, info, callingUid, resolvedUserId);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #4
Source File: TvInputHardwareManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void addHdmiInput(int id, TvInputInfo info) {
    if (info.getType() != TvInputInfo.TYPE_HDMI) {
        throw new IllegalArgumentException("info (" + info + ") has non-HDMI type.");
    }
    synchronized (mLock) {
        String parentId = info.getParentId();
        int parentIndex = indexOfEqualValue(mHardwareInputIdMap, parentId);
        if (parentIndex < 0) {
            throw new IllegalArgumentException("info (" + info + ") has invalid parentId.");
        }
        String oldInputId = mHdmiInputIdMap.get(id);
        if (oldInputId != null) {
            Slog.w(TAG, "Trying to override previous registration: old = "
                    + mInputMap.get(oldInputId) + ":" + id + ", new = "
                    + info + ":" + id);
        }
        mHdmiInputIdMap.put(id, info.getId());
        mInputMap.put(info.getId(), info);
    }
}
 
Example #5
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public TvInputInfo getTvInputInfo(String inputId, int userId) {
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(),
            Binder.getCallingUid(), userId, "getTvInputInfo");
    final long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            UserState userState = getOrCreateUserStateLocked(resolvedUserId);
            TvInputState state = userState.inputMap.get(inputId);
            return state == null ? null : state.info;
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #6
Source File: SetupTvInputProviderActivity.java    From ChannelSurfer with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    displayLayout();
    Log.d(TAG, "Created me");

    info = "";
    if(getIntent() != null) {
        info = getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
        Log.d(TAG, info+"");
    }

    SyncUtils.setUpPeriodicSync(this, info);
    setupTvInputProvider();
}
 
Example #7
Source File: HdmiCecLocalDeviceTv.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onInputAdded(String inputId) {
    TvInputInfo tvInfo = mService.getTvInputManager().getTvInputInfo(inputId);
    if (tvInfo == null) return;
    HdmiDeviceInfo info = tvInfo.getHdmiDeviceInfo();
    if (info == null) return;
    addTvInput(inputId, info.getId());
    if (info.isCecDevice()) {
        processDelayedActiveSource(info.getLogicalAddress());
    }
}
 
Example #8
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void addHdmiInput(int id, TvInputInfo inputInfo) {
    ensureHardwarePermission();
    ensureValidInput(inputInfo);
    synchronized (mLock) {
        mTvInputHardwareManager.addHdmiInput(id, inputInfo);
        addHardwareInputLocked(inputInfo);
    }
}
 
Example #9
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void addHardwareInput(int deviceId, TvInputInfo inputInfo) {
    ensureHardwarePermission();
    ensureValidInput(inputInfo);
    synchronized (mLock) {
        mTvInputHardwareManager.addHardwareInput(deviceId, inputInfo);
        addHardwareInputLocked(inputInfo);
    }
}
 
Example #10
Source File: TvInputHardwareManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void addHardwareInput(int deviceId, TvInputInfo info) {
    synchronized (mLock) {
        String oldInputId = mHardwareInputIdMap.get(deviceId);
        if (oldInputId != null) {
            Slog.w(TAG, "Trying to override previous registration: old = "
                    + mInputMap.get(oldInputId) + ":" + deviceId + ", new = "
                    + info + ":" + deviceId);
        }
        mHardwareInputIdMap.put(deviceId, info.getId());
        mInputMap.put(info.getId(), info);

        // Process pending state changes

        // For logical HDMI devices, they have information from HDMI CEC signals.
        for (int i = 0; i < mHdmiStateMap.size(); ++i) {
            TvInputHardwareInfo hardwareInfo =
                    findHardwareInfoForHdmiPortLocked(mHdmiStateMap.keyAt(i));
            if (hardwareInfo == null) {
                continue;
            }
            String inputId = mHardwareInputIdMap.get(hardwareInfo.getDeviceId());
            if (inputId != null && inputId.equals(info.getId())) {
                // No HDMI hotplug does not necessarily mean disconnected, as old devices may
                // not report hotplug state correctly. Using INPUT_STATE_CONNECTED_STANDBY to
                // denote unknown state.
                int state = mHdmiStateMap.valueAt(i)
                        ? INPUT_STATE_CONNECTED
                        : INPUT_STATE_CONNECTED_STANDBY;
                mHandler.obtainMessage(
                    ListenerHandler.STATE_CHANGED, state, 0, inputId).sendToTarget();
                return;
            }
        }
        // For the rest of the devices, we can tell by the cable connection status.
        Connection connection = mConnections.get(deviceId);
        if (connection != null) {
            mHandler.obtainMessage(ListenerHandler.STATE_CHANGED,
                connection.getInputStateLocked(), 0, info.getId()).sendToTarget();
        }
    }
}
 
Example #11
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void addHardwareInputLocked(TvInputInfo inputInfo) {
    ServiceState serviceState = getServiceStateLocked(mComponent, mUserId);
    serviceState.hardwareInputMap.put(inputInfo.getId(), inputInfo);
    buildTvInputListLocked(mUserId, null);
}
 
Example #12
Source File: TvInputHardwareManager.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public TvInputInfo getInfoLocked() {
    return mInfo;
}
 
Example #13
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void ensureValidInput(TvInputInfo inputInfo) {
    if (inputInfo.getId() == null || !mComponent.equals(inputInfo.getComponent())) {
        throw new IllegalArgumentException("Invalid TvInputInfo");
    }
}
 
Example #14
Source File: ChannelSetupStepFragment.java    From xipl with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}
 
Example #15
Source File: ChannelSetupStepSupportFragment.java    From xipl with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}
 
Example #16
Source File: TvInputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void createSession(final ITvInputClient client, final String inputId,
        boolean isRecordingSession, int seq, int userId) {
    final int callingUid = Binder.getCallingUid();
    final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), callingUid,
            userId, "createSession");
    final long identity = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            if (userId != mCurrentUserId && !isRecordingSession) {
                // A non-recording session of a backgroud (non-current) user
                // should not be created.
                // Let the client get onConnectionFailed callback for this case.
                sendSessionTokenToClientLocked(client, inputId, null, null, seq);
                return;
            }
            UserState userState = getOrCreateUserStateLocked(resolvedUserId);
            TvInputState inputState = userState.inputMap.get(inputId);
            if (inputState == null) {
                Slog.w(TAG, "Failed to find input state for inputId=" + inputId);
                sendSessionTokenToClientLocked(client, inputId, null, null, seq);
                return;
            }
            TvInputInfo info = inputState.info;
            ServiceState serviceState = userState.serviceStateMap.get(info.getComponent());
            if (serviceState == null) {
                serviceState = new ServiceState(info.getComponent(), resolvedUserId);
                userState.serviceStateMap.put(info.getComponent(), serviceState);
            }
            // Send a null token immediately while reconnecting.
            if (serviceState.reconnecting) {
                sendSessionTokenToClientLocked(client, inputId, null, null, seq);
                return;
            }

            // Create a new session token and a session state.
            IBinder sessionToken = new Binder();
            SessionState sessionState = new SessionState(sessionToken, info.getId(),
                    info.getComponent(), isRecordingSession, client, seq, callingUid,
                    resolvedUserId);

            // Add them to the global session state map of the current user.
            userState.sessionStateMap.put(sessionToken, sessionState);

            // Also, add them to the session state map of the current service.
            serviceState.sessionTokens.add(sessionToken);

            if (serviceState.service != null) {
                createSessionInternalLocked(serviceState.service, sessionToken,
                        resolvedUserId);
            } else {
                updateServiceConnectionLocked(info.getComponent(), resolvedUserId);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example #17
Source File: TifSetupFragment.java    From CumulusTV with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}
 
Example #18
Source File: RichSetupFragment.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}
 
Example #19
Source File: ChannelSetupStepFragment.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}
 
Example #20
Source File: ChannelSetupStepSupportFragment.java    From androidtv-sample-inputs with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInputId = getActivity().getIntent().getStringExtra(TvInputInfo.EXTRA_INPUT_ID);
}