Example usage for android.content Context TV_INPUT_SERVICE

List of usage examples for android.content Context TV_INPUT_SERVICE

Introduction

In this page you can find the example usage for android.content Context TV_INPUT_SERVICE.

Prototype

String TV_INPUT_SERVICE

To view the source code for android.content Context TV_INPUT_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.media.tv.TvInputManager for interacting with TV inputs on the device.

Usage

From source file:Main.java

public static String getServiceNameFromInputId(Context context, String inputId) {
    TvInputManager tim = (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE);
    for (TvInputInfo info : tim.getTvInputList()) {
        if (info.getId().equals(inputId)) {
            return info.getServiceInfo().name;
        }//from   w w w.j  av a2 s.co  m
    }
    return null;
}

From source file:com.android.tv.dvr.DvrSessionManager.java

public DvrSessionManager(Context context) {
    this(context, (TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE), new Handler());
}

From source file:com.android.tv.settings.MainFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    mAuthenticatorHelper = new AuthenticatorHelper(getContext(), new UserHandle(UserHandle.myUserId()),
            new AuthenticatorHelper.OnAccountsUpdateListener() {
                @Override/*from  w  w  w  . ja  v a2s.co  m*/
                public void onAccountsUpdate(UserHandle userHandle) {
                    updateAccounts();
                }
            });
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
    mConnectivityListener = new ConnectivityListener(getContext(), new ConnectivityListener.Listener() {
        @Override
        public void onConnectivityChange() {
            updateWifi();
        }
    });

    final TvInputManager manager = (TvInputManager) getContext().getSystemService(Context.TV_INPUT_SERVICE);
    if (manager != null) {
        for (final TvInputInfo input : manager.getTvInputList()) {
            if (input.isPassthroughInput()) {
                mInputSettingNeeded = true;
            }
        }
    }
    super.onCreate(savedInstanceState);
}

From source file:com.android.usbtuner.UsbInputController.java

/**
 * Enable/disable the component {@link UsbTunerTvInputService}.
 *
 * @param context {@link Context} instance
 * @param enabled {@code true} to enable the service; otherwise {@code false}
 *///from  w  ww.j a v  a 2  s.c  o  m
private void enableUsbTunerTvInputService(Context context, boolean enabled) {
    PackageManager pm = context.getPackageManager();
    ComponentName USBTUNER = new ComponentName(context, UsbTunerTvInputService.class);

    // Don't kill app by enabling/disabling TvActivity. If LC is killed by enabling/disabling
    // TvActivity, the following pm.setComponentEnabledSetting doesn't work.
    ((TvApplication) context.getApplicationContext()).handleInputCountChanged(true, enabled, true);
    // Since PackageManager.DONT_KILL_APP delays the operation by 10 seconds
    // (PackageManagerService.BROADCAST_DELAY), we'd better avoid using it. It is used only
    // when the LiveChannels app is active since we don't want to kill the running app.
    int flags = TvApplication.getSingletons(context).getMainActivityWrapper().isCreated()
            ? PackageManager.DONT_KILL_APP
            : 0;
    int newState = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (newState != pm.getComponentEnabledSetting(USBTUNER)) {
        // Send/cancel the USB tuner TV input setup recommendation card.
        TunerSetupActivity.onTvInputEnabled(context, enabled);
        // Enable/disable the USB tuner TV input.
        pm.setComponentEnabledSetting(USBTUNER, newState, flags);
        if (DEBUG)
            Log.d(TAG, "Status updated:" + enabled);
    }
    if (enabled && BuildCompat.isAtLeastN()) {
        TvInputInfo info = mDvbDeviceAccessor.buildTvInputInfo(context);
        if (info != null) {
            Log.i(TAG, "TvInputInfo updated: " + info.toString());
            ((TvInputManager) context.getSystemService(Context.TV_INPUT_SERVICE)).updateTvInputInfo(info);
        }
    }
}

From source file:com.android.tv.TvApplication.java

/**
 * Handles the global key KEYCODE_TV_INPUT.
 *//* w  ww .  ja v  a 2  s.c  o m*/
public void handleTvInputKey() {
    TvInputManager tvInputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    List<TvInputInfo> tvInputs = tvInputManager.getTvInputList();
    int inputCount = 0;
    boolean hasTunerInput = false;
    for (TvInputInfo input : tvInputs) {
        if (input.isPassthroughInput()) {
            if (!input.isHidden(this)) {
                ++inputCount;
            }
        } else if (!hasTunerInput) {
            hasTunerInput = true;
            ++inputCount;
        }
    }
    if (inputCount < 2) {
        return;
    }
    Activity activityToHandle = mMainActivityWrapper.isResumed() ? mMainActivityWrapper.getMainActivity()
            : mSelectInputActivity;
    if (activityToHandle != null) {
        // If startActivity is called, MainActivity.onPause is unnecessarily called. To
        // prevent it, MainActivity.dispatchKeyEvent is directly called.
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TV_INPUT));
        activityToHandle.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TV_INPUT));
    } else if (mMainActivityWrapper.isStarted()) {
        Bundle extras = new Bundle();
        extras.putString(Utils.EXTRA_KEY_ACTION, Utils.EXTRA_ACTION_SHOW_TV_INPUT);
        startMainActivity(extras);
    } else {
        startActivity(new Intent(this, SelectInputActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
}

From source file:com.android.tv.TvApplication.java

/**
 * Checks the input counts and enable/disable TvActivity. Also updates the input list in
 * {@link SetupUtils}.//from  ww  w .  j  ava 2s .c om
 *
 * @param calledByTunerServiceChanged true if it is called when UsbTunerTvInputService
 *        is enabled or disabled.
 * @param tunerServiceEnabled it's available only when calledByTunerServiceChanged is true.
 * @param dontKillApp when TvActivity is enabled or disabled by this method, the app restarts
 *        by default. But, if dontKillApp is true, the app won't restart.
 */
public void handleInputCountChanged(boolean calledByTunerServiceChanged, boolean tunerServiceEnabled,
        boolean dontKillApp) {
    TvInputManager inputManager = (TvInputManager) getSystemService(Context.TV_INPUT_SERVICE);
    boolean enable = (calledByTunerServiceChanged && tunerServiceEnabled)
            || Features.UNHIDE.isEnabled(TvApplication.this);
    if (!enable) {
        List<TvInputInfo> inputs = inputManager.getTvInputList();
        boolean skipTunerInputCheck = false;
        // Enable the TvActivity only if there is at least one tuner type input.
        if (!skipTunerInputCheck) {
            for (TvInputInfo input : inputs) {
                if (calledByTunerServiceChanged && !tunerServiceEnabled
                        && UsbTunerTvInputService.getInputId(this).equals(input.getId())) {
                    continue;
                }
                if (input.getType() == TvInputInfo.TYPE_TUNER) {
                    enable = true;
                    break;
                }
            }
        }
        if (DEBUG)
            Log.d(TAG, "Enable MainActivity: " + enable);
    }
    PackageManager packageManager = getPackageManager();
    ComponentName name = new ComponentName(this, TvActivity.class);
    int newState = enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
            : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (packageManager.getComponentEnabledSetting(name) != newState) {
        packageManager.setComponentEnabledSetting(name, newState,
                dontKillApp ? PackageManager.DONT_KILL_APP : 0);
    }
    SetupUtils.getInstance(TvApplication.this).onInputListUpdated(inputManager);
}