blob: dd67dddae1cd7186cf8fdca1d2a999a08888d7c5 [file] [log] [blame]
markchienf87ebdc2019-12-07 22:02:28 +08001/*
2 * Copyright (C) 2019 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 */
16package android.net.util;
17
markchienf053e4b2020-03-16 21:49:48 +080018import android.net.TetheringRequestParcel;
19
markchienf87ebdc2019-12-07 22:02:28 +080020import java.io.FileDescriptor;
21import java.net.SocketException;
markchienf053e4b2020-03-16 21:49:48 +080022import java.util.Objects;
markchienf87ebdc2019-12-07 22:02:28 +080023
24/**
25 * Native methods for tethering utilization.
26 *
27 * {@hide}
28 */
29public class TetheringUtils {
markchienf87ebdc2019-12-07 22:02:28 +080030 /**
31 * Configures a socket for receiving ICMPv6 router solicitations and sending advertisements.
32 * @param fd the socket's {@link FileDescriptor}.
33 * @param ifIndex the interface index.
34 */
35 public static native void setupRaSocket(FileDescriptor fd, int ifIndex)
36 throws SocketException;
markchien6cf0e552019-12-06 15:24:53 +080037
38 /**
39 * Read s as an unsigned 16-bit integer.
40 */
41 public static int uint16(short s) {
42 return s & 0xffff;
43 }
markchienf053e4b2020-03-16 21:49:48 +080044
45 /** Check whether two TetheringRequestParcels are the same. */
46 public static boolean isTetheringRequestEquals(final TetheringRequestParcel request,
47 final TetheringRequestParcel otherRequest) {
48 if (request == otherRequest) return true;
49
50 return request != null && otherRequest != null
51 && request.tetheringType == otherRequest.tetheringType
52 && Objects.equals(request.localIPv4Address, otherRequest.localIPv4Address)
53 && Objects.equals(request.staticClientAddress, otherRequest.staticClientAddress)
54 && request.exemptFromEntitlementCheck == otherRequest.exemptFromEntitlementCheck
55 && request.showProvisioningUi == otherRequest.showProvisioningUi;
56 }
markchienf87ebdc2019-12-07 22:02:28 +080057}