1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser.signin;
7 import android.content.Context;
8 import android.content.Intent;
9 import android.provider.Settings;
11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.ThreadUtils;
13 import org.chromium.chrome.browser.profiles.Profile;
14 import org.chromium.chrome.browser.profiles.ProfileAccountManagementMetrics;
17 * Stub entry points and implementation interface for the account management screen.
19 public class AccountManagementScreenHelper {
20 private static AccountManagementScreenManager sManager;
23 * TODO(guohui): add all Gaia service types.
24 * Enum for the Gaia service types, must match GAIAServiceType in
25 * signin_header_helper.h
27 public static final int GAIA_SERVICE_TYPE_SIGNUP = 5;
29 private static final String EXTRA_ACCOUNT_TYPES = "account_types";
30 private static final String EXTRA_VALUE_GOOGLE_ACCOUNTS = "com.google";
33 * The screen manager interface.
35 public interface AccountManagementScreenManager {
37 * Opens the account management UI screen.
38 * @param applicationContext The application context.
39 * @param profile The user profile.
40 * @param gaiaServiceType A signin::GAIAServiceType value that triggered the dialog.
42 void openAccountManagementScreen(
43 Context applicationContext, Profile profile, int gaiaServiceType);
47 * Sets the screen manager.
48 * @param manager An implementation of AccountManagementScreenManager interface.
50 public static void setManager(AccountManagementScreenManager manager) {
51 ThreadUtils.assertOnUiThread();
56 private static void openAccountManagementScreen(
57 Context applicationContext, Profile profile, int gaiaServiceType) {
58 ThreadUtils.assertOnUiThread();
59 if (sManager == null) return;
61 if (gaiaServiceType == GAIA_SERVICE_TYPE_SIGNUP)
62 openAndroidAccountCreationScreen(applicationContext);
64 sManager.openAccountManagementScreen(applicationContext, profile, gaiaServiceType);
68 * Opens the Android account manager for adding or creating a Google account.
69 * @param applicationContext
71 private static void openAndroidAccountCreationScreen(
72 Context applicationContext) {
73 logEvent(ProfileAccountManagementMetrics.DIRECT_ADD_ACCOUNT, GAIA_SERVICE_TYPE_SIGNUP);
75 Intent createAccountIntent = new Intent(Settings.ACTION_ADD_ACCOUNT);
76 createAccountIntent.putExtra(
77 EXTRA_ACCOUNT_TYPES, new String[]{EXTRA_VALUE_GOOGLE_ACCOUNTS});
78 createAccountIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
79 | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
80 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
82 applicationContext.startActivity(createAccountIntent);
86 * Log a UMA event for a given metric and a signin type.
87 * @param metric One of ProfileAccountManagementMetrics constants.
88 * @param gaiaServiceType A signin::GAIAServiceType.
90 public static void logEvent(int metric, int gaiaServiceType) {
91 nativeLogEvent(metric, gaiaServiceType);
95 private static native void nativeLogEvent(int metric, int gaiaServiceType);