blob: f2087248205c745e4d4dd1fc7f1fff8011de8b39 [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 */
Remi NGUYEN VAN111e1c32019-01-21 23:36:53 +090048 @SystemApi
49 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -040050 public CaptivePortal(IBinder binder) {
51 mBinder = binder;
52 }
53
54 @Override
55 public int describeContents() {
56 return 0;
57 }
58
59 @Override
60 public void writeToParcel(Parcel out, int flags) {
61 out.writeStrongBinder(mBinder);
62 }
63
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -070064 public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR
Paul Jensen49e3edf2015-05-22 10:50:39 -040065 = new Parcelable.Creator<CaptivePortal>() {
66 @Override
67 public CaptivePortal createFromParcel(Parcel in) {
68 return new CaptivePortal(in.readStrongBinder());
69 }
70
71 @Override
72 public CaptivePortal[] newArray(int size) {
73 return new CaptivePortal[size];
74 }
75 };
76
77 /**
78 * Indicate to the system that the captive portal has been
79 * dismissed. In response the framework will re-evaluate the network's
80 * connectivity and might take further action thereafter.
81 */
82 public void reportCaptivePortalDismissed() {
83 try {
84 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED);
85 } catch (RemoteException e) {
86 }
87 }
88
89 /**
90 * Indicate to the system that the user does not want to pursue signing in to the
91 * captive portal and the system should continue to prefer other networks
92 * without captive portals for use as the default active data network. The
93 * system will not retest the network for a captive portal so as to avoid
94 * disturbing the user with further sign in to network notifications.
95 */
96 public void ignoreNetwork() {
97 try {
98 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED);
99 } catch (RemoteException e) {
100 }
101 }
102
103 /**
104 * Indicate to the system the user wants to use this network as is, even though
105 * the captive portal is still in place. The system will treat the network
106 * as if it did not have a captive portal when selecting the network to use
107 * as the default active data network. This may result in this network
108 * becoming the default active data network, which could disrupt network
109 * connectivity for apps because the captive portal is still in place.
110 * @hide
111 */
Remi NGUYEN VAN111e1c32019-01-21 23:36:53 +0900112 @SystemApi
113 @TestApi
Paul Jensen49e3edf2015-05-22 10:50:39 -0400114 public void useNetwork() {
115 try {
116 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS);
117 } catch (RemoteException e) {
118 }
119 }
Remi NGUYEN VANd4a9de202019-01-30 22:01:20 +0900120
121 /**
122 * Log a captive portal login event.
123 * @hide
124 */
125 @SystemApi
126 @TestApi
127 public void logEvent(int eventId, String packageName) {
128 try {
129 ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName);
130 } catch (RemoteException e) {
131 }
132 }
Paul Jensen49e3edf2015-05-22 10:50:39 -0400133}