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