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 | 7731c5b | 2019-01-17 14:38:31 +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 | 7731c5b | 2019-01-17 14:38:31 +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 | 7731c5b | 2019-01-17 14:38:31 +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 | 7731c5b | 2019-01-17 14:38:31 +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; |
| 63 | |
| 64 | private final IBinder mBinder; |
| 65 | |
| 66 | /** @hide */ |
Remi NGUYEN VAN | 1e6b18602 | 2019-01-20 14:00:34 +0900 | [diff] [blame] | 67 | @SystemApi |
| 68 | @TestApi |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame^] | 69 | public CaptivePortal(@NonNull IBinder binder) { |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 70 | mBinder = binder; |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int describeContents() { |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public void writeToParcel(Parcel out, int flags) { |
| 80 | out.writeStrongBinder(mBinder); |
| 81 | } |
| 82 | |
| 83 | public static final Parcelable.Creator<CaptivePortal> CREATOR |
| 84 | = new Parcelable.Creator<CaptivePortal>() { |
| 85 | @Override |
| 86 | public CaptivePortal createFromParcel(Parcel in) { |
| 87 | return new CaptivePortal(in.readStrongBinder()); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public CaptivePortal[] newArray(int size) { |
| 92 | return new CaptivePortal[size]; |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | /** |
| 97 | * Indicate to the system that the captive portal has been |
| 98 | * dismissed. In response the framework will re-evaluate the network's |
| 99 | * connectivity and might take further action thereafter. |
| 100 | */ |
| 101 | public void reportCaptivePortalDismissed() { |
| 102 | try { |
| 103 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED); |
| 104 | } catch (RemoteException e) { |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Indicate to the system that the user does not want to pursue signing in to the |
| 110 | * captive portal and the system should continue to prefer other networks |
| 111 | * without captive portals for use as the default active data network. The |
| 112 | * system will not retest the network for a captive portal so as to avoid |
| 113 | * disturbing the user with further sign in to network notifications. |
| 114 | */ |
| 115 | public void ignoreNetwork() { |
| 116 | try { |
| 117 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED); |
| 118 | } catch (RemoteException e) { |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Indicate to the system the user wants to use this network as is, even though |
| 124 | * the captive portal is still in place. The system will treat the network |
| 125 | * as if it did not have a captive portal when selecting the network to use |
| 126 | * as the default active data network. This may result in this network |
| 127 | * becoming the default active data network, which could disrupt network |
| 128 | * connectivity for apps because the captive portal is still in place. |
| 129 | * @hide |
| 130 | */ |
Remi NGUYEN VAN | 1e6b18602 | 2019-01-20 14:00:34 +0900 | [diff] [blame] | 131 | @SystemApi |
| 132 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 133 | public void useNetwork() { |
| 134 | try { |
| 135 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS); |
| 136 | } catch (RemoteException e) { |
| 137 | } |
| 138 | } |
Remi NGUYEN VAN | de60221 | 2019-01-30 15:22:01 +0900 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Log a captive portal login event. |
| 142 | * @hide |
| 143 | */ |
| 144 | @SystemApi |
| 145 | @TestApi |
paulhu | 79b380c | 2019-03-15 17:17:02 +0800 | [diff] [blame^] | 146 | public void logEvent(int eventId, @NonNull String packageName) { |
Remi NGUYEN VAN | de60221 | 2019-01-30 15:22:01 +0900 | [diff] [blame] | 147 | try { |
| 148 | ICaptivePortal.Stub.asInterface(mBinder).logEvent(eventId, packageName); |
| 149 | } catch (RemoteException e) { |
| 150 | } |
| 151 | } |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 152 | } |