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.email.service;
     18 
     19 import com.android.email.SecurityPolicy;
     20 import com.android.emailcommon.provider.Policy;
     21 import com.android.emailcommon.service.IPolicyService;
     22 
     23 import android.app.Service;
     24 import android.content.Context;
     25 import android.content.Intent;
     26 import android.os.IBinder;
     27 
     28 public class PolicyService extends Service {
     29 
     30     private SecurityPolicy mSecurityPolicy;
     31     private Context mContext;
     32 
     33     private final IPolicyService.Stub mBinder = new IPolicyService.Stub() {
     34         public boolean isActive(Policy policy) {
     35             return mSecurityPolicy.isActive(policy);
     36         }
     37 
     38         public void policiesRequired(long accountId) {
     39             mSecurityPolicy.policiesRequired(accountId);
     40         }
     41 
     42         public void policiesUpdated(long accountId) {
     43             mSecurityPolicy.policiesUpdated(accountId);
     44         }
     45 
     46         public void setAccountHoldFlag(long accountId, boolean newState) {
     47             SecurityPolicy.setAccountHoldFlag(mContext, accountId, newState);
     48         }
     49 
     50         public boolean isActiveAdmin() {
     51             return mSecurityPolicy.isActiveAdmin();
     52         }
     53 
     54         public void remoteWipe() {
     55             mSecurityPolicy.remoteWipe();
     56         }
     57 
     58         public boolean isSupported(Policy policy) {
     59             return mSecurityPolicy.isSupported(policy);
     60         }
     61 
     62         public Policy clearUnsupportedPolicies(Policy policy) {
     63             return mSecurityPolicy.clearUnsupportedPolicies(policy);
     64         }
     65 
     66         public void setAccountPolicy(long accountId, Policy policy, String securityKey) {
     67             mSecurityPolicy.setAccountPolicy(accountId, policy, securityKey);
     68         }
     69     };
     70 
     71     @Override
     72     public IBinder onBind(Intent intent) {
     73         // When we bind this service, save the context and SecurityPolicy singleton
     74         mContext = this;
     75         mSecurityPolicy = SecurityPolicy.getInstance(this);
     76         return mBinder;
     77     }
     78 }