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 18 import android.os.IBinder; 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 import android.os.RemoteException; 22 23 /** 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. 28 */ 29 public class CaptivePortal implements Parcelable { 30 /** @hide */ 31 public static final int APP_RETURN_DISMISSED = 0; 32 /** @hide */ 33 public static final int APP_RETURN_UNWANTED = 1; 34 /** @hide */ 35 public static final int APP_RETURN_WANTED_AS_IS = 2; 36 37 private final IBinder mBinder; 38 39 /** @hide */ 40 public CaptivePortal(IBinder binder) { 41 mBinder = binder; 42 } 43 44 @Override 45 public int describeContents() { 46 return 0; 47 } 48 49 @Override 50 public void writeToParcel(Parcel out, int flags) { 51 out.writeStrongBinder(mBinder); 52 } 53 54 public static final Parcelable.Creator<CaptivePortal> CREATOR 55 = new Parcelable.Creator<CaptivePortal>() { 56 @Override 57 public CaptivePortal createFromParcel(Parcel in) { 58 return new CaptivePortal(in.readStrongBinder()); 59 } 60 61 @Override 62 public CaptivePortal[] newArray(int size) { 63 return new CaptivePortal[size]; 64 } 65 }; 66 67 /** 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. 71 */ 72 public void reportCaptivePortalDismissed() { 73 try { 74 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_DISMISSED); 75 } catch (RemoteException e) { 76 } 77 } 78 79 /** 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. 85 */ 86 public void ignoreNetwork() { 87 try { 88 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_UNWANTED); 89 } catch (RemoteException e) { 90 } 91 } 92 93 /** 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. 100 * @hide 101 */ 102 public void useNetwork() { 103 try { 104 ICaptivePortal.Stub.asInterface(mBinder).appResponse(APP_RETURN_WANTED_AS_IS); 105 } catch (RemoteException e) { 106 } 107 } 108 } 109