summaryrefslogtreecommitdiff
path: root/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
blob: cb500c23c65c5168a8fdb0f7494f00201e8d065e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/*
 * 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 com.android.wifitrackerlib;

import static android.net.wifi.WifiInfo.DEFAULT_MAC_ADDRESS;
import static android.net.wifi.WifiInfo.SECURITY_TYPE_PASSPOINT_R1_R2;
import static android.net.wifi.WifiInfo.SECURITY_TYPE_PASSPOINT_R3;
import static android.net.wifi.WifiInfo.SECURITY_TYPE_UNKNOWN;
import static android.net.wifi.WifiInfo.sanitizeSsid;

import static androidx.core.util.Preconditions.checkNotNull;

import static com.android.wifitrackerlib.Utils.getAutoConnectDescription;
import static com.android.wifitrackerlib.Utils.getBestScanResultByLevel;
import static com.android.wifitrackerlib.Utils.getConnectedDescription;
import static com.android.wifitrackerlib.Utils.getConnectingDescription;
import static com.android.wifitrackerlib.Utils.getDisconnectedDescription;
import static com.android.wifitrackerlib.Utils.getMeteredDescription;
import static com.android.wifitrackerlib.Utils.getVerboseLoggingDescription;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.os.Handler;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.StringJoiner;

/**
 * WifiEntry representation of a subscribed Passpoint network, uniquely identified by FQDN.
 */
