diff options
author | Enrico Granata <egranata@google.com> | 2017-02-23 18:07:59 -0800 |
---|---|---|
committer | Enrico Granata <egranata@google.com> | 2017-02-24 15:51:42 -0800 |
commit | 3c7a66693e28acaa82d3c9ff2ed99712270c889f (patch) | |
tree | 9e02265ea5513053347af74ffbb52030998c1321 /car-lib/src/com | |
parent | 15ba610af04a4b517863c8f93dd79e229fe4ab8c (diff) | |
download | Car-3c7a66693e28acaa82d3c9ff2ed99712270c889f.tar.gz |
Permission support for diagnostics.
This creates two permissions for access to diagnostic data:
- DIAGNOSTIC_READ, for read-only access to live and freeze frame data;
- DIAGNOSTIC_CLEAR, for deleting DTC data from the car.
It also extends the meaning of PERMISSION_VENDOR_EXTENSION to mean being allowed to read vendor-specific diagnostic sensor data.
Test: build
Bug: 35435164
For O-MR1.
Change-Id: I046bf6ae4a7aa2b2570ea5657bff9e1ce86edbce
Diffstat (limited to 'car-lib/src/com')
-rw-r--r-- | car-lib/src/com/android/car/internal/CarPermission.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/car-lib/src/com/android/car/internal/CarPermission.java b/car-lib/src/com/android/car/internal/CarPermission.java new file mode 100644 index 0000000000..0b3820f819 --- /dev/null +++ b/car-lib/src/com/android/car/internal/CarPermission.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * 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. + */ + +package com.android.car.internal; + +import android.content.Context; +import android.content.pm.PackageManager; +import android.os.Binder; +import android.os.Process; + +/** + * Represent an Android permission. + * + * @hide + */ +public class CarPermission { + private final Context mContext; + private final String mName; + + /** @hide */ + public CarPermission(Context context, String name) { + mContext = context; + mName = name; + } + + /** @hide */ + public boolean checkGranted() { + if (mName != null) { + if (Binder.getCallingUid() != Process.myUid()) { + return PackageManager.PERMISSION_GRANTED == + mContext.checkCallingOrSelfPermission(mName); + } + } + return true; + } + + /** @hide */ + public void assertGranted() { + if (checkGranted()) return; + throw new SecurityException( + "client does not have permission:" + + mName + + " pid:" + + Binder.getCallingPid() + + " uid:" + + Binder.getCallingUid()); + } +} |