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.emailcommon.service; 18 19 import android.content.Context; 20 import android.os.Bundle; 21 import android.os.IBinder; 22 import android.os.RemoteException; 23 24 public class AccountServiceProxy extends ServiceProxy implements IAccountService { 25 26 public static final int DEFAULT_ACCOUNT_COLOR = 0xFF0000FF; 27 28 private IAccountService mService = null; 29 private Object mReturn; 30 31 public AccountServiceProxy(Context _context) { 32 super(_context, getIntentForEmailPackage(_context, "ACCOUNT_INTENT")); 33 } 34 35 @Override 36 public void onConnected(IBinder binder) { 37 mService = IAccountService.Stub.asInterface(binder); 38 } 39 40 @Override 41 public IBinder asBinder() { 42 return null; 43 } 44 45 @Override 46 public void notifyLoginFailed(final long accountId, final String reason) { 47 setTask(new ProxyTask() { 48 @Override 49 public void run() throws RemoteException { 50 mService.notifyLoginFailed(accountId, reason); 51 } 52 }, "notifyLoginFailed"); 53 } 54 55 @Override 56 public void notifyLoginSucceeded(final long accountId) { 57 setTask(new ProxyTask() { 58 @Override 59 public void run() throws RemoteException { 60 mService.notifyLoginSucceeded(accountId); 61 } 62 }, "notifyLoginSucceeded"); 63 } 64 65 // The following call is synchronous, and should not be made from the UI thread 66 @Override 67 public void reconcileAccounts(final String protocol, final String accountManagerType) { 68 setTask(new ProxyTask() { 69 @Override 70 public void run() throws RemoteException { 71 mService.reconcileAccounts(protocol, accountManagerType); 72 } 73 }, "reconcileAccounts"); 74 waitForCompletion(); 75 } 76 77 // The following call is synchronous, and should not be made from the UI thread 78 @Override 79 public int getAccountColor(final long accountId) { 80 setTask(new ProxyTask() { 81 @Override 82 public void run() throws RemoteException{ 83 mReturn = mService.getAccountColor(accountId); 84 } 85 }, "getAccountColor"); 86 waitForCompletion(); 87 if (mReturn == null) { 88 return DEFAULT_ACCOUNT_COLOR; 89 } else { 90 return (Integer)mReturn; 91 } 92 } 93 94 // The following call is synchronous, and should not be made from the UI thread 95 @Override 96 public Bundle getConfigurationData(final String accountType) { 97 setTask(new ProxyTask() { 98 @Override 99 public void run() throws RemoteException{ 100 mReturn = mService.getConfigurationData(accountType); 101 } 102 }, "getConfigurationData"); 103 waitForCompletion(); 104 if (mReturn == null) { 105 return null; 106 } else { 107 return (Bundle)mReturn; 108 } 109 } 110 111 // The following call is synchronous, and should not be made from the UI thread 112 @Override 113 public String getDeviceId() { 114 setTask(new ProxyTask() { 115 @Override 116 public void run() throws RemoteException{ 117 mReturn = mService.getDeviceId(); 118 } 119 }, "getDeviceId"); 120 waitForCompletion(); 121 if (mReturn == null) { 122 return null; 123 } else { 124 return (String)mReturn; 125 } 126 } 127 } 128 129