зеркало из https://github.com/mozilla/gecko-dev.git
109 строки
3.0 KiB
C++
109 строки
3.0 KiB
C++
/*
|
|
* Copyright (C) 2012 Mozilla Foundation
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "GonkPermission.h"
|
|
#include <binder/IPCThreadState.h>
|
|
#include <binder/ProcessState.h>
|
|
#include <binder/IServiceManager.h>
|
|
#include <binder/IPermissionController.h>
|
|
|
|
#ifndef HAVE_ANDROID_OS
|
|
#define HAVE_ANDROID_OS 1
|
|
#endif
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
#include "mozilla/dom/TabParent.h"
|
|
#include "mozilla/SyncRunnable.h"
|
|
#include "nsThreadUtils.h"
|
|
|
|
#undef LOG
|
|
#include <android/log.h>
|
|
#undef ALOGE
|
|
#define ALOGE(args...) __android_log_print(ANDROID_LOG_ERROR, "gonkperm" , ## args)
|
|
|
|
using namespace android;
|
|
using namespace mozilla;
|
|
|
|
bool
|
|
GonkPermissionService::checkPermission(const String16& permission, int32_t pid,
|
|
int32_t uid)
|
|
{
|
|
// root can do anything.
|
|
if (0 == uid) {
|
|
return true;
|
|
}
|
|
|
|
String8 perm8(permission);
|
|
|
|
// Some ril implementations need android.permission.MODIFY_AUDIO_SETTINGS
|
|
if ((uid == AID_SYSTEM || uid == AID_RADIO || uid == AID_BLUETOOTH) &&
|
|
perm8 == "android.permission.MODIFY_AUDIO_SETTINGS") {
|
|
return true;
|
|
}
|
|
|
|
// No other permissions apply to non-app processes.
|
|
if (uid < AID_APP) {
|
|
ALOGE("%s for pid=%d,uid=%d denied: not an app",
|
|
String8(permission).string(), pid, uid);
|
|
return false;
|
|
}
|
|
|
|
// Only these permissions can be granted to apps through this service.
|
|
if (perm8 != "android.permission.CAMERA" &&
|
|
perm8 != "android.permission.RECORD_AUDIO") {
|
|
ALOGE("%s for pid=%d,uid=%d denied: unsupported permission",
|
|
String8(permission).string(), pid, uid);
|
|
return false;
|
|
}
|
|
|
|
// Users granted the permission through a prompt dialog.
|
|
// Before permission managment of gUM is done, app cannot remember the
|
|
// permission.
|
|
PermissionGrant permGrant(perm8.string(), pid);
|
|
if (nsTArray<PermissionGrant>::NoIndex != mGrantArray.IndexOf(permGrant)) {
|
|
mGrantArray.RemoveElement(permGrant);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static GonkPermissionService* gGonkPermissionService = NULL;
|
|
|
|
/* static */
|
|
void
|
|
GonkPermissionService::instantiate()
|
|
{
|
|
defaultServiceManager()->addService(String16(getServiceName()),
|
|
GetInstance());
|
|
}
|
|
|
|
/* static */
|
|
GonkPermissionService*
|
|
GonkPermissionService::GetInstance()
|
|
{
|
|
if (!gGonkPermissionService) {
|
|
gGonkPermissionService = new GonkPermissionService();
|
|
}
|
|
return gGonkPermissionService;
|
|
}
|
|
|
|
void
|
|
GonkPermissionService::addGrantInfo(const char* permission, int32_t pid)
|
|
{
|
|
mGrantArray.AppendElement(PermissionGrant(permission, pid));
|
|
}
|