Home | History | Annotate | Download | only in provider
      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  */
     34 @Deprecated
     35 public class ActivityRecognitionProviderWatcher {
     36     private static final String TAG = "ActivityRecognitionProviderWatcher";
     37 
     38     private static ActivityRecognitionProviderWatcher sWatcher;
     39     private static final Object sWatcherLock = new Object();
     40 
     41     private ActivityRecognitionProvider mActivityRecognitionProvider;
     42 
     43     private ActivityRecognitionProviderWatcher() {}
     44 
     45     public static ActivityRecognitionProviderWatcher getInstance() {
     46         synchronized (sWatcherLock) {
     47             if (sWatcher == null) {
     48                 sWatcher = new ActivityRecognitionProviderWatcher();
     49             }
     50             return sWatcher;
     51         }
     52     }
     53 
     54     private IActivityRecognitionHardwareWatcher.Stub mWatcherStub =
     55             new IActivityRecognitionHardwareWatcher.Stub() {
     56         @Override
     57         public void onInstanceChanged(IActivityRecognitionHardware instance) {
     58             int callingUid = Binder.getCallingUid();
     59             if (callingUid != Process.SYSTEM_UID) {
     60                 Log.d(TAG, "Ignoring calls from non-system server. Uid: " + callingUid);
     61                 return;
     62             }
     63 
     64             try {
     65                 mActivityRecognitionProvider = new ActivityRecognitionProvider(instance);
     66             } catch (RemoteException e) {
     67                 Log.e(TAG, "Error creating Hardware Activity-Recognition", e);
     68             }
     69         }
     70     };
     71 
     72     /**
     73      * Gets the binder needed to interact with proxy provider in the platform.
     74      */
     75     @NonNull
     76     public IBinder getBinder() {
     77         return mWatcherStub;
     78     }
     79 
     80     /**
     81      * Gets an object that supports the functionality of {@link ActivityRecognitionProvider}.
     82      *
     83      * @return Non-null value if the functionality is supported by the platform, false otherwise.
     84      */
     85     @Nullable
     86     public ActivityRecognitionProvider getActivityRecognitionProvider() {
     87         return mActivityRecognitionProvider;
     88     }
     89 }
     90