1 package android.net; 2 3 import android.annotation.Nullable; 4 import android.content.ComponentName; 5 import android.os.Parcel; 6 import android.os.Parcelable; 7 8 import java.util.Objects; 9 10 /** 11 * Holds metadata about a discovered network scorer/recommendation application. 12 * 13 * @hide 14 */ 15 public final class NetworkScorerAppData implements Parcelable { 16 /** UID of the scorer app. */ 17 public final int packageUid; 18 private final ComponentName mRecommendationService; 19 /** User visible label in Settings for the recommendation service. */ 20 private final String mRecommendationServiceLabel; 21 /** 22 * The {@link ComponentName} of the Activity to start before enabling the "connect to open 23 * wifi networks automatically" feature. 24 */ 25 private final ComponentName mEnableUseOpenWifiActivity; 26 /** 27 * The {@link android.app.NotificationChannel} ID used by {@link #mRecommendationService} to 28 * post open network notifications. 29 */ 30 private final String mNetworkAvailableNotificationChannelId; 31 NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp, String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity, String networkAvailableNotificationChannelId)32 public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp, 33 String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity, 34 String networkAvailableNotificationChannelId) { 35 this.packageUid = packageUid; 36 this.mRecommendationService = recommendationServiceComp; 37 this.mRecommendationServiceLabel = recommendationServiceLabel; 38 this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity; 39 this.mNetworkAvailableNotificationChannelId = networkAvailableNotificationChannelId; 40 } 41 NetworkScorerAppData(Parcel in)42 protected NetworkScorerAppData(Parcel in) { 43 packageUid = in.readInt(); 44 mRecommendationService = ComponentName.readFromParcel(in); 45 mRecommendationServiceLabel = in.readString(); 46 mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in); 47 mNetworkAvailableNotificationChannelId = in.readString(); 48 } 49 50 @Override writeToParcel(Parcel dest, int flags)51 public void writeToParcel(Parcel dest, int flags) { 52 dest.writeInt(packageUid); 53 ComponentName.writeToParcel(mRecommendationService, dest); 54 dest.writeString(mRecommendationServiceLabel); 55 ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest); 56 dest.writeString(mNetworkAvailableNotificationChannelId); 57 } 58 59 @Override describeContents()60 public int describeContents() { 61 return 0; 62 } 63 64 public static final @android.annotation.NonNull Creator<NetworkScorerAppData> CREATOR = 65 new Creator<NetworkScorerAppData>() { 66 @Override 67 public NetworkScorerAppData createFromParcel(Parcel in) { 68 return new NetworkScorerAppData(in); 69 } 70 71 @Override 72 public NetworkScorerAppData[] newArray(int size) { 73 return new NetworkScorerAppData[size]; 74 } 75 }; 76 getRecommendationServicePackageName()77 public String getRecommendationServicePackageName() { 78 return mRecommendationService.getPackageName(); 79 } 80 getRecommendationServiceComponent()81 public ComponentName getRecommendationServiceComponent() { 82 return mRecommendationService; 83 } 84 85 @Nullable getEnableUseOpenWifiActivity()86 public ComponentName getEnableUseOpenWifiActivity() { 87 return mEnableUseOpenWifiActivity; 88 } 89 90 @Nullable getRecommendationServiceLabel()91 public String getRecommendationServiceLabel() { 92 return mRecommendationServiceLabel; 93 } 94 95 @Nullable getNetworkAvailableNotificationChannelId()96 public String getNetworkAvailableNotificationChannelId() { 97 return mNetworkAvailableNotificationChannelId; 98 } 99 100 @Override toString()101 public String toString() { 102 return "NetworkScorerAppData{" + 103 "packageUid=" + packageUid + 104 ", mRecommendationService=" + mRecommendationService + 105 ", mRecommendationServiceLabel=" + mRecommendationServiceLabel + 106 ", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity + 107 ", mNetworkAvailableNotificationChannelId=" + 108 mNetworkAvailableNotificationChannelId + 109 '}'; 110 } 111 112 @Override equals(@ullable Object o)113 public boolean equals(@Nullable Object o) { 114 if (this == o) return true; 115 if (o == null || getClass() != o.getClass()) return false; 116 NetworkScorerAppData that = (NetworkScorerAppData) o; 117 return packageUid == that.packageUid && 118 Objects.equals(mRecommendationService, that.mRecommendationService) && 119 Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) && 120 Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity) && 121 Objects.equals(mNetworkAvailableNotificationChannelId, 122 that.mNetworkAvailableNotificationChannelId); 123 } 124 125 @Override hashCode()126 public int hashCode() { 127 return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel, 128 mEnableUseOpenWifiActivity, mNetworkAvailableNotificationChannelId); 129 } 130 } 131