blob: 26127ee28bcde09aca4814bc7c6b883fabef772e [file] [log] [blame]
cretin45d4cea552016-04-25 11:00:04 -07001/*
Michael Bestasec050052024-02-14 20:35:43 +02002 * SPDX-FileCopyrightText: 2016 The CyanogenMod Project
3 * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
4 * SPDX-License-Identifier: Apache-2.0
cretin45d4cea552016-04-25 11:00:04 -07005 */
6
Michael Bestasc83309e2018-02-03 17:42:13 +02007package org.lineageos.setupwizard;
cretin45d4cea552016-04-25 11:00:04 -07008
Aaron Kling6cb268b2024-03-02 19:14:19 -06009import static com.google.android.setupcompat.util.ResultCodes.RESULT_ACTIVITY_NOT_FOUND;
Oliver Scottddd0c8d2024-07-16 21:25:29 -040010import static com.google.android.setupcompat.util.ResultCodes.RESULT_SKIP;
Aaron Kling6cb268b2024-03-02 19:14:19 -060011
cretin45d4cea552016-04-25 11:00:04 -070012import android.content.Intent;
13import android.util.Log;
14
Aaron Kling6cb268b2024-03-02 19:14:19 -060015import androidx.activity.result.ActivityResult;
16
Michael Bestasc83309e2018-02-03 17:42:13 +020017import org.lineageos.setupwizard.util.SetupWizardUtils;
cretin45d4cea552016-04-25 11:00:04 -070018
Oliver Scottf58c0f42024-01-08 14:52:12 -050019public class BluetoothSetupActivity extends SubBaseActivity {
cretin45d4cea552016-04-25 11:00:04 -070020
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 Scottddd0c8d2024-07-16 21:25:29 -040030 if (!SetupWizardUtils.hasLeanback(this) || SetupWizardUtils.isBluetoothDisabled()) {
31 finishAction(RESULT_SKIP);
32 return;
33 }
cretin45d4cea552016-04-25 11:00:04 -070034 try {
Oliver Scott36163382024-04-11 19:15:50 -040035 Intent intent = new Intent(ACTION_CONNECT_INPUT);
cretin45d4cea552016-04-25 11:00:04 -070036 intent.putExtra(INTENT_EXTRA_NO_INPUT_MODE, true);
Oliver Scottf58c0f42024-01-08 14:52:12 -050037 startSubactivity(intent);
cretin45d4cea552016-04-25 11:00:04 -070038 } catch (Exception e) {
39 Log.e(TAG, "Error starting bluetooth setup", e);
Oliver Scottf58c0f42024-01-08 14:52:12 -050040 finishAction(RESULT_OK);
cretin45d4cea552016-04-25 11:00:04 -070041 SetupWizardUtils.disableComponent(this, BluetoothSetupActivity.class);
cretin45d4cea552016-04-25 11:00:04 -070042 }
43 }
Aaron Kling6cb268b2024-03-02 19:14:19 -060044
45 @Override
Tommy Webb59488092024-07-24 21:26:36 +000046 protected void onSubactivityResult(ActivityResult activityResult) {
Aaron Kling6cb268b2024-03-02 19:14:19 -060047 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 }
cretin45d4cea552016-04-25 11:00:04 -070056}