2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 import android.os.IBinder;
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 import android.os.RemoteException;
24 * A class allowing apps handling the {@link ConnectivityManager#ACTION_CAPTIVE_PORTAL_SIGN_IN}
25 * activity to indicate to the system different outcomes of captive portal sign in. This class is
26 * passed as an extra named {@link ConnectivityManager#EXTRA_CAPTIVE_PORTAL} with the
27 * {@code ACTION_CAPTIVE_PORTAL_SIGN_IN} activity.
29 public class CaptivePortal implements Parcelable {
31 public static final int APP_RETURN_DISMISSED = 0;
33 public static final int APP_RETURN_UNWANTED = 1;
35 public static final int APP_RETURN_WANTED_AS_IS = 2;
37 private final IBinder mBinder;
40 public CaptivePortal(IBinder binder) {
45 public int describeContents() {
50 public void writeToParcel(Parcel out, int flags) {
51 out.writeStrongBinder(mBinder);
54 public static final Parcelable.Creator<CaptivePortal> CREATOR
55 = new Parcelable.Creator<CaptivePortal>() {
57 public CaptivePortal createFromParcel(Parcel in) {
58 return new CaptivePortal(in.readStrongBinder());
62 public CaptivePortal[] newArray(int size) {
63 return new CaptivePortal[size];
68 * Indicate to the system that the captive portal has been
69 * dismissed. In response the framework will re-evaluate the network's
70 * connectivity and might take further action thereafter.
72 public void reportCaptivePortalDismissed() {
74 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
75 } catch (RemoteException e) {
80 * Indicate to the system that the user does not want to pursue signing in to the
81 * captive portal and the system should continue to prefer other networks
82 * without captive portals for use as the default active data network. The
83 * system will not retest the network for a captive portal so as to avoid
84 * disturbing the user with further sign in to network notifications.
86 public void ignoreNetwork() {
88 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
89 } catch (RemoteException e) {
94 * Indicate to the system the user wants to use this network as is, even though
95 * the captive portal is still in place. The system will treat the network
96 * as if it did not have a captive portal when selecting the network to use
97 * as the default active data network. This may result in this network
98 * becoming the default active data network, which could disrupt network
99 * connectivity for apps because the captive portal is still in place.
102 public void useNetwork() {
104 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
105 } catch (RemoteException e) {