blob: 9c12e958c2d208a477f243f6ae68191cfb8c58cd [file] [log] [blame]
Michael W2b90a7f2021-01-30 20:39:30 +01001/*
2 * Copyright (C) 2021 The LineageOS Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package org.lineageos.setupwizard;
18
19import android.app.Activity;
20import android.content.ComponentName;
21import android.content.Intent;
22import android.os.Bundle;
23
24import com.google.android.setupcompat.util.WizardManagerHelper;
25
26import org.lineageos.setupwizard.util.SetupWizardUtils;
27
28public class DeviceSpecificActivity extends BaseSetupWizardActivity {
29
30 private static final String ACTION_SETUP_DEVICE = "org.lineageos.settings.device.SUW_SETTINGS";
31 private static final int REQUEST_CODE_SETUP_DEVICE = 90000;
32
33 @Override
34 protected void onCreate(Bundle savedInstanceState) {
35 super.onCreate(savedInstanceState);
36 onStartSubactivity();
37 }
38
39 @Override
40 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
41 if (requestCode == REQUEST_CODE_SETUP_DEVICE) {
42 if (resultCode == RESULT_OK) {
43 goToNextPage();
44 } else {
45 finish();
46 }
47 } else if (resultCode == RESULT_CANCELED) {
48 onStartSubactivity();
49 applyBackwardTransition(TRANSITION_ID_NONE);
50 }
51 }
52
53 @Override
54 protected int getLayoutResId() {
55 return R.layout.setup_device_specific;
56 }
57
58 private void onStartSubactivity() {
59 Intent intent = new Intent(ACTION_SETUP_DEVICE);
60 ComponentName name = intent.resolveActivity(getPackageManager());
61 if (name != null) {
62 applyForwardTransition(TRANSITION_ID_SLIDE);
63 startActivityForResult(intent, REQUEST_CODE_SETUP_DEVICE);
64 } else {
65 SetupWizardUtils.disableComponent(this, DeviceSpecificActivity.class);
66 goToNextPage();
67 finish();
68 }
69 }
70
71 private void goToNextPage() {
72 applyForwardTransition(TRANSITION_ID_SLIDE);
73 Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK);
74 nextAction(NEXT_REQUEST, intent);
75 }
76}