1 /* 2 * Copyright (C) 2014 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.location.provider; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.hardware.location.IActivityRecognitionHardware; 22 import android.hardware.location.IActivityRecognitionHardwareWatcher; 23 import android.os.Binder; 24 import android.os.IBinder; 25 import android.os.Process; 26 import android.os.RemoteException; 27 import android.util.Log; 28 29 /** 30 * A watcher class for Activity-Recognition instances. 31 * 32 * @deprecated use {@link ActivityRecognitionProviderClient} instead. 33 * @hide 34 */ 35 @Deprecated 36 public class ActivityRecognitionProviderWatcher { 37 private static final String TAG = "ActivityRecognitionProviderWatcher"; 38 39 private static ActivityRecognitionProviderWatcher sWatcher; 40 private static final Object sWatcherLock = new Object(); 41 42 private ActivityRecognitionProvider mActivityRecognitionProvider; 43 ActivityRecognitionProviderWatcher()44 private ActivityRecognitionProviderWatcher() {} 45 getInstance()46 public static ActivityRecognitionProviderWatcher getInstance() { 47 synchronized (sWatcherLock) { 48 if (sWatcher == null) { 49 sWatcher = new ActivityRecognitionProviderWatcher(); 50 } 51 return sWatcher; 52 } 53 } 54 55 private IActivityRecognitionHardwareWatcher.Stub mWatcherStub = 56 new IActivityRecognitionHardwareWatcher.Stub() { 57 @Override 58 public void onInstanceChanged(IActivityRecognitionHardware instance) { 59 int callingUid = Binder.getCallingUid(); 60 if (callingUid != Process.SYSTEM_UID) { 61 Log.d(TAG, "Ignoring calls from non-system server. Uid: " + callingUid); 62 return; 63 } 64 65 try { 66 mActivityRecognitionProvider = new ActivityRecognitionProvider(instance); 67 } catch (RemoteException e) { 68 Log.e(TAG, "Error creating Hardware Activity-Recognition", e); 69 } 70 } 71 }; 72 73 /** 74 * Gets the binder needed to interact with proxy provider in the platform. 75 */ 76 @NonNull getBinder()77 public IBinder getBinder() { 78 return mWatcherStub; 79 } 80 81 /** 82 * Gets an object that supports the functionality of {@link ActivityRecognitionProvider}. 83 * 84 * @return Non-null value if the functionality is supported by the platform, false otherwise. 85 */ 86 @Nullable getActivityRecognitionProvider()87 public ActivityRecognitionProvider getActivityRecognitionProvider() { 88 return mActivityRecognitionProvider; 89 } 90 } 91