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 19 import com.android.internal.util.DumpUtils; 20 21 import android.app.timezone.RulesManager; 22 import android.content.Context; 23 import android.content.Intent; 24 import android.os.AsyncTask; 25 import android.os.UserHandle; 26 27 import java.io.PrintWriter; 28 import java.util.concurrent.Executor; 29 30 /** 31 * A single class that implements multiple helper interfaces for use by {@link RulesManagerService}. 32 */ 33 final class RulesManagerServiceHelperImpl 34 implements PermissionHelper, Executor, RulesManagerIntentHelper { 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 47 @Override 48 public boolean checkDumpPermission(String tag, PrintWriter pw) { 49 return DumpUtils.checkDumpPermission(mContext, tag, pw); 50 } 51 52 @Override 53 public void execute(Runnable runnable) { 54 AsyncTask.execute(runnable); 55 } 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 74 } 75