• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.applications.credentials;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.os.UserHandle;
23 import android.os.UserManager;
24 import android.util.Slog;
25 
26 import com.android.internal.annotations.VisibleForTesting;
27 import com.android.settings.SettingsActivity;
28 
29 /**
30  * Standalone activity used to launch a {@link DefaultCombinedPicker} fragment if the user is a
31  * normal user, a {@link DefaultCombinedPickerWork} fragment if the user is a work profile or {@link
32  * DefaultCombinedPickerPrivate} fragment if the user is a private profile.
33  */
34 public class CredentialsPickerActivity extends SettingsActivity {
35     private static final String TAG = "CredentialsPickerActivity";
36     private boolean mIsWorkProfile;
37     private boolean mIsPrivateSpace;
38 
39     /** Injects the fragment name into the intent so the correct fragment is opened. */
40     @VisibleForTesting
injectFragmentIntoIntent(Context context, Intent intent, int userId)41     public static void injectFragmentIntoIntent(Context context, Intent intent, int userId) {
42         final UserManager userManager = UserManager.get(context);
43 
44         if (DefaultCombinedPickerWork.isUserHandledByFragment(userManager, userId)) {
45             Slog.d(TAG, "Creating picker fragment using work profile");
46             intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPickerWork.class.getName());
47         } else if (DefaultCombinedPickerPrivate.isUserHandledByFragment(userManager)) {
48             Slog.d(TAG, "Creating picker fragment using private profile");
49             intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPickerPrivate.class.getName());
50         } else {
51             Slog.d(TAG, "Creating picker fragment using normal profile");
52             intent.putExtra(EXTRA_SHOW_FRAGMENT, DefaultCombinedPicker.class.getName());
53         }
54     }
55 
56     @Override
onCreate(Bundle savedInstanceState)57     protected void onCreate(Bundle savedInstanceState) {
58         final String packageName = getCallingPackage();
59         final Intent intent = getIntent();
60 
61         mIsWorkProfile = intent.getBooleanExtra(UserUtils.EXTRA_IS_WORK_PROFILE, false);
62         mIsPrivateSpace = intent.getBooleanExtra(UserUtils.EXTRA_IS_PRIVATE_SPACE, false);
63 
64         intent.putExtra(DefaultCombinedPicker.EXTRA_PACKAGE_NAME, packageName);
65         injectFragmentIntoIntent(this, intent, UserUtils.getUser(
66                 mIsWorkProfile, mIsPrivateSpace, this));
67 
68         super.onCreate(savedInstanceState);
69     }
70 
71     @Override
isValidFragment(String fragmentName)72     protected boolean isValidFragment(String fragmentName) {
73         return super.isValidFragment(fragmentName)
74                 || DefaultCombinedPicker.class.getName().equals(fragmentName)
75                 || DefaultCombinedPickerWork.class.getName().equals(fragmentName)
76                 || DefaultCombinedPickerPrivate.class.getName().equals(fragmentName);
77     }
78 }
79