1 /*
2  * Copyright (C) 2022 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 package com.google.android.iwlan;
17 
18 import android.os.Handler;
19 
20 import com.google.android.iwlan.IwlanDataService.IwlanDataServiceProvider;
21 
22 public class IwlanTunnelMetricsImpl implements TunnelMetricsInterface {
23     IwlanDataServiceProvider mDataServiceProvider;
24     Handler mIwlanDataServiceHandler;
25 
26     private static final int EVENT_BASE = IwlanEventListener.DATA_SERVICE_INTERNAL_EVENT_BASE;
27     private static final int EVENT_TUNNEL_OPENED_METRICS = EVENT_BASE + 8;
28     private static final int EVENT_TUNNEL_CLOSED_METRICS = EVENT_BASE + 9;
29 
IwlanTunnelMetricsImpl(IwlanDataServiceProvider dsp, Handler handler)30     public IwlanTunnelMetricsImpl(IwlanDataServiceProvider dsp, Handler handler) {
31         mDataServiceProvider = dsp;
32         mIwlanDataServiceHandler = handler;
33     }
34 
onOpened(OnOpenedMetrics metricsData)35     public void onOpened(OnOpenedMetrics metricsData) {
36         metricsData.setIwlanDataServiceProvider(mDataServiceProvider);
37         mIwlanDataServiceHandler.sendMessage(
38                 mIwlanDataServiceHandler.obtainMessage(EVENT_TUNNEL_OPENED_METRICS, metricsData));
39     }
40 
onClosed(OnClosedMetrics metricsData)41     public void onClosed(OnClosedMetrics metricsData) {
42         metricsData.setIwlanDataServiceProvider(mDataServiceProvider);
43         mIwlanDataServiceHandler.sendMessage(
44                 mIwlanDataServiceHandler.obtainMessage(EVENT_TUNNEL_CLOSED_METRICS, metricsData));
45     }
46 }
47