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 //
|
|
|
|
|
/** {@hide} */
|
|
|
|
|
public static final int EX_TYPE_FILTER_NONE = 0;
|
|
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
|
public static final int EX_TYPE_FILTER_NETWORK_RELEASED = 1;
|
|
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_NOT_BOUND = 2;
|
|
|
|
|
|
|
|
|
|
/** {@hide} */
|
2022-03-07 11:03:13 +00:00
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_NOT_CONNECTED = 3;
|
2020-06-15 16:10:01 -07:00
|
|
|
|
|
|
|
|
/** {@hide} */
|
2022-03-07 11:03:13 +00:00
|
|
|
public static final int EX_TYPE_FILTER_NOT_SUPPORTED = 4;
|
|
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
|
public static final int EX_TYPE_FILTER_SOCKET_LOCAL_ADDRESS_CHANGED = 5;
|
|
|
|
|
|
|
|
|
|
/** {@hide} */
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* {@hide}
|
|
|
|
|
*/
|
|
|
|
|
@NonNull
|
Autogenerate connectivity jarjar rules
Jarjar rules are hard to keep in sync with code, and hard to maintain
manually as the distinction between what should and should not be
jarjared is not always clear. This results in unsafe binaries that are
manually maintained, and developer frustration when something fails due
to incorrect jarjar rules.
Autogenerate jarjar rules at build time instead. This is achieved by
introducing a jarjar-rules-generator python-based library, which scans
pre-jarjar intermediate artifacts, and outputs jarjar rules for every
class to put it in a package specific to the module. The only exceptions
are:
- Classes that are API (module-lib API is the largest API surface of
the module)
- Classes that have unsupportedappusage symbols
- Classes that are excluded manually (for example, because they have
hardcoded external references, like for
ConnectivityServiceInitializer in SystemServer).
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: Ied17c3955ea2fda130089265d02908937ad8af1e
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);
|
|
|
|
|
}
|
|
|
|
|
}
|