| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 1 | /* |
| Michael Bestas | ec05005 | 2024-02-14 20:35:43 +0200 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: 2016 The CyanogenMod Project |
| 3 | * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 7 | package org.lineageos.setupwizard; |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 8 | |
| Aaron Kling | 6cb268b | 2024-03-02 19:14:19 -0600 | [diff] [blame] | 9 | import static com.google.android.setupcompat.util.ResultCodes.RESULT_ACTIVITY_NOT_FOUND; |
| Oliver Scott | ddd0c8d | 2024-07-16 21:25:29 -0400 | [diff] [blame] | 10 | import static com.google.android.setupcompat.util.ResultCodes.RESULT_SKIP; |
| Aaron Kling | 6cb268b | 2024-03-02 19:14:19 -0600 | [diff] [blame] | 11 | |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 12 | import android.content.Intent; |
| 13 | import android.util.Log; |
| 14 | |
| Aaron Kling | 6cb268b | 2024-03-02 19:14:19 -0600 | [diff] [blame] | 15 | import androidx.activity.result.ActivityResult; |
| 16 | |
| Michael Bestas | c83309e | 2018-02-03 17:42:13 +0200 | [diff] [blame] | 17 | import org.lineageos.setupwizard.util.SetupWizardUtils; |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 18 | |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 19 | public class BluetoothSetupActivity extends SubBaseActivity { |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 20 | |
| 21 | public static final String TAG = BluetoothSetupActivity.class.getSimpleName(); |
| 22 | |
| 23 | private static final String ACTION_CONNECT_INPUT = |
| 24 | "com.google.android.intent.action.CONNECT_INPUT"; |
| 25 | |
| 26 | private static final String INTENT_EXTRA_NO_INPUT_MODE = "no_input_mode"; |
| 27 | |
| 28 | @Override |
| 29 | protected void onStartSubactivity() { |
| Oliver Scott | ddd0c8d | 2024-07-16 21:25:29 -0400 | [diff] [blame] | 30 | if (!SetupWizardUtils.hasLeanback(this) || SetupWizardUtils.isBluetoothDisabled()) { |
| 31 | finishAction(RESULT_SKIP); |
| 32 | return; |
| 33 | } |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 34 | try { |
| Oliver Scott | 3616338 | 2024-04-11 19:15:50 -0400 | [diff] [blame] | 35 | Intent intent = new Intent(ACTION_CONNECT_INPUT); |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 36 | intent.putExtra(INTENT_EXTRA_NO_INPUT_MODE, true); |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 37 | startSubactivity(intent); |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 38 | } catch (Exception e) { |
| 39 | Log.e(TAG, "Error starting bluetooth setup", e); |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 40 | finishAction(RESULT_OK); |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 41 | SetupWizardUtils.disableComponent(this, BluetoothSetupActivity.class); |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 42 | } |
| 43 | } |
| Aaron Kling | 6cb268b | 2024-03-02 19:14:19 -0600 | [diff] [blame] | 44 | |
| 45 | @Override |
| Tommy Webb | 5948809 | 2024-07-24 21:26:36 +0000 | [diff] [blame] | 46 | protected void onSubactivityResult(ActivityResult activityResult) { |
| Aaron Kling | 6cb268b | 2024-03-02 19:14:19 -0600 | [diff] [blame] | 47 | Intent data = activityResult.getData(); |
| 48 | if (mIsSubactivityNotFound) { |
| 49 | finishAction(RESULT_ACTIVITY_NOT_FOUND); |
| 50 | } else if (data != null && data.getBooleanExtra("onBackPressed", false)) { |
| 51 | onStartSubactivity(); |
| 52 | } else { |
| 53 | nextAction(RESULT_OK, data); |
| 54 | } |
| 55 | } |
| cretin45 | d4cea55 | 2016-04-25 11:00:04 -0700 | [diff] [blame] | 56 | } |