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.IBinder; 23 24 import com.android.email.SecurityPolicy; 25 import com.android.emailcommon.provider.Policy; 26 import com.android.emailcommon.service.IPolicyService; 27 import com.android.mail.utils.LogTag; 28 import com.android.mail.utils.LogUtils; 29 30 public class PolicyService extends Service { 31 private static final String LOG_TAG = LogTag.getLogTag(); 32 33 private SecurityPolicy mSecurityPolicy; 34 private Context mContext; 35 36 private final IPolicyService.Stub mBinder = new IPolicyService.Stub() { 37 @Override 38 public boolean isActive(Policy policy) { 39 try { 40 return mSecurityPolicy.isActive(policy); 41 } catch (RuntimeException e) { 42 // Catch, log and rethrow the exception, as otherwise when the exception is 43 // ultimately handled, the complete stack trace is losk 44 LogUtils.e(LOG_TAG, e, "Exception thrown during call to SecurityPolicy#isActive"); 45 throw e; 46 } 47 } 48 49 @Override 50 public void setAccountHoldFlag(long accountId, boolean newState) { 51 SecurityPolicy.setAccountHoldFlag(mContext, accountId, newState); 52 } 53 54 @Override 55 public void remoteWipe() { 56 try { 57 mSecurityPolicy.remoteWipe(); 58 } catch (RuntimeException e) { 59 // Catch, log and rethrow the exception, as otherwise when the exception is 60 // ultimately handled, the complete stack trace is losk 61 LogUtils.e(LOG_TAG, e, "Exception thrown during call to SecurityPolicy#remoteWipe"); 62 throw e; 63 } 64 } 65 66 @Override 67 public void setAccountPolicy(long accountId, Policy policy, String securityKey) { 68 try { 69 mSecurityPolicy.setAccountPolicy(accountId, policy, securityKey); 70 } catch (RuntimeException e) { 71 // Catch, log and rethrow the exception, as otherwise when the exception is 72 // ultimately handled, the complete stack trace is losk 73 LogUtils.e(LOG_TAG, e, 74 "Exception thrown from call to SecurityPolicy#setAccountPolicy"); 75 throw e; 76 } 77 } 78 }; 79 80 @Override 81 public IBinder onBind(Intent intent) { 82 // When we bind this service, save the context and SecurityPolicy singleton 83 mContext = this; 84 mSecurityPolicy = SecurityPolicy.getInstance(this); 85 return mBinder; 86 } 87 }