1 /* 2 * Copyright (C) 2013 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.inputmethod.latin.personalization; 18 19 import android.accounts.Account; 20 import android.accounts.AccountManager; 21 import android.content.Context; 22 import android.util.Patterns; 23 24 import java.util.ArrayList; 25 import java.util.List; 26 27 public class AccountUtils { 28 private AccountUtils() { 29 // This utility class is not publicly instantiable. 30 } 31 32 private static Account[] getAccounts(final Context context) { 33 return AccountManager.get(context).getAccounts(); 34 } 35 36 public static List<String> getDeviceAccountsEmailAddresses(final Context context) { 37 final ArrayList<String> retval = new ArrayList<String>(); 38 for (final Account account : getAccounts(context)) { 39 final String name = account.name; 40 if (Patterns.EMAIL_ADDRESS.matcher(name).matches()) { 41 retval.add(name); 42 retval.add(name.split("@")[0]); 43 } 44 } 45 return retval; 46 } 47 } 48