blob: 4047068f1c7ba61ca86b51e5b757284846db7bd4 [file] [log] [blame]
Paul Jensen49e3edf2015-05-22 10:50:39 -04001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed urnder 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 */
16package android.net;
17
Remi NGUYEN VANd0a93342019-01-21 21:07:10 +090018import android.annotation.SystemApi;
19import android.annotation.TestApi;
Paul Jensen49e3edf2015-05-22 10:50:39 -040020import android.os.IBinder;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.os.RemoteException;
24
25/**
26 * A class allowing apps handling the {@link ConnectivityManager#ACTION_CAPTIVE_PORTAL_SIGN_IN}
27 * activity to indicate to the system different outcomes of captive portal sign in. This class is
28 * passed as an extra named {@link ConnectivityManager#EXTRA_CAPTIVE_PORTAL} with the
29 * {@code ACTION_CAPTIVE_PORTAL_SIGN_IN} activity.
30 */
31public class CaptivePortal implements Parcelable {
32 /** @hide */
Remi NGUYEN VANd0a93342019-01-21 21:07:10 +090033 @SystemApi
34 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040035 public static final int APP_RETURN_DISMISSED = 0;
36 /** @hide */
Remi NGUYEN VANd0a93342019-01-21 21:07:10 +090037 @SystemApi
38 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040039 public static final int APP_RETURN_UNWANTED = 1;
40 /** @hide */
Remi NGUYEN VANd0a93342019-01-21 21:07:10 +090041 @SystemApi
42 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040043 public static final int APP_RETURN_WANTED_AS_IS = 2;
44
45 private final IBinder mBinder;
46
47 /** @hide */
48 public CaptivePortal(IBinder binder) {
49 mBinder = binder;
50 }
51
52 @Override
53 public int describeContents() {
54 return 0;
55 }
56
57 @Override
58 public void writeToParcel(Parcel out, int flags) {
59 out.writeStrongBinder(mBinder);
60 }
61
62 public static final Parcelable.Creator<CaptivePortal> CREATOR
63 = new Parcelable.Creator<CaptivePortal>() {
64 @Override
65 public CaptivePortal createFromParcel(Parcel in) {
66 return new CaptivePortal(in.readStrongBinder());
67 }
68
69 @Override
70 public CaptivePortal[] newArray(int size) {
71 return new CaptivePortal[size];
72 }
73 };
74
75 /**
76 * Indicate to the system that the captive portal has been
77 * dismissed. In response the framework will re-evaluate the network's
78 * connectivity and might take further action thereafter.
79 */
80 public void reportCaptivePortalDismissed() {
81 try {
82 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
83 } catch (RemoteException e) {
84 }
85 }
86
87 /**
88 * Indicate to the system that the user does not want to pursue signing in to the
89 * captive portal and the system should continue to prefer other networks
90 * without captive portals for use as the default active data network. The
91 * system will not retest the network for a captive portal so as to avoid
92 * disturbing the user with further sign in to network notifications.
93 */
94 public void ignoreNetwork() {
95 try {
96 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
97 } catch (RemoteException e) {
98 }
99 }
100
101 /**
102 * Indicate to the system the user wants to use this network as is, even though
103 * the captive portal is still in place. The system will treat the network
104 * as if it did not have a captive portal when selecting the network to use
105 * as the default active data network. This may result in this network
106 * becoming the default active data network, which could disrupt network
107 * connectivity for apps because the captive portal is still in place.
108 * @hide
109 */
110 public void useNetwork() {
111 try {
112 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
113 } catch (RemoteException e) {
114 }
115 }
116}