1/* 2 * Copyright (C) 2011 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 17package com.android.email.service; 18 19import android.app.Service; 20import android.content.Context; 21import android.content.Intent; 22import android.os.Bundle; 23import android.os.IBinder; 24 25import com.android.email.NotificationController; 26import com.android.email.ResourceHelper; 27import com.android.email2.ui.MailActivityEmail; 28import com.android.emailcommon.Configuration; 29import com.android.emailcommon.Device; 30import com.android.emailcommon.VendorPolicyLoader; 31import com.android.emailcommon.service.IAccountService; 32import com.android.emailcommon.utility.EmailAsyncTask; 33 34import java.io.IOException; 35 36public class AccountService extends Service { 37 38 // Save context 39 private Context mContext; 40 41 private final IAccountService.Stub mBinder = new IAccountService.Stub() { 42 43 @Override 44 public int getAccountColor(long accountId) { 45 return ResourceHelper.getInstance(mContext).getAccountColor(accountId); 46 } 47 48 @Override 49 public Bundle getConfigurationData(String accountType) { 50 Bundle bundle = new Bundle(); 51 bundle.putBoolean(Configuration.EXCHANGE_CONFIGURATION_USE_ALTERNATE_STRINGS, 52 VendorPolicyLoader.getInstance(mContext).useAlternateExchangeStrings()); 53 return bundle; 54 } 55 56 @Override 57 public String getDeviceId() { 58 try { 59 EmailAsyncTask.runAsyncSerial(new Runnable() { 60 @Override 61 public void run() { 62 // Make sure remote services are running (re: lifecycle) 63 EmailServiceUtils.startRemoteServices(mContext); 64 // Send current logging flags 65 MailActivityEmail.updateLoggingFlags(mContext); 66 }}); 67 return Device.getDeviceId(mContext); 68 } catch (IOException e) { 69 return null; 70 } 71 } 72 }; 73 74 @Override 75 public IBinder onBind(Intent intent) { 76 if (mContext == null) { 77 mContext = this; 78 } 79 // Make sure we have a valid deviceId (just retrieves a static String except first time) 80 try { 81 Device.getDeviceId(this); 82 } catch (IOException e) { 83 } 84 return mBinder; 85 } 86} 87