public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntryCallback {
    static final String TAG = "PasspointWifiEntry";
    public static final String KEY_PREFIX = "PasspointWifiEntry:";

    private final List<ScanResult> mCurrentHomeScanResults = new ArrayList<>();
    private final List<ScanResult> mCurrentRoamingScanResults = new ArrayList<>();

    @NonNull private final String mKey;
    @NonNull private final String mFqdn;
    @NonNull private final String mFriendlyName;
    @Nullable
    private PasspointConfiguration mPasspointConfig;
    @Nullable private WifiConfiguration mWifiConfig;
    private List<Integer> mTargetSecurityTypes =
            Arrays.asList(SECURITY_TYPE_PASSPOINT_R1_R2, SECURITY_TYPE_PASSPOINT_R3);

    private OsuWifiEntry mOsuWifiEntry;
    private boolean mShouldAutoOpenCaptivePortal = false;

    protected long mSubscriptionExpirationTimeInMillis;

    // PasspointConfiguration#setMeteredOverride(int meteredOverride) is a hide API and we can't
    // set it in PasspointWifiEntry#setMeteredChoice(int meteredChoice).
    // For PasspointWifiEntry#getMeteredChoice() to return correct value right after
    // PasspointWifiEntry#setMeteredChoice(int meteredChoice), cache
    // PasspointConfiguration#getMeteredOverride() in this variable.
    private int mMeteredOverride = METERED_CHOICE_AUTO;

    /**
     * Create a PasspointWifiEntry with the associated PasspointConfiguration
     */
    PasspointWifiEntry(
            @NonNull WifiTrackerInjector injector,
            @NonNull Handler callbackHandler,
            @NonNull PasspointConfiguration passpointConfig,
            @NonNull WifiManager wifiManager,
            boolean forSavedNetworksPage) throws IllegalArgumentException {
        super(injector, callbackHandler, wifiManager, forSavedNetworksPage);

        checkNotNull(passpointConfig, "Cannot construct with null PasspointConfiguration!");
        mPasspointConfig = passpointConfig;
        mKey = uniqueIdToPasspointWifiEntryKey(passpointConfig.getUniqueId());
        mFqdn = passpointConfig.getHomeSp().getFqdn();
        checkNotNull(mFqdn, "Cannot construct with null PasspointConfiguration FQDN!");
        mFriendlyName = passpointConfig.getHomeSp().getFriendlyName();
        mSubscriptionExpirationTimeInMillis =
                passpointConfig.getSubscriptionExpirationTimeMillis();
        mMeteredOverride = mPasspointConfig.getMeteredOverride();
    }

    /**
     * Create a PasspointWifiEntry with the associated WifiConfiguration for use with network
     * suggestions, since WifiManager#getAllMatchingWifiConfigs() does not provide a corresponding
     * PasspointConfiguration.
     */
    PasspointWifiEntry(
            @NonNull WifiTrackerInjector injector,
            @NonNull Context context, @NonNull Handler callbackHandler,
            @NonNull WifiConfiguration wifiConfig,
            @NonNull WifiManager wifiManager,
            boolean forSavedNetworksPage) throws IllegalArgumentException {
        super(injector, callbackHandler, wifiManager, forSavedNetworksPage);

        checkNotNull(wifiConfig, "Cannot construct with null WifiConfiguration!");
        if (!wifiConfig.isPasspoint()) {
            throw new IllegalArgumentException("Given WifiConfiguration is not for Passpoint!");
        }
        mWifiConfig = wifiConfig;
        mKey = uniqueIdToPasspointWifiEntryKey(wifiConfig.getKey());
        mFqdn = wifiConfig.FQDN;
        checkNotNull(mFqdn, "Cannot construct with null WifiConfiguration FQDN!");
        mFriendlyName = mWifiConfig.providerFriendlyName;
    }

    @Override
    public String getKey() {
        return mKey;
    }

    @Override
    @ConnectedState
    public synchronized int getConnectedState() {
        if (isExpired()) {
            if (super.getConnectedState() == CONNECTED_STATE_DISCONNECTED
                    && mOsuWifiEntry != null) {
                return mOsuWifiEntry.getConnectedState();
            }
        }
        return super.getConnectedState();
    }

    @Override
    public String getTitle() {
        return mFriendlyName;
    }

    @Override
    public synchronized String getSummary(boolean concise) {
        StringJoiner sj = new StringJoiner(mContext.getString(
                R.string.wifitrackerlib_summary_separator));

        if (isExpired()) {
            if (mOsuWifiEntry != null) {
                sj.add(mOsuWifiEntry.getSummary(concise));
            } else {
                sj.add(mContext.getString(R.string.wifitrackerlib_wifi_passpoint_expired));
            }
        } else {
            final String connectedStateDescription;
            final @ConnectedState int connectedState = getConnectedState();
            switch (connectedState) {
                case CONNECTED_STATE_DISCONNECTED:
                    connectedStateDescription = getDisconnectedDescription(mInjector, mContext,
                            mWifiConfig,
                            mForSavedNetworksPage,
                            concise);
                    break;
                case CONNECTED_STATE_CONNECTING:
                    connectedStateDescription = getConnectingDescription(mContext, mNetworkInfo);
                    break;
                case CONNECTED_STATE_CONNECTED:
                    connectedStateDescription = getConnectedDescription(mContext,
                            mWifiConfig,
                            mNetworkCapabilities,
                            mIsDefaultNetwork,
                            isLowQuality(),
                            mConnectivityReport);
                    break;
                default:
                    Log.e(TAG, "getConnectedState() returned unknown state: " + connectedState);
                    connectedStateDescription = null;
            }
            if (!TextUtils.isEmpty(connectedStateDescription)) {
                sj.add(connectedStateDescription);
            }
        }

        String autoConnectDescription = getAutoConnectDescription(mContext, this);
        if (!TextUtils.isEmpty(autoConnectDescription)) {
            sj.add(autoConnectDescription);
        }

        String meteredDescription = getMeteredDescription(mContext, this);
        if (!TextUtils.isEmpty(meteredDescription)) {
            sj.add(meteredDescription);
        }

        if (!concise) {
            String verboseLoggingDescription = getVerboseLoggingDescription(this);
            if (!TextUtils.isEmpty(verboseLoggingDescription)) {
                sj.add(verboseLoggingDescription);
            }
        }

        return sj.toString();
    }

    @Override
    public synchronized String getSsid() {
        if (mWifiInfo != null) {
            return sanitizeSsid(mWifiInfo.getSSID());
        }

        return mWifiConfig != null ? sanitizeSsid(mWifiConfig.SSID) : null;
    }

    synchronized Set<String> getAllUtf8Ssids() {
        Set<String> allSsids = new ArraySet<>();
        for (ScanResult scan : mCurrentHomeScanResults) {
            allSsids.add(scan.SSID);
        }
        for (ScanResult scan : mCurrentRoamingScanResults) {
            allSsids.add(scan.SSID);
        }
        return allSsids;
    }

    @Override
    public synchronized List<Integer> getSecurityTypes() {
        return new ArrayList<>(mTargetSecurityTypes);
    }

    @Override
    public synchronized String getMacAddress() {
        if (mWifiInfo != null) {
            final String wifiInfoMac = mWifiInfo.getMacAddress();
            if (!TextUtils.isEmpty(wifiInfoMac)
                    && !TextUtils.equals(wifiInfoMac, DEFAULT_MAC_ADDRESS)) {
                return wifiInfoMac;
            }
        }
        if (mWifiConfig == null || getPrivacy() != PRIVACY_RANDOMIZED_MAC) {
            final String[] factoryMacs = mWifiManager.getFactoryMacAddresses();
            if (factoryMacs.length > 0) {
                return factoryMacs[0];
            }
            return null;
        }
        return mWifiConfig.getRandomizedMacAddress().toString();
    }

    @Override
    public synchronized boolean isMetered() {
        return getMeteredChoice() == METERED_CHOICE_METERED
                || (mWifiConfig != null && mWifiConfig.meteredHint);
    }

    @Override
    public synchronized boolean isSuggestion() {
        return mWifiConfig != null && mWifiConfig.fromWifiNetworkSuggestion;
    }

    @Override
    public synchronized boolean isSubscription() {
        return mPasspointConfig != null;
    }

    @Override
    public synchronized boolean canConnect() {
        if (isExpired()) {
            return mOsuWifiEntry != null && mOsuWifiEntry.canConnect();
        }

        return mLevel != WIFI_LEVEL_UNREACHABLE
                && getConnectedState() == CONNECTED_STATE_DISCONNECTED && mWifiConfig != null;
    }

    @Override
    public synchronized void connect(@Nullable ConnectCallback callback) {
        if (isExpired()) {
            if (mOsuWifiEntry != null) {
                mOsuWifiEntry.connect(callback);
                return;
            }
        }
        // We should flag this network to auto-open captive portal since this method represents
        // the user manually connecting to a network (i.e. not auto-join).
        mShouldAutoOpenCaptivePortal = true;
        mConnectCallback = callback;

        if (mWifiConfig == null) {
            // We should not be able to call connect() if mWifiConfig is null
            new ConnectActionListener().onFailure(0);
        }
        mWifiManager.stopRestrictingAutoJoinToSubscriptionId();
        mWifiManager.connect(mWifiConfig, new ConnectActionListener());
    }

    @Override
    public boolean canDisconnect() {
        return getConnectedState() == CONNECTED_STATE_CONNECTED;
    }

    @Override
    public synchronized void disconnect(@Nullable DisconnectCallback callback) {
        if (canDisconnect()) {
            mCalledDisconnect = true;
            mDisconnectCallback = callback;
            mCallbackHandler.postDelayed(() -> {
                if (callback != null && mCalledDisconnect) {
                    callback.onDisconnectResult(
                            DisconnectCallback.DISCONNECT_STATUS_FAILURE_UNKNOWN);
                }
            }, 10_000 /* delayMillis */);
            mWifiManager.disableEphemeralNetwork(mFqdn);
            mWifiManager.disconnect();
        }
    }

    @Override
    public synchronized boolean canForget() {
        return !isSuggestion() && mPasspointConfig != null;
    }

    @Override
    public synchronized void forget(@Nullable ForgetCallback callback) {
        if (!canForget()) {
            return;
        }

        mForgetCallback = callback;
        mWifiManager.removePasspointConfiguration(mPasspointConfig.getHomeSp().getFqdn());
        new ForgetActionListener().onSuccess();
    }

    @Override
    @MeteredChoice
    public synchronized int getMeteredChoice() {
        if (mMeteredOverride == WifiConfiguration.METERED_OVERRIDE_METERED) {
            return METERED_CHOICE_METERED;
        } else if (mMeteredOverride == WifiConfiguration.METERED_OVERRIDE_NOT_METERED) {
            return METERED_CHOICE_UNMETERED;
        }
        return METERED_CHOICE_AUTO;
    }

    @Override
    public synchronized boolean canSetMeteredChoice() {
        return !isSuggestion() && mPasspointConfig != null;
    }

    @Override
    public synchronized void setMeteredChoice(int meteredChoice) {
        if (mPasspointConfig == null || !canSetMeteredChoice()) {
            return;
        }

        switch (meteredChoice) {
            case METERED_CHOICE_AUTO:
                mMeteredOverride = WifiConfiguration.METERED_OVERRIDE_NONE;
                break;
            case METERED_CHOICE_METERED:
                mMeteredOverride = WifiConfiguration.METERED_OVERRIDE_METERED;
                break;
            case METERED_CHOICE_UNMETERED:
                mMeteredOverride = WifiConfiguration.METERED_OVERRIDE_NOT_METERED;
                break;
            default:
                // Do nothing.
                return;
        }
        mWifiManager.setPasspointMeteredOverride(mPasspointConfig.getHomeSp().getFqdn(),
                mMeteredOverride);
    }

    @Override
    public synchronized boolean canSetPrivacy() {
        return !isSuggestion() && mPasspointConfig != null;
    }

    @Override
    @Privacy
    public synchronized int getPrivacy() {
        if (mPasspointConfig == null) {
            return PRIVACY_RANDOMIZED_MAC;
        }

        return mPasspointConfig.isMacRandomizationEnabled()
                ? PRIVACY_RANDOMIZED_MAC : PRIVACY_DEVICE_MAC;
    }

    @Override
    public synchronized void setPrivacy(int privacy) {
        if (mPasspointConfig == null || !canSetPrivacy()) {
            return;
        }

        mWifiManager.setMacRandomizationSettingPasspointEnabled(
                mPasspointConfig.getHomeSp().getFqdn(),
                privacy == PRIVACY_DEVICE_MAC ? false : true);
    }

    @Override
    public synchronized boolean isAutoJoinEnabled() {
        // Suggestion network; use WifiConfig instead
        if (mPasspointConfig != null) {
            return mPasspointConfig.isAutojoinEnabled();
        }
        if (mWifiConfig != null) {
            return mWifiConfig.allowAutojoin;
        }
        return false;
    }

    @Override
    public synchronized boolean canSetAutoJoinEnabled() {
        return mPasspointConfig != null || mWifiConfig != null;
    }

    @Override
    public synchronized void setAutoJoinEnabled(boolean enabled) {
        if (mPasspointConfig != null) {
            mWifiManager.allowAutojoinPasspoint(mPasspointConfig.getHomeSp().getFqdn(), enabled);
        } else if (mWifiConfig != null) {
            mWifiManager.allowAutojoin(mWifiConfig.networkId, enabled);
        }
    }

    @Override
    public String getSecurityString(boolean concise) {
        return mContext.getString(R.string.wifitrackerlib_wifi_security_passpoint);
    }

    @Override
    public synchronized String getStandardString() {
        if (mWifiInfo != null) {
            return Utils.getStandardString(mContext, mWifiInfo.getWifiStandard());
        }
        if (!mCurrentHomeScanResults.isEmpty()) {
            return Utils.getStandardString(
                    mContext, mCurrentHomeScanResults.get(0).getWifiStandard());
        }
        if (!mCurrentRoamingScanResults.isEmpty()) {
            return Utils.getStandardString(
                    mContext, mCurrentRoamingScanResults.get(0).getWifiStandard());
        }
        return "";
    }

    @Override
    public synchronized String getBandString() {
        if (mWifiInfo != null) {
            return Utils.wifiInfoToBandString(mContext, mWifiInfo);
        }
        if (!mCurrentHomeScanResults.isEmpty()) {
            return Utils.frequencyToBandString(mContext, mCurrentHomeScanResults.get(0).frequency);
        }
        if (!mCurrentRoamingScanResults.isEmpty()) {
            return Utils.frequencyToBandString(
                    mContext, mCurrentRoamingScanResults.get(0).frequency);
        }
        return "";
    }

    @Override
    public synchronized boolean isExpired() {
        if (mSubscriptionExpirationTimeInMillis <= 0) {
            // Expiration time not specified.
            return false;
        } else {
            return System.currentTimeMillis() >= mSubscriptionExpirationTimeInMillis;
        }
    }

    @WorkerThread
    synchronized void updatePasspointConfig(@Nullable PasspointConfiguration passpointConfig) {
        mPasspointConfig = passpointConfig;
        if (mPasspointConfig != null) {
            mSubscriptionExpirationTimeInMillis =
                    passpointConfig.getSubscriptionExpirationTimeMillis();
            mMeteredOverride = passpointConfig.getMeteredOverride();
        }
        notifyOnUpdated();
    }

    @WorkerThread
    synchronized void updateScanResultInfo(@Nullable WifiConfiguration wifiConfig,
            @Nullable List<ScanResult> homeScanResults,
            @Nullable List<ScanResult> roamingScanResults)
            throws IllegalArgumentException {
        mWifiConfig = wifiConfig;
        mCurrentHomeScanResults.clear();
        mCurrentRoamingScanResults.clear();
        if (homeScanResults != null) {
            mCurrentHomeScanResults.addAll(homeScanResults);
        }
        if (roamingScanResults != null) {
            mCurrentRoamingScanResults.addAll(roamingScanResults);
        }
        if (mWifiConfig != null) {
            List<ScanResult> currentScanResults = new ArrayList<>();
            if (homeScanResults != null && !homeScanResults.isEmpty()) {
                currentScanResults.addAll(homeScanResults);
            } else if (roamingScanResults != null && !roamingScanResults.isEmpty()) {
                currentScanResults.addAll(roamingScanResults);
            }
            ScanResult bestScanResult = getBestScanResultByLevel(currentScanResults);
            if (bestScanResult != null) {
                mWifiConfig.SSID = "\"" + bestScanResult.SSID + "\"";
            }
            if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) {
                mLevel = bestScanResult != null
                        ? mWifiManager.calculateSignalLevel(bestScanResult.level)
                        : WIFI_LEVEL_UNREACHABLE;
            }
        } else {
            mLevel = WIFI_LEVEL_UNREACHABLE;
        }
        notifyOnUpdated();
    }

    @Override
    protected synchronized void updateSecurityTypes() {
        if (mWifiInfo != null) {
            final int wifiInfoSecurity = mWifiInfo.getCurrentSecurityType();
            if (wifiInfoSecurity != SECURITY_TYPE_UNKNOWN) {
                mTargetSecurityTypes = Collections.singletonList(wifiInfoSecurity);
                return;
            }
        }
    }

    @WorkerThread
    @Override
    protected boolean connectionInfoMatches(@NonNull WifiInfo wifiInfo) {
        if (!wifiInfo.isPasspointAp()) {
            return false;
        }

        // Match with FQDN until WifiInfo supports returning the passpoint uniqueID
        return TextUtils.equals(wifiInfo.getPasspointFqdn(), mFqdn);
    }

    @WorkerThread
    @Override
    synchronized void onNetworkCapabilitiesChanged(
            @NonNull Network network, @NonNull NetworkCapabilities capabilities) {
        super.onNetworkCapabilitiesChanged(network, capabilities);

        // Auto-open an available captive portal if the user manually connected to this network.
        if (canSignIn() && mShouldAutoOpenCaptivePortal) {
            mShouldAutoOpenCaptivePortal = false;
            signIn(null /* callback */);
        }
    }

    @NonNull
    static String uniqueIdToPasspointWifiEntryKey(@NonNull String uniqueId) {
        checkNotNull(uniqueId, "Cannot create key with null unique id!");
        return KEY_PREFIX + uniqueId;
    }

    @Override
    protected String getScanResultDescription() {
        // TODO(b/70983952): Fill this method in.
        return "";
    }

    @Override
    synchronized String getNetworkSelectionDescription() {
        return Utils.getNetworkSelectionDescription(mWifiConfig);
    }

    /** Pass a reference to a matching OsuWifiEntry for expiration handling */
    synchronized void setOsuWifiEntry(OsuWifiEntry osuWifiEntry) {
        mOsuWifiEntry = osuWifiEntry;
        if (mOsuWifiEntry != null) {
            mOsuWifiEntry.setListener(this);
        }
    }

    /** Callback for updates to the linked OsuWifiEntry */
    @Override
    public void onUpdated() {
        notifyOnUpdated();
    }

    @Override
    public synchronized boolean canSignIn() {
        return mNetwork != null
                && mNetworkCapabilities != null
                && mNetworkCapabilities.hasCapability(
                NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
    }

    @Override
    public void signIn(@Nullable SignInCallback callback) {
        if (canSignIn()) {
            NonSdkApiWrapper.startCaptivePortalApp(
                    mContext.getSystemService(ConnectivityManager.class), mNetwork);
        }
    }

    /** Get the PasspointConfiguration instance of the entry. */
    public PasspointConfiguration getPasspointConfig() {
        return mPasspointConfig;
    }

    @Override
    public String toString() {
        StringJoiner sj = new StringJoiner("][", "[", "]");
        sj.add("FQDN:" + mFqdn);
        sj.add("FriendlyName:" + mFriendlyName);
        if (mPasspointConfig != null) {
            sj.add("UniqueId:" + mPasspointConfig.getUniqueId());
        } else if (mWifiConfig != null) {
            sj.add("UniqueId:" + mWifiConfig.getKey());
        }
        return super.toString() + sj;
    }
}