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