1 /*
2  * Copyright (C) 2021 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  */
16 
17 package android.net;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.os.Looper;
22 import android.os.Message;
23 
24 import com.android.internal.annotations.VisibleForTesting;
25 
26 import java.io.FileDescriptor;
27 import java.io.PrintWriter;
28 
29 /**
30  * Extract an interface for multiple implementation of {@link NetworkFactory}, depending on the SDK
31  * version.
32  *
33  * Known implementations:
34  * - {@link NetworkFactoryImpl}: For Android S+
35  * - {@link NetworkFactoryLegacyImpl}: For Android R-
36  *
37  * @hide
38  */
39 interface NetworkFactoryShim {
register(String logTag)40     void register(String logTag);
41 
registerIgnoringScore(String logTag)42     default void registerIgnoringScore(String logTag) {
43         throw new UnsupportedOperationException();
44     }
45 
terminate()46     void terminate();
47 
releaseRequestAsUnfulfillableByAnyFactory(NetworkRequest r)48     void releaseRequestAsUnfulfillableByAnyFactory(NetworkRequest r);
49 
reevaluateAllRequests()50     void reevaluateAllRequests();
51 
setScoreFilter(int score)52     void setScoreFilter(int score);
53 
setScoreFilter(@onNull NetworkScore score)54     void setScoreFilter(@NonNull NetworkScore score);
55 
setCapabilityFilter(NetworkCapabilities netCap)56     void setCapabilityFilter(NetworkCapabilities netCap);
57 
getRequestCount()58     int getRequestCount();
59 
getSerialNumber()60     int getSerialNumber();
61 
getProvider()62     NetworkProvider getProvider();
63 
dump(FileDescriptor fd, PrintWriter writer, String[] args)64     void dump(FileDescriptor fd, PrintWriter writer, String[] args);
65 
66     // All impls inherit Handler
67     @VisibleForTesting
obtainMessage(int what, int arg1, int arg2, @Nullable Object obj)68     Message obtainMessage(int what, int arg1, int arg2, @Nullable Object obj);
69 
getLooper()70     Looper getLooper();
71 }
72