Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 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; |
Marc Blank | aeee10e | 2011-04-27 17:12:06 -0700 | [diff] [blame] | 20 | import com.android.emailcommon.provider.Policy; |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 21 | import com.android.emailcommon.service.IPolicyService; |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 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() { |
Marc Blank | aeee10e | 2011-04-27 17:12:06 -0700 | [diff] [blame] | 34 | public boolean isActive(Policy policy) { |
| 35 | return mSecurityPolicy.isActive(policy); |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | public void policiesRequired(long accountId) { |
| 39 | mSecurityPolicy.policiesRequired(accountId); |
| 40 | } |
| 41 | |
Marc Blank | aeee10e | 2011-04-27 17:12:06 -0700 | [diff] [blame] | 42 | public void policiesUpdated(long accountId) { |
| 43 | mSecurityPolicy.policiesUpdated(accountId); |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 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 | |
Marc Blank | aeee10e | 2011-04-27 17:12:06 -0700 | [diff] [blame] | 58 | public boolean isSupported(Policy policy) { |
| 59 | return mSecurityPolicy.isSupported(policy); |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Marc Blank | aeee10e | 2011-04-27 17:12:06 -0700 | [diff] [blame] | 62 | public Policy clearUnsupportedPolicies(Policy policy) { |
| 63 | return mSecurityPolicy.clearUnsupportedPolicies(policy); |
Marc Blank | 9ba506c | 2011-02-08 18:54:56 -0800 | [diff] [blame] | 64 | } |
| 65 | }; |
| 66 | |
| 67 | @Override |
| 68 | public IBinder onBind(Intent intent) { |
| 69 | // When we bind this service, save the context and SecurityPolicy singleton |
| 70 | mContext = this; |
| 71 | mSecurityPolicy = SecurityPolicy.getInstance(this); |
| 72 | return mBinder; |
| 73 | } |
| 74 | } |