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;
16 * Stub entry points and implementation interface for the account management screen.
18 public class AccountManagementScreenHelper {
19 private static AccountManagementScreenManager sManager;
22 * TODO(aruslan): http://crbug.com/379987 Move to a generator.
23 * Enum for tracking user interactions with the account management menu
25 * This must match enum ProfileAndroidAccountManagementMenu in profile_metrics.h.
27 // User arrived at the Account management screen.
28 public static final int ACCOUNT_MANAGEMENT_MENU_VIEW = 0;
29 // User arrived at the Account management screen, and clicked Add account.
30 public static final int ACCOUNT_MANAGEMENT_MENU_ADD_ACCOUNT = 1;
31 // User arrived at the Account management screen, and clicked Go incognito.
32 public static final int ACCOUNT_MANAGEMENT_MENU_GO_INCOGNITO = 2;
33 // User arrived at the Account management screen, and clicked on primary.
34 public static final int ACCOUNT_MANAGEMENT_MENU_CLICK_PRIMARY_ACCOUNT = 3;
35 // User arrived at the Account management screen, and clicked on secondary.
36 public static final int ACCOUNT_MANAGEMENT_MENU_CLICK_SECONDARY_ACCOUNT = 4;
37 // User arrived at the Account management screen, toggled Chrome signout.
38 public static final int ACCOUNT_MANAGEMENT_MENU_TOGGLE_SIGNOUT = 5;
39 // User toggled Chrome signout, and clicked Signout.
40 public static final int ACCOUNT_MANAGEMENT_MENU_SIGNOUT_SIGNOUT = 6;
41 // User toggled Chrome signout, and clicked Cancel.
42 public static final int ACCOUNT_MANAGEMENT_MENU_SIGNOUT_CANCEL = 7;
43 // User arrived at the android Account management screen directly from some
45 public static final int ACCOUNT_MANAGEMENT_ADD_ACCOUNT = 8;
47 * TODO(guohui): add all Gaia service types.
48 * Enum for the Gaia service types, must match GAIAServiceType in
49 * signin_header_helper.h
51 public static final int GAIA_SERVICE_TYPE_SIGNUP = 5;
53 private static final String EXTRA_ACCOUNT_TYPES = "account_types";
54 private static final String EXTRA_VALUE_GOOGLE_ACCOUNTS = "com.google";
57 * The screen manager interface.
59 public interface AccountManagementScreenManager {
61 * Opens the account management UI screen.
62 * @param applicationContext The application context.
63 * @param profile The user profile.
64 * @param gaiaServiceType A signin::GAIAServiceType value that triggered the dialog.
66 void openAccountManagementScreen(
67 Context applicationContext, Profile profile, int gaiaServiceType);
71 * Sets the screen manager.
72 * @param manager An implementation of AccountManagementScreenManager interface.
74 public static void setManager(AccountManagementScreenManager manager) {
75 ThreadUtils.assertOnUiThread();
80 private static void openAccountManagementScreen(
81 Context applicationContext, Profile profile, int gaiaServiceType) {
82 ThreadUtils.assertOnUiThread();
83 if (sManager == null) return;
85 if (gaiaServiceType == GAIA_SERVICE_TYPE_SIGNUP)
86 openAndroidAccountCreationScreen(applicationContext);
88 sManager.openAccountManagementScreen(applicationContext, profile, gaiaServiceType);
92 * Opens the Android account manager for adding or creating a Google account.
93 * @param applicationContext
95 private static void openAndroidAccountCreationScreen(
96 Context applicationContext) {
97 logEvent(ACCOUNT_MANAGEMENT_ADD_ACCOUNT, GAIA_SERVICE_TYPE_SIGNUP);
99 Intent createAccountIntent = new Intent(Settings.ACTION_ADD_ACCOUNT);
100 createAccountIntent.putExtra(
101 EXTRA_ACCOUNT_TYPES, new String[]{EXTRA_VALUE_GOOGLE_ACCOUNTS});
102 createAccountIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
103 | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
104 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
106 applicationContext.startActivity(createAccountIntent);
110 * Log a UMA event for a given metric and a signin type.
111 * @param metric A PROFILE_ANDROID_ACCOUNT_MANAGEMENT_MENU metric.
112 * @param gaiaServiceType A signin::GAIAServiceType.
114 public static void logEvent(int metric, int gaiaServiceType) {
115 nativeLogEvent(metric, gaiaServiceType);
119 private static native void nativeLogEvent(int metric, int gaiaServiceType);