Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 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; |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 19 | /** User visible label in Settings for the recommendation service. */ |
| 20 | private final String mRecommendationServiceLabel; |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 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; |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 26 | /** |
| 27 | * The {@link android.app.NotificationChannel} ID used by {@link #mRecommendationService} to |
| 28 | * post open network notifications. |
| 29 | */ |
| 30 | private final String mNetworkAvailableNotificationChannelId; |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 31 | |
| 32 | public NetworkScorerAppData(int packageUid, ComponentName recommendationServiceComp, |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 33 | String recommendationServiceLabel, ComponentName enableUseOpenWifiActivity, |
| 34 | String networkAvailableNotificationChannelId) { |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 35 | this.packageUid = packageUid; |
| 36 | this.mRecommendationService = recommendationServiceComp; |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 37 | this.mRecommendationServiceLabel = recommendationServiceLabel; |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 38 | this.mEnableUseOpenWifiActivity = enableUseOpenWifiActivity; |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 39 | this.mNetworkAvailableNotificationChannelId = networkAvailableNotificationChannelId; |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | protected NetworkScorerAppData(Parcel in) { |
| 43 | packageUid = in.readInt(); |
| 44 | mRecommendationService = ComponentName.readFromParcel(in); |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 45 | mRecommendationServiceLabel = in.readString(); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 46 | mEnableUseOpenWifiActivity = ComponentName.readFromParcel(in); |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 47 | mNetworkAvailableNotificationChannelId = in.readString(); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void writeToParcel(Parcel dest, int flags) { |
| 52 | dest.writeInt(packageUid); |
| 53 | ComponentName.writeToParcel(mRecommendationService, dest); |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 54 | dest.writeString(mRecommendationServiceLabel); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 55 | ComponentName.writeToParcel(mEnableUseOpenWifiActivity, dest); |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 56 | dest.writeString(mNetworkAvailableNotificationChannelId); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public int describeContents() { |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | public static final 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 | |
| 77 | public String getRecommendationServicePackageName() { |
| 78 | return mRecommendationService.getPackageName(); |
| 79 | } |
| 80 | |
| 81 | public ComponentName getRecommendationServiceComponent() { |
| 82 | return mRecommendationService; |
| 83 | } |
| 84 | |
| 85 | @Nullable |
| 86 | public ComponentName getEnableUseOpenWifiActivity() { |
| 87 | return mEnableUseOpenWifiActivity; |
| 88 | } |
| 89 | |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 90 | @Nullable |
| 91 | public String getRecommendationServiceLabel() { |
| 92 | return mRecommendationServiceLabel; |
| 93 | } |
| 94 | |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 95 | @Nullable |
| 96 | public String getNetworkAvailableNotificationChannelId() { |
| 97 | return mNetworkAvailableNotificationChannelId; |
| 98 | } |
| 99 | |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 100 | @Override |
| 101 | public String toString() { |
| 102 | return "NetworkScorerAppData{" + |
| 103 | "packageUid=" + packageUid + |
| 104 | ", mRecommendationService=" + mRecommendationService + |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 105 | ", mRecommendationServiceLabel=" + mRecommendationServiceLabel + |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 106 | ", mEnableUseOpenWifiActivity=" + mEnableUseOpenWifiActivity + |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 107 | ", mNetworkAvailableNotificationChannelId=" + |
| 108 | mNetworkAvailableNotificationChannelId + |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 109 | '}'; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean equals(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) && |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 119 | Objects.equals(mRecommendationServiceLabel, that.mRecommendationServiceLabel) && |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 120 | Objects.equals(mEnableUseOpenWifiActivity, that.mEnableUseOpenWifiActivity) && |
| 121 | Objects.equals(mNetworkAvailableNotificationChannelId, |
| 122 | that.mNetworkAvailableNotificationChannelId); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public int hashCode() { |
Stephen Chen | 8b1339a | 2017-02-28 18:11:34 -0800 | [diff] [blame] | 127 | return Objects.hash(packageUid, mRecommendationService, mRecommendationServiceLabel, |
Amin Shaikh | d601360 | 2017-03-24 15:52:32 -0700 | [diff] [blame] | 128 | mEnableUseOpenWifiActivity, mNetworkAvailableNotificationChannelId); |
Jeremy Joslin | f621bc9 | 2017-02-16 11:11:57 -0800 | [diff] [blame] | 129 | } |
| 130 | } |