1 /* 2 * Copyright (C) 2023 The Android Open Source 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 17 package com.android.settings.privatespace; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 import androidx.annotation.Nullable; 24 import androidx.fragment.app.FragmentActivity; 25 import androidx.navigation.fragment.NavHostFragment; 26 27 import com.android.settings.R; 28 import com.android.settings.SetupWizardUtils; 29 import com.android.settings.overlay.FeatureFactory; 30 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 31 32 import com.google.android.setupdesign.util.ThemeHelper; 33 34 /** Activity class that helps in setting up of private space */ 35 public class PrivateSpaceSetupActivity extends FragmentActivity { 36 private static final String TAG = "PrivateSpaceSetupAct"; 37 public static final int SET_LOCK_ACTION = 1; 38 public static final int ACCOUNT_LOGIN_ACTION = 2; 39 public static final String EXTRA_ACTION_TYPE = "action_type"; 40 private NavHostFragment mNavHostFragment; 41 private MetricsFeatureProvider mMetricsFeatureProvider; 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 if (!android.os.Flags.allowPrivateProfile() 46 || !android.multiuser.Flags.enablePrivateSpaceFeatures()) { 47 return; 48 } 49 setTheme(SetupWizardUtils.getTheme(this, getIntent())); 50 ThemeHelper.trySetDynamicColor(this); 51 super.onCreate(savedInstanceState); 52 mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); 53 setContentView(R.layout.privatespace_setup_root); 54 mNavHostFragment = 55 (NavHostFragment) 56 getSupportFragmentManager().findFragmentById(R.id.ps_nav_host_fragment); 57 mNavHostFragment.getNavController().setGraph(R.navigation.privatespace_main_context_nav); 58 } 59 60 @Override onActivityResult(int requestCode, int resultCode, @Nullable Intent data)61 protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 62 if (requestCode == SET_LOCK_ACTION && resultCode == RESULT_OK) { 63 mNavHostFragment.getNavController().navigate(R.id.action_pre_finish_delay_fragment); 64 } else if (requestCode == ACCOUNT_LOGIN_ACTION) { 65 if (resultCode == RESULT_OK) { 66 mMetricsFeatureProvider.action( 67 this, SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_ACCOUNT_LOGIN_SUCCESS, true); 68 mNavHostFragment.getNavController().navigate(R.id.show_set_lock_fragment); 69 } else { 70 mMetricsFeatureProvider.action( 71 this, 72 SettingsEnums.ACTION_PRIVATE_SPACE_SETUP_ACCOUNT_LOGIN_SUCCESS, 73 false); 74 mNavHostFragment.getNavController().navigate(R.id.action_advance_login_error); 75 } 76 } 77 super.onActivityResult(requestCode, resultCode, data); 78 } 79 } 80