Adds Google account login during private space setup

This has the following changes:
1. On profile creation starts intent to add google account to the private profile for Pixel only devices.
2. On accout sign in failed show an error screen with message to try again.
3. Moves the lock setup fragment from private to main user which now calls the helper Activity as a private user which helps to setup lock. This activity can now also be called from the planned Secondary Auth settings page to set up private profile lock.
4. On set up complete use SHOW_WORK_APPS intent as a workaroud to start launcher.

Bug: 308397617
Test: Manual setup
Change-Id: I19b95375409f015b2a5d30fdad766c2f6baa634b
This commit is contained in:
josephpv
2023-10-30 11:29:26 +00:00
committed by Joseph Vincent
parent b4890641b0
commit 380ac9a48e
18 changed files with 335 additions and 54 deletions

View File

@@ -16,27 +16,84 @@
package com.android.settings.privatespace;
import static android.app.admin.DevicePolicyManager.ACTION_SET_NEW_PASSWORD;
import static android.app.admin.DevicePolicyManager.EXTRA_PASSWORD_COMPLEXITY;
import static android.app.admin.DevicePolicyManager.PASSWORD_COMPLEXITY_LOW;
import static com.android.settings.privatespace.PrivateSpaceSetupActivity.ACCOUNT_LOGIN_ACTION;
import static com.android.settings.privatespace.PrivateSpaceSetupActivity.EXTRA_ACTION_TYPE;
import static com.android.settings.privatespace.PrivateSpaceSetupActivity.SET_LOCK_ACTION;
import android.app.KeyguardManager;
import android.content.Intent;
import android.os.Bundle;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.navigation.fragment.NavHostFragment;
import com.android.settings.R;
import com.android.settings.SetupWizardUtils;
import com.android.settings.overlay.FeatureFactory;
import com.google.android.setupdesign.util.ThemeHelper;
/** Activity that is started as private profile user that helps to set private profile lock. */
/** Activity that is started as private profile user that helps to set private profile lock or
* add an account on the private profile. */
public class PrivateProfileContextHelperActivity extends FragmentActivity {
private static final String TAG = "PrivateProfileHelper";
private final ActivityResultLauncher<Intent> mAddAccountToPrivateProfile =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
this::onAccountAdded);
private final ActivityResultLauncher<Intent> mVerifyDeviceLock =
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
this::onSetDeviceNewLock);
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SetupWizardUtils.getTheme(this, getIntent()));
ThemeHelper.trySetDynamicColor(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.privatespace_setup_root);
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
.findFragmentById(R.id.ps_nav_host_fragment);
navHostFragment.getNavController().setGraph(R.navigation.privatespace_private_context_nav);
if (savedInstanceState == null) {
int action = getIntent().getIntExtra(EXTRA_ACTION_TYPE, -1);
if (action == ACCOUNT_LOGIN_ACTION) {
PrivateSpaceLoginFeatureProvider privateSpaceLoginFeatureProvider =
FeatureFactory.getFeatureFactory().getPrivateSpaceLoginFeatureProvider();
if (!privateSpaceLoginFeatureProvider.initiateAccountLogin(this,
mAddAccountToPrivateProfile)) {
setResult(RESULT_OK);
finish();
}
} else if (action == SET_LOCK_ACTION) {
createPrivateSpaceLock();
}
}
}
private void createPrivateSpaceLock() {
final Intent intent = new Intent(ACTION_SET_NEW_PASSWORD);
intent.putExtra(EXTRA_PASSWORD_COMPLEXITY, PASSWORD_COMPLEXITY_LOW);
mVerifyDeviceLock.launch(intent);
}
private void onAccountAdded(@Nullable ActivityResult result) {
if (result != null && result.getResultCode() == RESULT_OK) {
setResult(RESULT_OK);
} else {
setResult(RESULT_CANCELED);
}
finish();
}
private void onSetDeviceNewLock(@Nullable ActivityResult result) {
// TODO(b/307281644) : Verify this for biometrics and check result code after new
// Authentication changes are merged.
if (result != null && getSystemService(KeyguardManager.class).isDeviceSecure()) {
setResult(RESULT_OK);
} else {
setResult(RESULT_CANCELED);
}
finish();
}
}