blob: 15a571d6750c72cdfdf7ac325d3299dba038d4a6 [file] [log] [blame]
Neil Fuller328532a2017-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
19import android.content.Context;
20import android.os.ParcelFileDescriptor;
21
22import java.io.FileInputStream;
23import java.io.IOException;
24import java.util.concurrent.Executor;
25import libcore.io.Streams;
26
27/**
28 * A single class that implements multiple helper interfaces for use by {@link RulesManagerService}.
29 */
30final class RulesManagerServiceHelperImpl
31 implements PermissionHelper, Executor, FileDescriptorHelper {
32
33 private final Context mContext;
34
35 RulesManagerServiceHelperImpl(Context context) {
36 mContext = context;
37 }
38
39 @Override
40 public void enforceCallerHasPermission(String requiredPermission) {
41 mContext.enforceCallingPermission(requiredPermission, null /* message */);
42 }
43
44 // TODO Wake lock required?
45 @Override
46 public void execute(Runnable runnable) {
47 // TODO Is there a better way?
48 new Thread(runnable).start();
49 }
50
51 @Override
52 public byte[] readFully(ParcelFileDescriptor parcelFileDescriptor) throws IOException {
53 try (ParcelFileDescriptor pfd = parcelFileDescriptor) {
54 // Read bytes
55 FileInputStream in = new FileInputStream(pfd.getFileDescriptor(), false /* isOwner */);
56 return Streams.readFully(in);
57 }
58 }
59}