18a574694606f0e5d781334d0d426fc379c51f3edMarc Blank/* 28a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * Copyright (C) 2011 The Android Open Source Project 38a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * 48a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * Licensed under the Apache License, Version 2.0 (the "License"); 58a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * you may not use this file except in compliance with the License. 68a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * You may obtain a copy of the License at 78a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * 88a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * http://www.apache.org/licenses/LICENSE-2.0 98a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * 108a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * Unless required by applicable law or agreed to in writing, software 118a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * distributed under the License is distributed on an "AS IS" BASIS, 128a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * See the License for the specific language governing permissions and 148a574694606f0e5d781334d0d426fc379c51f3edMarc Blank * limitations under the License. 158a574694606f0e5d781334d0d426fc379c51f3edMarc Blank */ 168a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 178a574694606f0e5d781334d0d426fc379c51f3edMarc Blankpackage com.android.email.service; 188a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 194e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blankimport android.app.Service; 204e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blankimport android.content.Context; 214e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blankimport android.content.Intent; 224e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blankimport android.os.Bundle; 234e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blankimport android.os.IBinder; 244e4aba9ebc43c6a83190f3a883fa05bb7d5100b3Marc Blank 2551c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdonimport com.android.email.DebugUtils; 268a574694606f0e5d781334d0d426fc379c51f3edMarc Blankimport com.android.email.ResourceHelper; 2737500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blankimport com.android.emailcommon.Configuration; 28dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blankimport com.android.emailcommon.Device; 29c6089bc01f2ae49fb11904a4b4f222811358254fMarc Blankimport com.android.emailcommon.VendorPolicyLoader; 308a574694606f0e5d781334d0d426fc379c51f3edMarc Blankimport com.android.emailcommon.service.IAccountService; 31c4cdb11d24c19428dd39f986b00c1a29e75e1505Todd Kennedyimport com.android.emailcommon.utility.EmailAsyncTask; 328a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 33dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blankimport java.io.IOException; 34dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank 358a574694606f0e5d781334d0d426fc379c51f3edMarc Blankpublic class AccountService extends Service { 368a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 37dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank // Save context 388a574694606f0e5d781334d0d426fc379c51f3edMarc Blank private Context mContext; 398a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 408a574694606f0e5d781334d0d426fc379c51f3edMarc Blank private final IAccountService.Stub mBinder = new IAccountService.Stub() { 418a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 428a574694606f0e5d781334d0d426fc379c51f3edMarc Blank @Override 43c4cdb11d24c19428dd39f986b00c1a29e75e1505Todd Kennedy public int getAccountColor(long accountId) { 448a574694606f0e5d781334d0d426fc379c51f3edMarc Blank return ResourceHelper.getInstance(mContext).getAccountColor(accountId); 458a574694606f0e5d781334d0d426fc379c51f3edMarc Blank } 4637500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank 4737500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank @Override 48c4cdb11d24c19428dd39f986b00c1a29e75e1505Todd Kennedy public Bundle getConfigurationData(String accountType) { 4937500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank Bundle bundle = new Bundle(); 5037500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank bundle.putBoolean(Configuration.EXCHANGE_CONFIGURATION_USE_ALTERNATE_STRINGS, 5137500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank VendorPolicyLoader.getInstance(mContext).useAlternateExchangeStrings()); 5237500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank return bundle; 5337500777f1ca2dc7a1f831b9f3af63cbe7b9d487Marc Blank } 54dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank 55dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank @Override 56c4cdb11d24c19428dd39f986b00c1a29e75e1505Todd Kennedy public String getDeviceId() { 57dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank try { 58c4cdb11d24c19428dd39f986b00c1a29e75e1505Todd Kennedy EmailAsyncTask.runAsyncSerial(new Runnable() { 59fdec974c93817988a00248b7d223ec9f7f20ecb8Marc Blank @Override 60fdec974c93817988a00248b7d223ec9f7f20ecb8Marc Blank public void run() { 61f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank // Make sure remote services are running (re: lifecycle) 62f419287f22ae44f25e1ba1f757ec33c7941bbfa8Marc Blank EmailServiceUtils.startRemoteServices(mContext); 63fdec974c93817988a00248b7d223ec9f7f20ecb8Marc Blank // Send current logging flags 6451c653646d14d841fbe527aee9fab7a1886338f8Martin Hibdon DebugUtils.updateLoggingFlags(mContext); 65fdec974c93817988a00248b7d223ec9f7f20ecb8Marc Blank }}); 66dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank return Device.getDeviceId(mContext); 67dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank } catch (IOException e) { 68dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank return null; 69dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank } 70dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank } 718a574694606f0e5d781334d0d426fc379c51f3edMarc Blank }; 728a574694606f0e5d781334d0d426fc379c51f3edMarc Blank 738a574694606f0e5d781334d0d426fc379c51f3edMarc Blank @Override 748a574694606f0e5d781334d0d426fc379c51f3edMarc Blank public IBinder onBind(Intent intent) { 758a574694606f0e5d781334d0d426fc379c51f3edMarc Blank if (mContext == null) { 768a574694606f0e5d781334d0d426fc379c51f3edMarc Blank mContext = this; 778a574694606f0e5d781334d0d426fc379c51f3edMarc Blank } 78dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank // Make sure we have a valid deviceId (just retrieves a static String except first time) 79dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank try { 80dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank Device.getDeviceId(this); 81dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank } catch (IOException e) { 82dc78a769fce18d259eccc602c4623fa74cdf5319Marc Blank } 838a574694606f0e5d781334d0d426fc379c51f3edMarc Blank return mBinder; 848a574694606f0e5d781334d0d426fc379c51f3edMarc Blank } 85afe097f318a7eeac9d240d2bedbc5caba7640ea8Yu Ping Hu} 86