2020-06-15 16:10:01 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2020 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 android.net;
|
|
|
|
|
|
|
|
|
|
import android.annotation.IntDef;
|
|
|
|
|
import android.annotation.NonNull;
|
|
|
|
|
import android.annotation.SystemApi;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
2022-03-10 03:06:43 +00:00
|
|
|
import com.android.internal.annotations.VisibleForTesting;
|
|
|
|
|
|
2020-06-15 16:10:01 -07:00
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is the exception type passed back through the onError method on {@link QosCallback}.
|
|
|
|
|
* {@link QosCallbackException#getCause()} contains the actual error that caused this exception.
|
|
|
|
|
*
|
|
|
|
|
* The possible exception types as causes are:
|
|
|
|
|
* 1. {@link NetworkReleasedException}
|
|
|
|
|
* 2. {@link SocketNotBoundException}
|
|
|
|
|
* 3. {@link UnsupportedOperationException}
|
|
|
|
|
* 4. {@link SocketLocalAddressChangedException}
|
|
|
|
|
*
|
|
|
|
|
* @hide
|
|
|
|
|
*/
|
|
|
|
|
@SystemApi
|
|
|
|
|
public final class QosCallbackException extends Exception {
|
|
|
|
|
|
|
|
|
|
/** @hide */
|
|
|
|
|
@IntDef(prefix = {"EX_TYPE_"}, value = {
|
|
|
|
|
EX_TYPE_FILTER_NONE,
|
|
|
|
|
EX_TYPE_FILTER_NETWORK_RELEASED,
|
|
|
|
|
EX_TYPE_FILTER_SOCKET_NOT_BOUND,
|
2022-03-07 11:03:13 +00:00
|
|
|
EX_TYPE_FILTER_SOCKET_NOT_CONNECTED,
|
2020-06-15 16:10:01 -07:00
|
|
|
EX_TYPE_FILTER_NOT_SUPPORTED,
|
|
|
|
|
EX_TYPE_FILTER_SOCKET_LOCAL_ADDRESS_CHANGED,
|
2022-03-07 11:03:13 +00:00
|
|
|
EX_TYPE_FILTER_SOCKET_REMOTE_ADDRESS_CHANGED,
|
2020-06-15 16:10:01 -07:00
|
|
|
})
|
|
|
|
|
@Retention(RetentionPolicy.SOURCE)
|
|
|
|
|
public @interface ExceptionType {}
|
|
|
|
|
|
|
|
|
|
private static final String TAG = "QosCallbackException";
|
|
|
|
|
|
|
|
|
|
// Types of exceptions supported //
|
2022-07-13 20:42:13 +09:00
|
|
|
// The constants are used for the sendQosCallbackError system API, so they must not be changed
|
|
|
|
|
// as there may be callers relying on their historical values to call that API.
|
|
|
|
|
// TODO: mark the constants as @SystemApi, since they are necessary to call a system API.
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2020-06-15 16:10:01 -07:00
|
|
|
public static final int EX_TYPE_FILTER_NONE = 0;
|
|
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2020-06-15 16:10:01 -07:00
|
|
|
public static final int EX_TYPE_FILTER_NETWORK_RELEASED = 1;
|
|
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2020-06-15 16:10:01 -07:00
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_NOT_BOUND = 2;
|
|
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2022-07-13 20:42:13 +09:00
|
|
|
public static final int EX_TYPE_FILTER_NOT_SUPPORTED = 3;
|
2020-06-15 16:10:01 -07:00
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2022-07-13 20:42:13 +09:00
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_LOCAL_ADDRESS_CHANGED = 4;
|
2022-03-07 11:03:13 +00:00
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2022-07-13 20:42:13 +09:00
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_NOT_CONNECTED = 5;
|
2022-03-07 11:03:13 +00:00
|
|
|
|
2025-08-29 16:26:42 +00:00
|
|
|
/** @hide */
|
2022-03-07 11:03:13 +00:00
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_REMOTE_ADDRESS_CHANGED = 6;
|
2020-06-15 16:10:01 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates exception based off of a type and message. Not all types of exceptions accept a
|
|
|
|
|
* custom message.
|
|
|
|
|
*
|
2025-08-29 16:26:42 +00:00
|
|
|
* @hide
|
2020-06-15 16:10:01 -07:00
|
|
|
*/
|
|
|
|
|
@NonNull
|
Use jarjar rule generator for connectivity rules
(This rolls forward part of a previous change, now that jarjar was fixed
to not get very slow when the number of rules increases).
Autogenerate connectivity jarjar rules at build time, to avoid issues
with forgotten jarjar rules or hard-to-diagnose errors introduced by
incorrect rules.
This change causes all classes in framework-connectivity(-t) and
service-connectivity to be jarjared into android.net.connectivity, but
still avoids jarjaring classes in com.android.server as before, to keep
it small.
For many classes this differs from the original jarjar rule.
Notes on implementation:
- connectivity-jarjar-rules now has a subset
framework-connectivity-jarjar-rules containing only the rules
necessary for framework-connectivity. This is necessary because
framework-connectivity cannot depend on rules generated based on
service-connectivity, as there would be a dependency cycle
(service-connectivity depends on framework-connectivity); Soong even
crashes with a stack overflow.
- framework-wifi.stubs.module_lib is added to
framework-connectivity-pre-jarjar as it is necessary to build it (it
is already in impl_only_libs in the defaults).
It is unclear why framework-connectivity-pre-jarjar could build
before that (possibly because it was only used as "lib" ?)
- Fix package-private visibility; for example NattSocketKeepalive,
TcpSocketKeepalive are not API so should be jarjared, but are used
by ConnectivityManager which is not jarjared, so they are not in the
same package after the change. Package-private members in the
former 2 need to be public to be accessible. Changes in this commit
are all that is needed, as demonstrated by followup commits that move
the classes to a different package without further changes, and that
enforce that no class in an API package gets jarjared.
- framework-connectivity-internal-test-defaults is separated from
framework-connectivity-test-defaults, for unit tests that need to
access internal jarjared classes. Such tests need to use the jarjar
rules themselves too, so this is only appropriate for connectivity
internal unit tests.
Test: atest ConnectivityCoverageTests CtsNetTestCases
Bug: 217129444
Change-Id: Ib1bd939b71c0171d945fc01b96195d2f620ff13b
2022-04-20 15:59:16 +09:00
|
|
|
public static QosCallbackException createException(@ExceptionType final int type) {
|
2020-06-15 16:10:01 -07:00
|
|
|
switch (type) {
|
|
|
|
|
case EX_TYPE_FILTER_NETWORK_RELEASED:
|
|
|
|
|
return new QosCallbackException(new NetworkReleasedException());
|
|
|
|
|
case EX_TYPE_FILTER_SOCKET_NOT_BOUND:
|
|
|
|
|
return new QosCallbackException(new SocketNotBoundException());
|
2022-03-07 11:03:13 +00:00
|
|
|
case EX_TYPE_FILTER_SOCKET_NOT_CONNECTED:
|
|
|
|
|
return new QosCallbackException(new SocketNotConnectedException());
|
2020-06-15 16:10:01 -07:00
|
|
|
case EX_TYPE_FILTER_NOT_SUPPORTED:
|
|
|
|
|
return new QosCallbackException(new UnsupportedOperationException(
|
|
|
|
|
"This device does not support the specified filter"));
|
|
|
|
|
case EX_TYPE_FILTER_SOCKET_LOCAL_ADDRESS_CHANGED:
|
|
|
|
|
return new QosCallbackException(
|
|
|
|
|
new SocketLocalAddressChangedException());
|
2022-03-07 11:03:13 +00:00
|
|
|
case EX_TYPE_FILTER_SOCKET_REMOTE_ADDRESS_CHANGED:
|
|
|
|
|
return new QosCallbackException(
|
|
|
|
|
new SocketRemoteAddressChangedException());
|
2020-06-15 16:10:01 -07:00
|
|
|
default:
|
|
|
|
|
Log.wtf(TAG, "create: No case setup for exception type: '" + type + "'");
|
|
|
|
|
return new QosCallbackException(
|
|
|
|
|
new RuntimeException("Unknown exception code: " + type));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 03:06:43 +00:00
|
|
|
@VisibleForTesting
|
2020-06-15 16:10:01 -07:00
|
|
|
public QosCallbackException(@NonNull final String message) {
|
|
|
|
|
super(message);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-10 03:06:43 +00:00
|
|
|
@VisibleForTesting
|
2020-06-15 16:10:01 -07:00
|
|
|
public QosCallbackException(@NonNull final Throwable cause) {
|
|
|
|
|
super(cause);
|
|
|
|
|
}
|
|
|
|
|
}
|