Merge "Remove the implementation of deprecated ContextHub APIs" into main
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 3a58993..218b023 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -256,6 +256,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     public int[] getContextHubHandles() {
+        if (Flags.removeOldContextHubApis()) {
+            return null;
+        }
+
         try {
             return mService.getContextHubHandles();
         } catch (RemoteException e) {
@@ -277,6 +281,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     public ContextHubInfo getContextHubInfo(int hubHandle) {
+        if (Flags.removeOldContextHubApis()) {
+            return null;
+        }
+
         try {
             return mService.getContextHubInfo(hubHandle);
         } catch (RemoteException e) {
@@ -308,6 +316,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     public int loadNanoApp(int hubHandle, @NonNull NanoApp app) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         try {
             return mService.loadNanoApp(hubHandle, app);
         } catch (RemoteException e) {
@@ -335,6 +347,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     public int unloadNanoApp(int nanoAppHandle) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         try {
             return mService.unloadNanoApp(nanoAppHandle);
         } catch (RemoteException e) {
@@ -375,6 +391,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     @Nullable public NanoAppInstanceInfo getNanoAppInstanceInfo(int nanoAppHandle) {
+        if (Flags.removeOldContextHubApis()) {
+            return null;
+        }
+
         try {
             return mService.getNanoAppInstanceInfo(nanoAppHandle);
         } catch (RemoteException e) {
@@ -398,6 +418,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     @NonNull public int[] findNanoAppOnHub(int hubHandle, @NonNull NanoAppFilter filter) {
+        if (Flags.removeOldContextHubApis()) {
+            return null;
+        }
+
         try {
             return mService.findNanoAppOnHub(hubHandle, filter);
         } catch (RemoteException e) {
@@ -433,6 +457,10 @@
     @Deprecated
     @RequiresPermission(android.Manifest.permission.ACCESS_CONTEXT_HUB)
     public int sendMessage(int hubHandle, int nanoAppHandle, @NonNull ContextHubMessage message) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         try {
             return mService.sendMessage(hubHandle, nanoAppHandle, message);
         } catch (RemoteException e) {
@@ -648,6 +676,10 @@
     @Deprecated
     @SuppressLint("RequiresPermission")
     public int registerCallback(@NonNull Callback callback) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         return registerCallback(callback, null);
     }
 
@@ -657,6 +689,10 @@
      */
     @Deprecated
     public int registerCallback(ICallback callback) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         if (mLocalCallback != null) {
             Log.w(TAG, "Max number of local callbacks reached!");
             return -1;
@@ -682,6 +718,10 @@
     @Deprecated
     @SuppressLint("RequiresPermission")
     public int registerCallback(Callback callback, Handler handler) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         synchronized(this) {
             if (mCallback != null) {
                 Log.w(TAG, "Max number of callbacks reached!");
@@ -1041,16 +1081,20 @@
     @SuppressLint("RequiresPermission")
     @Deprecated
     public int unregisterCallback(@NonNull Callback callback) {
-      synchronized(this) {
-          if (callback != mCallback) {
-              Log.w(TAG, "Cannot recognize callback!");
-              return -1;
-          }
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
 
-          mCallback = null;
-          mCallbackHandler = null;
-      }
-      return 0;
+        synchronized (this) {
+            if (callback != mCallback) {
+                Log.w(TAG, "Cannot recognize callback!");
+                return -1;
+            }
+
+            mCallback = null;
+            mCallbackHandler = null;
+        }
+        return 0;
     }
 
     /**
@@ -1059,6 +1103,10 @@
      */
     @Deprecated
     public synchronized int unregisterCallback(ICallback callback) {
+        if (Flags.removeOldContextHubApis()) {
+            return -1;
+        }
+
         if (callback != mLocalCallback) {
             Log.w(TAG, "Cannot recognize local callback!");
             return -1;