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 | |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 18 | import android.annotation.SystemApi; |
| 19 | import android.annotation.TestApi; |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 20 | import android.os.IBinder; |
| 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import 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 | */ |
| 31 | public class CaptivePortal implements Parcelable { |
| 32 | /** @hide */ |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 33 | @SystemApi |
| 34 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 35 | public static final int APP_RETURN_DISMISSED = 0; |
| 36 | /** @hide */ |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 37 | @SystemApi |
| 38 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 39 | public static final int APP_RETURN_UNWANTED = 1; |
| 40 | /** @hide */ |
Remi NGUYEN VAN | d0a9334 | 2019-01-21 21:07:10 +0900 | [diff] [blame] | 41 | @SystemApi |
| 42 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 43 | public static final int APP_RETURN_WANTED_AS_IS = 2; |
| 44 | |
| 45 | private final IBinder mBinder; |
| 46 | |
| 47 | /** @hide */ |
Remi NGUYEN VAN | 111e1c3 | 2019-01-21 23:36:53 +0900 | [diff] [blame^] | 48 | @SystemApi |
| 49 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 50 | 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 | |
| 64 | public static final Parcelable.Creator<CaptivePortal> CREATOR |
| 65 | = 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 VAN | 111e1c3 | 2019-01-21 23:36:53 +0900 | [diff] [blame^] | 112 | @SystemApi |
| 113 | @TestApi |
Paul Jensen | 49e3edf | 2015-05-22 10:50:39 -0400 | [diff] [blame] | 114 | public void useNetwork() { |
| 115 | try { |
| 116 | ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS); |
| 117 | } catch (RemoteException e) { |
| 118 | } |
| 119 | } |
| 120 | } |