blob: ba7323ddbd81294fb9f9a928422f470571bdb654 [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 VAN7731c5b2019-01-17 14:38:31 +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 {
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090032 /**
33 * Response code from the captive portal application, indicating that the portal was dismissed
34 * and the network should be re-validated.
35 * @see ICaptivePortal#appResponse(int)
36 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
37 * @hide
38 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090039 @SystemApi
40 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040041 public static final int APP_RETURN_DISMISSED = 0;
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090042 /**
43 * Response code from the captive portal application, indicating that the user did not login and
44 * does not want to use the captive portal network.
45 * @see ICaptivePortal#appResponse(int)
46 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
47 * @hide
48 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090049 @SystemApi
50 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040051 public static final int APP_RETURN_UNWANTED = 1;
Remi NGUYEN VANe501d2a2019-03-12 09:21:55 +090052 /**
53 * Response code from the captive portal application, indicating that the user does not wish to
54 * login but wants to use the captive portal network as-is.
55 * @see ICaptivePortal#appResponse(int)
56 * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
57 * @hide
58 */
Remi NGUYEN VAN7731c5b2019-01-17 14:38:31 +090059 @SystemApi
60 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040061 public static final int APP_RETURN_WANTED_AS_IS = 2;
62
63 private final IBinder mBinder;
64
65 /** @hide */
Remi NGUYEN VAN1e6b186022019-01-20 14:00:34 +090066 @SystemApi
67 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040068 public CaptivePortal(IBinder binder) {
69 mBinder = binder;
70 }
71
72 @Override
73 public int describeContents() {
74 return 0;
75 }
76
77 @Override
78 public void writeToParcel(Parcel out, int flags) {
79 out.writeStrongBinder(mBinder);
80 }
81
82 public static final Parcelable.Creator<CaptivePortal> CREATOR
83 = new Parcelable.Creator<CaptivePortal>() {
84 @Override
85 public CaptivePortal createFromParcel(Parcel in) {
86 return new CaptivePortal(in.readStrongBinder());
87 }
88
89 @Override
90 public CaptivePortal[] newArray(int size) {
91 return new CaptivePortal[size];
92 }
93 };
94
95 /**
96 * Indicate to the system that the captive portal has been
97 * dismissed. In response the framework will re-evaluate the network's
98 * connectivity and might take further action thereafter.
99 */
100 public void reportCaptivePortalDismissed() {
101 try {
102 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
103 } catch (RemoteException e) {
104 }
105 }
106
107 /**
108 * Indicate to the system that the user does not want to pursue signing in to the
109 * captive portal and the system should continue to prefer other networks
110 * without captive portals for use as the default active data network. The
111 * system will not retest the network for a captive portal so as to avoid
112 * disturbing the user with further sign in to network notifications.
113 */
114 public void ignoreNetwork() {
115 try {
116 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
117 } catch (RemoteException e) {
118 }
119 }
120
121 /**
122 * Indicate to the system the user wants to use this network as is, even though
123 * the captive portal is still in place. The system will treat the network
124 * as if it did not have a captive portal when selecting the network to use
125 * as the default active data network. This may result in this network
126 * becoming the default active data network, which could disrupt network
127 * connectivity for apps because the captive portal is still in place.
128 * @hide
129 */
Remi NGUYEN VAN1e6b186022019-01-20 14:00:34 +0900130 @SystemApi
131 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -0400132 public void useNetwork() {
133 try {
134 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
135 } catch (RemoteException e) {
136 }
137 }
Remi NGUYEN VANde602212019-01-30 15:22:01 +0900138
139 /**
140 * Log a captive portal login event.
141 * @hide
142 */
143 @SystemApi
144 @TestApi
145 public void logEvent(int eventId, String packageName) {
146 try {
147 ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName);
148 } catch (RemoteException e) {
149 }
150 }
Paul Jensen49e3edf2015-05-22 10:50:39 -0400151}