• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package android.net;
17 
18 import android.annotation.NonNull;
19 import android.annotation.RequiresPermission;
20 import android.annotation.SystemApi;
21 import android.os.IBinder;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import 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  */
32 public class CaptivePortal implements Parcelable {
33     /**
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      */
40     @SystemApi
41     public static final int APP_RETURN_DISMISSED    = 0;
42     /**
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      */
49     @SystemApi
50     public static final int APP_RETURN_UNWANTED     = 1;
51     /**
52      * Response code from the captive portal application, indicating that the user does not wish to
53      * login but wants to use the captive portal network as-is.
54      * @see ICaptivePortal#appResponse(int)
55      * @see android.net.INetworkMonitor#notifyCaptivePortalAppFinished(int)
56      * @hide
57      */
58     @SystemApi
59     public static final int APP_RETURN_WANTED_AS_IS = 2;
60     /** Event offset of request codes from captive portal application. */
61     private static final int APP_REQUEST_BASE = 100;
62     /**
63      * Request code from the captive portal application, indicating that the network condition may
64      * have changed and the network should be re-validated.
65      * @see ICaptivePortal#appRequest(int)
66      * @see android.net.INetworkMonitor#forceReevaluation(int)
67      * @hide
68      */
69     @SystemApi
70     public static final int APP_REQUEST_REEVALUATION_REQUIRED = APP_REQUEST_BASE + 0;
71 
72     private final IBinder mBinder;
73 
74     /** @hide */
CaptivePortal(@onNull IBinder binder)75     public CaptivePortal(@NonNull IBinder binder) {
76         mBinder = binder;
77     }
78 
79     @Override
describeContents()80     public int describeContents() {
81         return 0;
82     }
83 
84     @Override
writeToParcel(Parcel out, int flags)85     public void writeToParcel(Parcel out, int flags) {
86         out.writeStrongBinder(mBinder);
87     }
88 
89     public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR
90             = new Parcelable.Creator<CaptivePortal>() {
91         @Override
92         public CaptivePortal createFromParcel(Parcel in) {
93             return new CaptivePortal(in.readStrongBinder());
94         }
95 
96         @Override
97         public CaptivePortal[] newArray(int size) {
98             return new CaptivePortal[size];
99         }
100     };
101 
102     /**
103      * Indicate to the system that the captive portal has been
104      * dismissed.  In response the framework will re-evaluate the network's
105      * connectivity and might take further action thereafter.
106      */
reportCaptivePortalDismissed()107     public void reportCaptivePortalDismissed() {
108         try {
109             ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
110         } catch (RemoteException e) {
111         }
112     }
113 
114     /**
115      * Indicate to the system that the user does not want to pursue signing in to the
116      * captive portal and the system should continue to prefer other networks
117      * without captive portals for use as the default active data network.  The
118      * system will not retest the network for a captive portal so as to avoid
119      * disturbing the user with further sign in to network notifications.
120      */
ignoreNetwork()121     public void ignoreNetwork() {
122         try {
123             ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
124         } catch (RemoteException e) {
125         }
126     }
127 
128     /**
129      * Indicate to the system the user wants to use this network as is, even though
130      * the captive portal is still in place.  The system will treat the network
131      * as if it did not have a captive portal when selecting the network to use
132      * as the default active data network. This may result in this network
133      * becoming the default active data network, which could disrupt network
134      * connectivity for apps because the captive portal is still in place.
135      * @hide
136      */
137     @SystemApi
useNetwork()138     public void useNetwork() {
139         try {
140             ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
141         } catch (RemoteException e) {
142         }
143     }
144 
145     /**
146      * Request that the system reevaluates the captive portal status.
147      * @hide
148      */
149     @SystemApi
150     @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
reevaluateNetwork()151     public void reevaluateNetwork() {
152         try {
153             ICaptivePortal.Stub.asInterface(mBinder).appRequest(APP_REQUEST_REEVALUATION_REQUIRED);
154         } catch (RemoteException e) {
155         }
156     }
157 
158     /**
159      * Log a captive portal login event.
160      * @param eventId one of the CAPTIVE_PORTAL_LOGIN_* constants in metrics_constants.proto.
161      * @param packageName captive portal application package name.
162      * @hide
163      * @deprecated The event will not be logged in Android S and above. The
164      * caller is migrating to statsd.
165      */
166     @Deprecated
167     @SystemApi
logEvent(int eventId, @NonNull String packageName)168     public void logEvent(int eventId, @NonNull String packageName) {
169     }
170 }
171