Home | History | Annotate | Download | only in exchange
      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.exchange;
     18 
     19 import com.android.emailcommon.provider.Account;
     20 import com.android.emailcommon.provider.Policy;
     21 import com.android.emailcommon.service.PolicyServiceProxy;
     22 
     23 import android.content.Context;
     24 import android.os.RemoteException;
     25 
     26 public class SecurityPolicyDelegate {
     27 
     28     public static boolean isActive(Context context, Policy policy) {
     29         try {
     30             return new PolicyServiceProxy(context).isActive(policy);
     31         } catch (RemoteException e) {
     32         }
     33         return false;
     34     }
     35 
     36     public static void policiesRequired(Context context, long accountId) {
     37         try {
     38             new PolicyServiceProxy(context).policiesRequired(accountId);
     39         } catch (RemoteException e) {
     40             throw new IllegalStateException("PolicyService transaction failed");
     41         }
     42     }
     43 
     44     public static void policiesUpdated(Context context, long accountId) {
     45         try {
     46             new PolicyServiceProxy(context).policiesUpdated(accountId);
     47         } catch (RemoteException e) {
     48             throw new IllegalStateException("PolicyService transaction failed");
     49         }
     50     }
     51 
     52     public static void setAccountHoldFlag(Context context, Account account, boolean newState) {
     53         try {
     54             new PolicyServiceProxy(context).setAccountHoldFlag(account.mId, newState);
     55         } catch (RemoteException e) {
     56             throw new IllegalStateException("PolicyService transaction failed");
     57         }
     58     }
     59 
     60     public static boolean isActiveAdmin(Context context) {
     61         try {
     62             return new PolicyServiceProxy(context).isActiveAdmin();
     63         } catch (RemoteException e) {
     64         }
     65         return false;
     66     }
     67 
     68     public static void remoteWipe(Context context) {
     69         try {
     70             new PolicyServiceProxy(context).remoteWipe();
     71         } catch (RemoteException e) {
     72             throw new IllegalStateException("PolicyService transaction failed");
     73         }
     74     }
     75 
     76     public static boolean isSupported(Context context, Policy policy) {
     77         try {
     78             return new PolicyServiceProxy(context).isSupported(policy);
     79         } catch (RemoteException e) {
     80         }
     81         return false;
     82      }
     83 
     84     public static Policy clearUnsupportedPolicies(Context context, Policy policy) {
     85         try {
     86             return new PolicyServiceProxy(context).clearUnsupportedPolicies(policy);
     87         } catch (RemoteException e) {
     88         }
     89         throw new IllegalStateException("PolicyService transaction failed");
     90     }
     91 }
     92