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 com.android.settings.wifi;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.content.DialogInterface;
22 import android.content.Intent;
23 import android.net.wifi.ScanResult;
24 import android.net.wifi.WifiManager.NetworkRequestUserSelectionCallback;
25 
26 import androidx.annotation.NonNull;
27 import androidx.annotation.VisibleForTesting;
28 
29 import com.android.settings.R;
30 import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
31 
32 import java.util.List;
33 
34 /**
35  * This is base fragment of {@link NetworkRequestDialogFragment} and
36  * {@link NetworkRequestSingleSsidDialogFragment} to handle activity callback methods.
37  */
38 abstract public class NetworkRequestDialogBaseFragment extends InstrumentedDialogFragment {
39 
40     @VisibleForTesting
41     final static String EXTRA_APP_NAME = "com.android.settings.wifi.extra.APP_NAME";
42 
43     NetworkRequestDialogActivity mActivity = null;
44     private String mAppName = "";
45 
46     @Override
getMetricsCategory()47     public int getMetricsCategory() {
48         return SettingsEnums.WIFI_SCANNING_NEEDED_DIALOG;
49     }
50 
51     @Override
onAttach(Context context)52     public void onAttach(Context context) {
53         super.onAttach(context);
54         if (context instanceof NetworkRequestDialogActivity) {
55             mActivity = (NetworkRequestDialogActivity) context;
56         }
57 
58         final Intent intent = getActivity().getIntent();
59         if (intent != null) {
60             mAppName = intent.getStringExtra(EXTRA_APP_NAME);
61         }
62     }
63 
64     @Override
onDetach()65     public void onDetach() {
66         super.onDetach();
67         mActivity = null;
68     }
69 
70     @Override
onCancel(@onNull DialogInterface dialog)71     public void onCancel(@NonNull DialogInterface dialog) {
72         super.onCancel(dialog);
73 
74         if (mActivity != null) {
75             mActivity.onCancel();
76         }
77     }
78 
getTitle()79     protected String getTitle() {
80         return getString(R.string.network_connection_request_dialog_title);
81     }
82 
getSummary()83     protected String getSummary() {
84         return getString(R.string.network_connection_request_dialog_summary, mAppName);
85     }
86 
onUserSelectionCallbackRegistration( NetworkRequestUserSelectionCallback userSelectionCallback)87     protected void onUserSelectionCallbackRegistration(
88             NetworkRequestUserSelectionCallback userSelectionCallback) {
89     }
90 
onMatch(List<ScanResult> scanResults)91     protected void onMatch(List<ScanResult> scanResults) {
92     }
93 }
94