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