• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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.google.android.googlelogin;
18 
19 import android.content.Intent;
20 // import android.accounts.AccountManager;
21 
22 /**
23  * Miscellaneous constants used by the GoogleLoginService and its
24  * clients.
25  */
26 public class GoogleLoginServiceConstants {
27     /** This class is never instantiated. */
GoogleLoginServiceConstants()28     private GoogleLoginServiceConstants() {
29     }
30 
31     /**
32      * Key used in the "extras" bundle.
33      * <p>
34      * The value of the mapping with this key is a String[]
35      * representing the Google accounts currently known on the device.
36      */
37     public static final String ACCOUNTS_KEY = "accounts"; // AccountManager.KEY_ACCOUNTS;
38 
39     /**
40      * Key used in the "extras" bundle.
41      * <p>
42      * The value of the mapping with this key is a String containing
43      * the requested authentication token.
44      */
45     public static final String AUTHTOKEN_KEY = "authtoken"; // AccountManager.KEY_AUTHTOKEN;
46 
47     /**
48      * Key used in the "extras" bundle.
49      * <p>
50      * The value of the mapping with this key is a String containing
51      * the account name (username) used to generate the accompanying
52      * authentication token.
53      */
54     public static final String AUTH_ACCOUNT_KEY = "authAccount"; // AccountManager.KEY_ACCOUNT_NAME;
55 
56     /**
57      * Key used in the "extras" bundle that will be present if an error
58      * has occurred.
59      * <p>
60      * The value of the mapping with this key is an int. The possible values are
61      * {@link #ERROR_CODE_GLS_NOT_FOUND} or
62      * {@link #ERROR_CODE_GLS_VERIFICATION_FAILED}.
63      */
64     public static final String ERROR_CODE_KEY = "errorCode"; // AccountManager.KEY_ERROR_CODE;
65 
66     /**
67      * Error code (see {@link #ERROR_CODE_KEY}) for when the Google login
68      * service can not be found.
69      */
70     public static final int ERROR_CODE_GLS_NOT_FOUND = 0;
71 
72     /**
73      * Error code (see {@link #ERROR_CODE_KEY}) for when the verification of the
74      * Google login service fails.
75      */
76     public static final int ERROR_CODE_GLS_VERIFICATION_FAILED = 1;
77 
78     /**
79      * Gets a message (can be used as an Exception message) for a particular
80      * error code.
81      *
82      * @param errorCode The error code.
83      * @return A message describing the error code. This will not be localized.
84      */
getErrorCodeMessage(int errorCode)85     static String getErrorCodeMessage(int errorCode) {
86         switch (errorCode) {
87             case ERROR_CODE_GLS_NOT_FOUND:
88                 return "The Google login service cannot be found.";
89 
90             case ERROR_CODE_GLS_VERIFICATION_FAILED:
91                 return "The Google login service cannot be verified.";
92 
93             default:
94                 return "Unknown error";
95         }
96     }
97 
98     /**
99      * Extras to be returned to the caller.
100      */
101     public static final String REQUEST_EXTRAS = "callerExtras";
102 
103     /**
104      * YouTube logins produce an extra bit of data: the youtube
105      * username linked to the google account that we log in to.
106      * getAuthToken will return this extra string when logging
107      * in to the 'youtube' service.
108      */
109     public static final String YOUTUBE_USER_KEY = "YouTubeUser";
110 
111     /**
112      * The name of the Google login service.
113      */
114     public static final String SERVICE_NAME = "GoogleLoginService";
115 
116     /**
117      * The package name of the Google login service.
118      */
119     public static final String SERVICE_PACKAGE_NAME = "com.google.android.googleapps";
120 
121     /**
122      * The fully qualified name of the Google login service (package + name).
123      */
124     public static final String FULLY_QUALIFIED_SERVICE_NAME =
125             SERVICE_PACKAGE_NAME + "." + SERVICE_NAME;
126 
127     /** The intent used to bind to the Google Login Service. */
128     public static final Intent SERVICE_INTENT =
129         (new Intent()).setClassName(SERVICE_PACKAGE_NAME, FULLY_QUALIFIED_SERVICE_NAME);
130 
131     public static final int FLAG_GOOGLE_ACCOUNT = 0x1;
132     public static final int FLAG_HOSTED_ACCOUNT = 0x2;
133     public static final int FLAG_YOUTUBE_ACCOUNT = 0x4;
134     public static final int FLAG_SAML_ACCOUNT = 0x8;
135     public static final int FLAG_LEGACY_GOOGLE = 0x10;
136     public static final int FLAG_LEGACY_HOSTED_OR_GOOGLE = 0x20;
137 
138     public static final String FEATURE_LEGACY_GOOGLE = "legacy_google";
139     public static final String FEATURE_LEGACY_HOSTED_OR_GOOGLE = "legacy_hosted_or_google";
140     public static final String FEATURE_HOSTED_OR_GOOGLE = "hosted_or_google";
141     public static final String FEATURE_GOOGLE = "google";
142     public static final String FEATURE_YOUTUBE = "youtubelinked";
143     public static final String FEATURE_SAML_ACCOUNT = "saml";
144 
145     /**
146      * Prefix for service features, combine with the service name (as defined by
147      * ClientLogin ) for example service_cp for an account having calendar.
148      */
149     public static final String FEATURE_SERVICE_PREFIX = "service_";
150 
151     public static final boolean REQUIRE_GOOGLE = true;
152     public static final boolean PREFER_HOSTED = false;
153 
154     // the account type for google accounts that are authenticated via GAIA
155     public static final String ACCOUNT_TYPE = "com.google";
156 
157     /**
158      * Action sent as a broadcast Intent by the AccountsService
159      * when it starts up and no accounts are available (so some should be added).
160      */
161     public static final String LOGIN_ACCOUNTS_MISSING_ACTION =
162         "com.google.android.googlelogin.LOGIN_ACCOUNTS_MISSING";
163 
featureForService(String service)164     public static String featureForService(String service) {
165         return FEATURE_SERVICE_PREFIX + service;
166     }
167 }
168