1 /*
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  */
16 
17 package android.net.ipmemorystore;
18 
19 import android.annotation.NonNull;
20 
21 /**
22  * A listener for the IpMemoryStore to return network attributes.
23  * @hide
24  */
25 public interface OnNetworkAttributesRetrievedListener {
26     /**
27      * The memory store has come up with the answer to a query that was sent.
28      */
onNetworkAttributesRetrieved(Status status, String l2Key, NetworkAttributes attributes)29     void onNetworkAttributesRetrieved(Status status, String l2Key, NetworkAttributes attributes);
30 
31     /** Converts this OnNetworkAttributesRetrievedListener to a parcelable object */
32     @NonNull
toAIDL( @onNull final OnNetworkAttributesRetrievedListener listener)33     static IOnNetworkAttributesRetrievedListener toAIDL(
34             @NonNull final OnNetworkAttributesRetrievedListener listener) {
35         return new IOnNetworkAttributesRetrievedListener.Stub() {
36             @Override
37             public void onNetworkAttributesRetrieved(final StatusParcelable statusParcelable,
38                     final String l2Key,
39                     final NetworkAttributesParcelable networkAttributesParcelable) {
40                 // NonNull, but still don't crash the system server if null
41                 if (null != listener) {
42                     listener.onNetworkAttributesRetrieved(
43                             new Status(statusParcelable), l2Key, null == networkAttributesParcelable
44                                 ? null : new NetworkAttributes(networkAttributesParcelable));
45                 }
46             }
47 
48             @Override
49             public int getInterfaceVersion() {
50                 return this.VERSION;
51             }
52         };
53     }
54 }
55