1 package com.android.hotspot2.pps; 2 3 import android.util.Base64; 4 5 import com.android.hotspot2.Utils; 6 import com.android.hotspot2.omadm.MOManager; 7 import com.android.hotspot2.omadm.OMAException; 8 import com.android.hotspot2.omadm.OMANode; 9 10 import java.nio.charset.StandardCharsets; 11 12 import static com.android.hotspot2.omadm.MOManager.TAG_CertSHA256Fingerprint; 13 import static com.android.hotspot2.omadm.MOManager.TAG_CertURL; 14 import static com.android.hotspot2.omadm.MOManager.TAG_Password; 15 import static com.android.hotspot2.omadm.MOManager.TAG_Restriction; 16 import static com.android.hotspot2.omadm.MOManager.TAG_TrustRoot; 17 import static com.android.hotspot2.omadm.MOManager.TAG_URI; 18 import static com.android.hotspot2.omadm.MOManager.TAG_UpdateInterval; 19 import static com.android.hotspot2.omadm.MOManager.TAG_UpdateMethod; 20 import static com.android.hotspot2.omadm.MOManager.TAG_Username; 21 import static com.android.hotspot2.omadm.MOManager.TAG_UsernamePassword; 22 23 public class UpdateInfo { 24 public enum UpdateRestriction {HomeSP, RoamingPartner, Unrestricted} 25 26 private final long mInterval; 27 private final boolean mSPPClientInitiated; 28 private final UpdateRestriction mUpdateRestriction; 29 private final String mURI; 30 private final String mUsername; 31 private final String mPassword; 32 private final String mCertURL; 33 private final String mCertFP; 34 UpdateInfo(OMANode policyUpdate)35 public UpdateInfo(OMANode policyUpdate) throws OMAException { 36 mInterval = MOManager.getLong(policyUpdate, TAG_UpdateInterval, null) * 37 MOManager.IntervalFactor; 38 mSPPClientInitiated = MOManager.getSelection(policyUpdate, TAG_UpdateMethod); 39 mUpdateRestriction = MOManager.getSelection(policyUpdate, TAG_Restriction); 40 mURI = MOManager.getString(policyUpdate, TAG_URI); 41 42 OMANode unp = policyUpdate.getChild(TAG_UsernamePassword); 43 if (unp != null) { 44 mUsername = MOManager.getString(unp.getChild(TAG_Username)); 45 String pw = MOManager.getString(unp.getChild(TAG_Password)); 46 mPassword = new String(Base64.decode(pw.getBytes(StandardCharsets.US_ASCII), 47 Base64.DEFAULT), StandardCharsets.UTF_8); 48 } else { 49 mUsername = null; 50 mPassword = null; 51 } 52 53 OMANode trustRoot = MOManager.getChild(policyUpdate, TAG_TrustRoot); 54 mCertURL = MOManager.getString(trustRoot, TAG_CertURL); 55 mCertFP = MOManager.getString(trustRoot, TAG_CertSHA256Fingerprint); 56 } 57 getInterval()58 public long getInterval() { 59 return mInterval; 60 } 61 isSPPClientInitiated()62 public boolean isSPPClientInitiated() { 63 return mSPPClientInitiated; 64 } 65 getUpdateRestriction()66 public UpdateRestriction getUpdateRestriction() { 67 return mUpdateRestriction; 68 } 69 getURI()70 public String getURI() { 71 return mURI; 72 } 73 getUsername()74 public String getUsername() { 75 return mUsername; 76 } 77 getPassword()78 public String getPassword() { 79 return mPassword; 80 } 81 getCertURL()82 public String getCertURL() { 83 return mCertURL; 84 } 85 getCertFP()86 public String getCertFP() { 87 return mCertFP; 88 } 89 90 @Override toString()91 public String toString() { 92 return "UpdateInfo{" + 93 "interval=" + Utils.toHMS(mInterval) + 94 ", SPPClientInitiated=" + mSPPClientInitiated + 95 ", updateRestriction=" + mUpdateRestriction + 96 ", URI='" + mURI + '\'' + 97 ", username='" + mUsername + '\'' + 98 ", password=" + mPassword + 99 ", certURL='" + mCertURL + '\'' + 100 ", certFP='" + mCertFP + '\'' + 101 '}'; 102 } 103 } 104