Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 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 | |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 18 | import android.annotation.NonNull; |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| 20 | import android.annotation.TestApi; |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 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 { |
Remi NGUYEN VAN | e501d2a | 2019-03-12 09:21:55 +0900 | [diff] [blame] | 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 | */ |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 40 | @SystemApi |
| 41 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 42 | public static final int APP_RETURN_DISMISSED = 0; |
Remi NGUYEN VAN | e501d2a | 2019-03-12 09:21:55 +0900 | [diff] [blame] | 43 | /** |
| 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 VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 50 | @SystemApi |
| 51 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 52 | public static final int APP_RETURN_UNWANTED = 1; |
Remi NGUYEN VAN | e501d2a | 2019-03-12 09:21:55 +0900 | [diff] [blame] | 53 | /** |
| 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 VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 60 | @SystemApi |
| 61 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 62 | public static final int APP_RETURN_WANTED_AS_IS = 2; |
Chiachang Wang | 207b6cf | 2020-01-09 13:50:55 +0800 | [diff] [blame] | 63 | /** Event offset of request codes from captive portal application. */ |
| 64 | private static final int APP_REQUEST_BASE = 100; |
| 65 | /** |
| 66 | * Request code from the captive portal application, indicating that the network condition may |
| 67 | * have changed and the network should be re-validated. |
| 68 | * @see ICaptivePortal#appRequest(int) |
| 69 | * @see android.net.INetworkMonitor#forceReevaluation(int) |
| 70 | * @hide |
| 71 | */ |
| 72 | @SystemApi |
| 73 | @TestApi |
| 74 | public static final int APP_REQUEST_REEVALUATION_REQUIRED = APP_REQUEST_BASE + 0; |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 75 | |
| 76 | private final IBinder mBinder; |
| 77 | |
| 78 | /** @hide */ |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 79 | public CaptivePortal(@NonNull IBinder binder) { |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 80 | mBinder = binder; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public int describeContents() { |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void writeToParcel(Parcel out, int flags) { |
| 90 | out.writeStrongBinder(mBinder); |
| 91 | } |
| 92 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 93 | public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 94 | = new Parcelable.Creator<CaptivePortal>() { |
| 95 | @Override |
| 96 | public CaptivePortal createFromParcel(Parcel in) { |
| 97 | return new CaptivePortal(in.readStrongBinder()); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public CaptivePortal[] newArray(int size) { |
| 102 | return new CaptivePortal[size]; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * Indicate to the system that the captive portal has been |
| 108 | * dismissed. In response the framework will re-evaluate the network's |
| 109 | * connectivity and might take further action thereafter. |
| 110 | */ |
| 111 | public void reportCaptivePortalDismissed() { |
| 112 | try { |
| 113 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED); |
| 114 | } catch (RemoteException e) { |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Indicate to the system that the user does not want to pursue signing in to the |
| 120 | * captive portal and the system should continue to prefer other networks |
| 121 | * without captive portals for use as the default active data network. The |
| 122 | * system will not retest the network for a captive portal so as to avoid |
| 123 | * disturbing the user with further sign in to network notifications. |
| 124 | */ |
| 125 | public void ignoreNetwork() { |
| 126 | try { |
| 127 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED); |
| 128 | } catch (RemoteException e) { |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Indicate to the system the user wants to use this network as is, even though |
| 134 | * the captive portal is still in place. The system will treat the network |
| 135 | * as if it did not have a captive portal when selecting the network to use |
| 136 | * as the default active data network. This may result in this network |
| 137 | * becoming the default active data network, which could disrupt network |
| 138 | * connectivity for apps because the captive portal is still in place. |
| 139 | * @hide |
| 140 | */ |
Remi NGUYEN VAN | 111e1c3 | 2019-01-21 23:36:53 +0900 | [diff] [blame] | 141 | @SystemApi |
| 142 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 143 | public void useNetwork() { |
| 144 | try { |
| 145 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS); |
| 146 | } catch (RemoteException e) { |
| 147 | } |
| 148 | } |
Remi NGUYEN VAN | d4a9de20 | 2019-01-30 22:01:20 +0900 | [diff] [blame] | 149 | |
| 150 | /** |
Chiachang Wang | 207b6cf | 2020-01-09 13:50:55 +0800 | [diff] [blame] | 151 | * Request that the system reevaluates the captive portal status. |
| 152 | * @hide |
| 153 | */ |
| 154 | @SystemApi |
| 155 | @TestApi |
| 156 | public void reevaluateNetwork() { |
| 157 | try { |
| 158 | ICaptivePortal.Stub.asInterface(mBinder).appRequest(APP_REQUEST_REEVALUATION_REQUIRED); |
| 159 | } catch (RemoteException e) { |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /** |
Remi NGUYEN VAN | d4a9de20 | 2019-01-30 22:01:20 +0900 | [diff] [blame] | 164 | * Log a captive portal login event. |
Remi NGUYEN VAN | 59a06a0 | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 165 | * @param eventId one of the CAPTIVE_PORTAL_LOGIN_* constants in metrics_constants.proto. |
| 166 | * @param packageName captive portal application package name. |
Remi NGUYEN VAN | d4a9de20 | 2019-01-30 22:01:20 +0900 | [diff] [blame] | 167 | * @hide |
| 168 | */ |
| 169 | @SystemApi |
| 170 | @TestApi |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 171 | public void logEvent(int eventId, @NonNull String packageName) { |
Remi NGUYEN VAN | d4a9de20 | 2019-01-30 22:01:20 +0900 | [diff] [blame] | 172 | try { |
| 173 | ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName); |
| 174 | } catch (RemoteException e) { |
| 175 | } |
| 176 | } |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 177 | } |