OSDN Git Service

Add LOCATION_HARDWARE permission to Rtt API.
authorWei Wang <weiwa@google.com>
Wed, 16 Aug 2017 18:54:27 +0000 (11:54 -0700)
committerWei Wang <weiwa@google.com>
Thu, 17 Aug 2017 21:46:20 +0000 (14:46 -0700)
Test: Manual
Bug: 62264080
Bug: 62344058

Change-Id: I00744a046c0fdcccd2f10924a70d816372e49fa4

wifi/java/android/net/wifi/RttManager.java

index ac5df05..dc5ba0c 100644 (file)
@@ -1,5 +1,6 @@
 package android.net.wifi;
 
+import android.Manifest;
 import android.annotation.NonNull;
 import android.annotation.RequiresPermission;
 import android.annotation.SuppressLint;
@@ -313,6 +314,7 @@ public class RttManager {
              };
     }
 
+    @RequiresPermission(Manifest.permission.LOCATION_HARDWARE)
     public RttCapabilities getRttCapabilities() {
         synchronized (mCapabilitiesLock) {
             if (mRttCapabilities == null) {
@@ -925,6 +927,51 @@ public class RttManager {
         public void onAborted();
     }
 
+    /**
+     * A parcelable that contains rtt client information.
+     *
+     * @hide
+     */
+    public static class RttClient implements Parcelable {
+        // Package name of RttClient.
+        private final String mPackageName;
+
+        public RttClient(String packageName) {
+            mPackageName = packageName;
+        }
+
+        protected RttClient(Parcel in) {
+            mPackageName = in.readString();
+        }
+
+        public static final Creator<RttManager.RttClient> CREATOR =
+                new Creator<RttManager.RttClient>() {
+            @Override
+            public RttManager.RttClient createFromParcel(Parcel in) {
+                return new RttManager.RttClient(in);
+            }
+
+            @Override
+            public RttManager.RttClient[] newArray(int size) {
+                return new RttManager.RttClient[size];
+            }
+        };
+
+        @Override
+        public int describeContents() {
+            return 0;
+        }
+
+        @Override
+        public void writeToParcel(Parcel parcel, int i) {
+            parcel.writeString(mPackageName);
+        }
+
+        public String getPackageName() {
+            return mPackageName;
+        }
+    }
+
     private boolean rttParamSanity(RttParams params, int index) {
         if (mRttCapabilities == null) {
             if(getRttCapabilities() == null) {
@@ -1236,7 +1283,8 @@ public class RttManager {
         mAsyncChannel.connectSync(mContext, handler, messenger);
         // We cannot use fullyConnectSync because it sends the FULL_CONNECTION message
         // synchronously, which causes RttService to receive the wrong replyTo value.
-        mAsyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
+        mAsyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION,
+                new RttClient(context.getPackageName()));
         mAsyncChannel.sendMessage(CMD_OP_REG_BINDER, key[0]);
     }