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 android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.os.AsyncTask; 22 import android.os.Binder; 23 import android.os.ParcelFileDescriptor; 24 25 import java.io.FileInputStream; 26 import java.io.IOException; 27 import java.io.PrintWriter; 28 import java.util.concurrent.Executor; 29 import libcore.io.Streams; 30 31 /** 32 * A single class that implements multiple helper interfaces for use by {@link RulesManagerService}. 33 */ 34 final class RulesManagerServiceHelperImpl implements PermissionHelper, Executor { 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 // TODO(nfuller): Switch to DumpUtils.checkDumpPermission() when it is available in AOSP. 50 if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) 51 != PackageManager.PERMISSION_GRANTED) { 52 pw.println("Permission Denial: can't dump LocationManagerService from from pid=" 53 + Binder.getCallingPid() 54 + ", uid=" + Binder.getCallingUid()); 55 return false; 56 } 57 return true; 58 } 59 60 @Override 61 public void execute(Runnable runnable) { 62 AsyncTask.execute(runnable); 63 } 64 } 65