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.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     // The following call is synchronous, and should not be made from the UI thread
     46     @Override
     47     public int getAccountColor(final long accountId) {
     48         setTask(new ProxyTask() {
     49             @Override
     50             public void run() throws RemoteException{
     51                 mReturn = mService.getAccountColor(accountId);
     52             }
     53         }, "getAccountColor");
     54         waitForCompletion();
     55         if (mReturn == null) {
     56             return DEFAULT_ACCOUNT_COLOR;
     57         } else {
     58             return (Integer)mReturn;
     59         }
     60     }
     61 
     62     // The following call is synchronous, and should not be made from the UI thread
     63     @Override
     64     public Bundle getConfigurationData(final String accountType) {
     65         setTask(new ProxyTask() {
     66             @Override
     67             public void run() throws RemoteException{
     68                 mReturn = mService.getConfigurationData(accountType);
     69             }
     70         }, "getConfigurationData");
     71         waitForCompletion();
     72         if (mReturn == null) {
     73             return null;
     74         } else {
     75             return (Bundle)mReturn;
     76         }
     77     }
     78 
     79     // The following call is synchronous, and should not be made from the UI thread
     80     @Override
     81     public String getDeviceId() {
     82         setTask(new ProxyTask() {
     83             @Override
     84             public void run() throws RemoteException{
     85                 mReturn = mService.getDeviceId();
     86             }
     87         }, "getDeviceId");
     88         waitForCompletion();
     89         if (mReturn == null) {
     90             return null;
     91         } else {
     92             return (String)mReturn;
     93         }
     94     }
     95 }
     96 
     97