blob: 8f5c7a783304b7e5133df14465a17c88171469ba [file] [log] [blame]
Neil Fuller68f66662017-03-16 18:32:21 +00001/*
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
17package com.android.server.timezone;
18
Neil Fullera7d21f82017-12-05 15:09:35 +000019import com.android.internal.util.DumpUtils;
20
Neil Fullerb1442272017-12-18 15:59:50 +000021import android.app.timezone.RulesManager;
Neil Fuller68f66662017-03-16 18:32:21 +000022import android.content.Context;
Neil Fullerb1442272017-12-18 15:59:50 +000023import android.content.Intent;
Neil Fuller17ee5db2017-07-18 14:02:01 +010024import android.os.AsyncTask;
Neil Fullerb1442272017-12-18 15:59:50 +000025import android.os.UserHandle;
Neil Fuller68f66662017-03-16 18:32:21 +000026
Neil Fuller87b11282017-06-23 16:43:45 +010027import java.io.PrintWriter;
Neil Fuller68f66662017-03-16 18:32:21 +000028import java.util.concurrent.Executor;
Neil Fuller68f66662017-03-16 18:32:21 +000029
30/**
31 * A single class that implements multiple helper interfaces for use by {@link RulesManagerService}.
32 */
Neil Fullerb1442272017-12-18 15:59:50 +000033final class RulesManagerServiceHelperImpl
34 implements PermissionHelper, Executor, RulesManagerIntentHelper {
Neil Fuller68f66662017-03-16 18:32:21 +000035
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 Fuller87b11282017-06-23 16:43:45 +010047 @Override
48 public boolean checkDumpPermission(String tag, PrintWriter pw) {
Neil Fullera7d21f82017-12-05 15:09:35 +000049 return DumpUtils.checkDumpPermission(mContext, tag, pw);
Neil Fuller87b11282017-06-23 16:43:45 +010050 }
51
Neil Fuller68f66662017-03-16 18:32:21 +000052 @Override
53 public void execute(Runnable runnable) {
Neil Fuller17ee5db2017-07-18 14:02:01 +010054 AsyncTask.execute(runnable);
Neil Fuller68f66662017-03-16 18:32:21 +000055 }
Neil Fullerb1442272017-12-18 15:59:50 +000056
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 Fuller68f66662017-03-16 18:32:21 +000074}