blob: 6a58852f4210a9e67280fad60f3d2193e5dc1c5d [file] [log] [blame]
Glenn Kasten44deb052012-02-05 18:09:08 -08001/*
2 * Copyright (C) 2012 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#include <binder/IPCThreadState.h>
18#include <binder/IServiceManager.h>
19#include <binder/PermissionCache.h>
20#include "ServiceUtilities.h"
21
22namespace android {
23
24// This optimization assumes mediaserver process doesn't fork, which it doesn't
25const pid_t getpid_cached = getpid();
26
27bool recordingAllowed() {
28 if (getpid_cached == IPCThreadState::self()->getCallingPid()) return true;
29 static const String16 sRecordAudio("android.permission.RECORD_AUDIO");
30 // don't use PermissionCache; this is not a system permission
31 bool ok = checkCallingPermission(sRecordAudio);
32 if (!ok) ALOGE("Request requires android.permission.RECORD_AUDIO");
33 return ok;
34}
35
36bool settingsAllowed() {
37 if (getpid_cached == IPCThreadState::self()->getCallingPid()) return true;
38 static const String16 sAudioSettings("android.permission.MODIFY_AUDIO_SETTINGS");
39 // don't use PermissionCache; this is not a system permission
40 bool ok = checkCallingPermission(sAudioSettings);
41 if (!ok) ALOGE("Request requires android.permission.MODIFY_AUDIO_SETTINGS");
42 return ok;
43}
44
45bool dumpAllowed() {
46 // don't optimize for same pid, since mediaserver never dumps itself
47 static const String16 sDump("android.permission.DUMP");
48 // OK to use PermissionCache; this is a system permission
49 bool ok = PermissionCache::checkCallingPermission(sDump);
50 // convention is for caller to dump an error message to fd instead of logging here
51 //if (!ok) ALOGE("Request requires android.permission.DUMP");
52 return ok;
53}
54
55} // namespace android