summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-03-29 13:14:15 -0700
committerRebecca Silberstein <silberst@google.com>2017-04-28 22:24:05 -0700
commit768b7a7cb87525e92eb1a59a7a3e0c98b9f6f238 (patch)
tree3a227d9e79fb60ebf17ee37942449ee58fb76a12 /service
parent003b695597a1f010724662fbf4ac76953a71e3b8 (diff)
LocalOnlyHotspotRequestInfo: track LOHS requests
Add a new class to keep track of apps Binder instances that request LocalOnlyHotspot. When the app dies, it will trigger a callback to remove the request. We will also unlinkToDeath when the app calls to stop using LocalOnlyHotspot. This object also contains a Messenger that will allow WifiServiceImpl to communicate updates to WifiManager for the requesting app. Bug: 36732530 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: Ia366a3cc7339cdea94a137d62905b15b72cf05c0
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/LocalOnlyHotspotRequestInfo.java96
1 files changed, 96 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/LocalOnlyHotspotRequestInfo.java b/service/java/com/android/server/wifi/LocalOnlyHotspotRequestInfo.java
new file mode 100644
index 000000000..2925d966b
--- /dev/null
+++ b/service/java/com/android/server/wifi/LocalOnlyHotspotRequestInfo.java
@@ -0,0 +1,96 @@
+/*
+ * 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.server.wifi;
+
+import android.annotation.NonNull;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Message;
+import android.os.Messenger;
+import android.os.RemoteException;
+
+import com.android.internal.util.Preconditions;
+
+/**
+ * Tracks information about applications requesting use of the LocalOnlyHotspot.
+ *
+ * @hide
+ */
+public class LocalOnlyHotspotRequestInfo implements IBinder.DeathRecipient {
+ private final int mUid;
+ private final IBinder mBinder;
+ private final RequestingApplicationDeathCallback mCallback;
+ private final Messenger mMessenger;
+
+ /**
+ * Callback for use with LocalOnlyHotspot to unregister requesting applications upon death.
+ */
+ public interface RequestingApplicationDeathCallback {
+ /**
+ * Called when requesting app has died.
+ */
+ void onLocalOnlyHotspotRequestorDeath(LocalOnlyHotspotRequestInfo requestor);
+ }
+
+ LocalOnlyHotspotRequestInfo(@NonNull IBinder binder, @NonNull Messenger messenger,
+ @NonNull RequestingApplicationDeathCallback callback) {
+ mUid = Binder.getCallingUid();
+ mBinder = Preconditions.checkNotNull(binder);
+ mMessenger = Preconditions.checkNotNull(messenger);
+ mCallback = Preconditions.checkNotNull(callback);
+
+ try {
+ mBinder.linkToDeath(this, 0);
+ } catch (RemoteException e) {
+ binderDied();
+ }
+ }
+
+ /**
+ * Allow caller to unlink this object from binder death.
+ */
+ public void unlinkDeathRecipient() {
+ mBinder.unlinkToDeath(this, 0);
+ }
+
+ /**
+ * Application requesting LocalOnlyHotspot died
+ */
+ @Override
+ public void binderDied() {
+ mCallback.onLocalOnlyHotspotRequestorDeath(this);
+ }
+
+ /**
+ * Send a message to WifiManager for the calling application.
+ *
+ * @param what Message type to send
+ * @param arg1 arg1 for the message
+ *
+ * @throws RemoteException
+ */
+ public void sendMessage(int what, int arg1) throws RemoteException {
+ Message message = Message.obtain();
+ message.what = what;
+ message.arg1 = arg1;
+ mMessenger.send(message);
+ }
+
+ public int getUid() {
+ return mUid;
+ }
+}