Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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.server.timezone; |
| 18 | |
Neil Fuller | a7d21f8 | 2017-12-05 15:09:35 +0000 | [diff] [blame] | 19 | import com.android.internal.util.DumpUtils; |
| 20 | |
Neil Fuller | b144227 | 2017-12-18 15:59:50 +0000 | [diff] [blame] | 21 | import android.app.timezone.RulesManager; |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 22 | import android.content.Context; |
Neil Fuller | b144227 | 2017-12-18 15:59:50 +0000 | [diff] [blame] | 23 | import android.content.Intent; |
Neil Fuller | 17ee5db | 2017-07-18 14:02:01 +0100 | [diff] [blame] | 24 | import android.os.AsyncTask; |
Neil Fuller | b144227 | 2017-12-18 15:59:50 +0000 | [diff] [blame] | 25 | import android.os.UserHandle; |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 26 | |
Neil Fuller | 87b1128 | 2017-06-23 16:43:45 +0100 | [diff] [blame] | 27 | import java.io.PrintWriter; |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 28 | import java.util.concurrent.Executor; |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * A single class that implements multiple helper interfaces for use by {@link RulesManagerService}. |
| 32 | */ |
Neil Fuller | b144227 | 2017-12-18 15:59:50 +0000 | [diff] [blame] | 33 | final class RulesManagerServiceHelperImpl |
| 34 | implements PermissionHelper, Executor, RulesManagerIntentHelper { |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 35 | |
| 36 | private final Context mContext; |
| 37 | |
| 38 | RulesManagerServiceHelperImpl(Context context) { |
| 39 | mContext = context; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void enforceCallerHasPermission(String requiredPermission) { |
| 44 | mContext.enforceCallingPermission(requiredPermission, null /* message */); |
| 45 | } |
| 46 | |
Neil Fuller | 87b1128 | 2017-06-23 16:43:45 +0100 | [diff] [blame] | 47 | @Override |
| 48 | public boolean checkDumpPermission(String tag, PrintWriter pw) { |
Neil Fuller | a7d21f8 | 2017-12-05 15:09:35 +0000 | [diff] [blame] | 49 | return DumpUtils.checkDumpPermission(mContext, tag, pw); |
Neil Fuller | 87b1128 | 2017-06-23 16:43:45 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 52 | @Override |
| 53 | public void execute(Runnable runnable) { |
Neil Fuller | 17ee5db | 2017-07-18 14:02:01 +0100 | [diff] [blame] | 54 | AsyncTask.execute(runnable); |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 55 | } |
Neil Fuller | b144227 | 2017-12-18 15:59:50 +0000 | [diff] [blame] | 56 | |
| 57 | @Override |
| 58 | public void sendTimeZoneOperationStaged() { |
| 59 | sendOperationIntent(true /* staged */); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void sendTimeZoneOperationUnstaged() { |
| 64 | sendOperationIntent(false /* staged */); |
| 65 | } |
| 66 | |
| 67 | private void sendOperationIntent(boolean staged) { |
| 68 | Intent intent = new Intent(RulesManager.ACTION_RULES_UPDATE_OPERATION); |
| 69 | intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND); |
| 70 | intent.putExtra(RulesManager.EXTRA_OPERATION_STAGED, staged); |
| 71 | mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM); |
| 72 | } |
| 73 | |
Neil Fuller | 68f6666 | 2017-03-16 18:32:21 +0000 | [diff] [blame] | 74 | } |