• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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.location;
18 
19 import android.content.Context;
20 import android.hardware.location.IFusedLocationHardware;
21 import android.hardware.location.IFusedLocationHardwareSink;
22 import android.location.FusedBatchOptions;
23 import android.os.RemoteException;
24 
25 /**
26  * FusedLocationHardware decorator that adds permission checking.
27  * @hide
28  */
29 public class FusedLocationHardwareSecure extends IFusedLocationHardware.Stub {
30     private final IFusedLocationHardware mLocationHardware;
31     private final Context mContext;
32     private final String mPermissionId;
33 
FusedLocationHardwareSecure( IFusedLocationHardware locationHardware, Context context, String permissionId)34     public FusedLocationHardwareSecure(
35             IFusedLocationHardware locationHardware,
36             Context context,
37             String permissionId) {
38         mLocationHardware = locationHardware;
39         mContext = context;
40         mPermissionId = permissionId;
41     }
42 
checkPermissions()43     private void checkPermissions() {
44         mContext.enforceCallingPermission(
45                 mPermissionId,
46                 String.format(
47                         "Permission '%s' not granted to access FusedLocationHardware",
48                         mPermissionId));
49     }
50 
51     @Override
registerSink(IFusedLocationHardwareSink eventSink)52     public void registerSink(IFusedLocationHardwareSink eventSink) throws RemoteException {
53         checkPermissions();
54         mLocationHardware.registerSink(eventSink);
55     }
56 
57     @Override
unregisterSink(IFusedLocationHardwareSink eventSink)58     public void unregisterSink(IFusedLocationHardwareSink eventSink) throws RemoteException {
59         checkPermissions();
60         mLocationHardware.unregisterSink(eventSink);
61     }
62 
63     @Override
getSupportedBatchSize()64     public int getSupportedBatchSize() throws RemoteException {
65         checkPermissions();
66         return mLocationHardware.getSupportedBatchSize();
67     }
68 
69     @Override
startBatching(int id, FusedBatchOptions batchOptions)70     public void startBatching(int id, FusedBatchOptions batchOptions) throws RemoteException {
71         checkPermissions();
72         mLocationHardware.startBatching(id, batchOptions);
73     }
74 
75     @Override
stopBatching(int id)76     public void stopBatching(int id) throws RemoteException {
77         checkPermissions();
78         mLocationHardware.stopBatching(id);
79     }
80 
81     @Override
updateBatchingOptions( int id, FusedBatchOptions batchoOptions )82     public void updateBatchingOptions(
83             int id,
84             FusedBatchOptions batchoOptions
85             ) throws RemoteException {
86         checkPermissions();
87         mLocationHardware.updateBatchingOptions(id, batchoOptions);
88     }
89 
90     @Override
requestBatchOfLocations(int batchSizeRequested)91     public void requestBatchOfLocations(int batchSizeRequested) throws RemoteException {
92         checkPermissions();
93         mLocationHardware.requestBatchOfLocations(batchSizeRequested);
94     }
95 
96     @Override
supportsDiagnosticDataInjection()97     public boolean supportsDiagnosticDataInjection() throws RemoteException {
98         checkPermissions();
99         return mLocationHardware.supportsDiagnosticDataInjection();
100     }
101 
102     @Override
injectDiagnosticData(String data)103     public void injectDiagnosticData(String data) throws RemoteException {
104         checkPermissions();
105         mLocationHardware.injectDiagnosticData(data);
106     }
107 
108     @Override
supportsDeviceContextInjection()109     public boolean supportsDeviceContextInjection() throws RemoteException {
110         checkPermissions();
111         return mLocationHardware.supportsDeviceContextInjection();
112     }
113 
114     @Override
injectDeviceContext(int deviceEnabledContext)115     public void injectDeviceContext(int deviceEnabledContext) throws RemoteException {
116         checkPermissions();
117         mLocationHardware.injectDeviceContext(deviceEnabledContext);
118     }
119 }
120