blob: ebd8a7e3528ac910386a6365ff1ef48dc6893394 [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
paulhu79b380c2019-03-15 17:17:02 +080018import android.annotation.NonNull;
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090019import android.annotation.SystemApi;
20import android.annotation.TestApi;
Paul Jensen49e3edf2015-05-22 10:50:39 -040021import android.os.IBinder;
22import android.os.Parcel;
23import android.os.Parcelable;
24import android.os.RemoteException;
25
26/**
27 * A class allowing apps handling the {@link ConnectivityManager#ACTION_CAPTIVE_PORTAL_SIGN_IN}
28 * activity to indicate to the system different outcomes of captive portal sign in. This class is
29 * passed as an extra named {@link ConnectivityManager#EXTRA_CAPTIVE_PORTAL} with the
30 * {@code ACTION_CAPTIVE_PORTAL_SIGN_IN} activity.
31 */
32public class CaptivePortal implements Parcelable {
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090033 /**
34 * Response code from the captive portal application, indicating that the portal was dismissed
35 * and the network should be re-validated.
36 * @see ICaptivePortal#appResponse(int)
37 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
38 * @hide
39 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090040 @SystemApi
41 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040042 public static final int APP_RETURN_DISMISSED = 0;
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090043 /**
44 * Response code from the captive portal application, indicating that the user did not login and
45 * does not want to use the captive portal network.
46 * @see ICaptivePortal#appResponse(int)
47 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
48 * @hide
49 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090050 @SystemApi
51 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040052 public static final int APP_RETURN_UNWANTED = 1;
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090053 /**
54 * Response code from the captive portal application, indicating that the user does not wish to
55 * login but wants to use the captive portal network as-is.
56 * @see ICaptivePortal#appResponse(int)
57 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
58 * @hide
59 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090060 @SystemApi
61 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040062 public static final int APP_RETURN_WANTED_AS_IS = 2;
63
64 private final IBinder mBinder;
65
66 /** @hide */
Remi NGUYEN VAN1e6b186022019-01-20 14:00:34 +090067 @SystemApi
68 @TestApi
paulhu79b380c2019-03-15 17:17:02 +080069 public CaptivePortal(@NonNull IBinder binder) {
Paul Jensen49e3edf2015-05-22 10:50:39 -040070 mBinder = binder;
71 }
72
73 @Override
74 public int describeContents() {
75 return 0;
76 }
77
78 @Override
79 public void writeToParcel(Parcel out, int flags) {
80 out.writeStrongBinder(mBinder);
81 }
82
83 public static final Parcelable.Creator<CaptivePortal> CREATOR
84 = new Parcelable.Creator<CaptivePortal>() {
85 @Override
86 public CaptivePortal createFromParcel(Parcel in) {
87 return new CaptivePortal(in.readStrongBinder());
88 }
89
90 @Override
91 public CaptivePortal[] newArray(int size) {
92 return new CaptivePortal[size];
93 }
94 };
95
96 /**
97 * Indicate to the system that the captive portal has been
98 * dismissed. In response the framework will re-evaluate the network's
99 * connectivity and might take further action thereafter.
100 */
101 public void reportCaptivePortalDismissed() {
102 try {
103 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
104 } catch (RemoteException e) {
105 }
106 }
107
108 /**
109 * Indicate to the system that the user does not want to pursue signing in to the
110 * captive portal and the system should continue to prefer other networks
111 * without captive portals for use as the default active data network. The
112 * system will not retest the network for a captive portal so as to avoid
113 * disturbing the user with further sign in to network notifications.
114 */
115 public void ignoreNetwork() {
116 try {
117 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
118 } catch (RemoteException e) {
119 }
120 }
121
122 /**
123 * Indicate to the system the user wants to use this network as is, even though
124 * the captive portal is still in place. The system will treat the network
125 * as if it did not have a captive portal when selecting the network to use
126 * as the default active data network. This may result in this network
127 * becoming the default active data network, which could disrupt network
128 * connectivity for apps because the captive portal is still in place.
129 * @hide
130 */
Remi NGUYEN VAN1e6b186022019-01-20 14:00:34 +0900131 @SystemApi
132 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -0400133 public void useNetwork() {
134 try {
135 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
136 } catch (RemoteException e) {
137 }
138 }
Remi NGUYEN VANde602212019-01-30 15:22:01 +0900139
140 /**
141 * Log a captive portal login event.
142 * @hide
143 */
144 @SystemApi
145 @TestApi
paulhu79b380c2019-03-15 17:17:02 +0800146 public void logEvent(int eventId, @NonNull String packageName) {
Remi NGUYEN VANde602212019-01-30 15:22:01 +0900147 try {
148 ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName);
149 } catch (RemoteException e) {
150 }
151 }
Paul Jensen49e3edf2015-05-22 10:50:39 -0400152}