| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.admin; |
| 18 |
|
| 19 |
import android.os.Parcel; |
| 20 |
import android.os.Parcelable; |
| 21 |
|
| 22 |
import java.net.InetAddress; |
| 23 |
import java.net.UnknownHostException; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public final class ConnectEvent extends NetworkEvent implements Parcelable { |
| 33 |
|
| 34 |
|
| 35 |
private final String mIpAddress; |
| 36 |
|
| 37 |
|
| 38 |
private final int mPort; |
| 39 |
|
| 40 |
|
| 41 |
public ConnectEvent(String ipAddress, int port, String packageName, long timestamp) { |
| 42 |
super(packageName, timestamp); |
| 43 |
this.mIpAddress = ipAddress; |
| 44 |
this.mPort = port; |
| 45 |
} |
| 46 |
|
| 47 |
private ConnectEvent(Parcel in) { |
| 48 |
this.mIpAddress = in.readString(); |
| 49 |
this.mPort = in.readInt(); |
| 50 |
this.mPackageName = in.readString(); |
| 51 |
this.mTimestamp = in.readLong(); |
| 52 |
this.mId = in.readLong(); |
| 53 |
} |
| 54 |
|
| 55 |
public InetAddress getInetAddress() { |
| 56 |
try { |
| 57 |
|
| 58 |
return InetAddress.getByName(mIpAddress); |
| 59 |
} catch (UnknownHostException e) { |
| 60 |
|
| 61 |
return InetAddress.getLoopbackAddress(); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
public int getPort() { |
| 66 |
return mPort; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public String toString() { |
| 71 |
return String.format("ConnectEvent(%d, %s, %d, %d, %s)", mId, mIpAddress, mPort, mTimestamp, |
| 72 |
mPackageName); |
| 73 |
} |
| 74 |
|
| 75 |
public static final @android.annotation.NonNull Parcelable.Creator<ConnectEvent> CREATOR |
| 76 |
= new Parcelable.Creator<ConnectEvent>() { |
| 77 |
@Override |
| 78 |
public ConnectEvent createFromParcel(Parcel in) { |
| 79 |
if (in.readInt() != PARCEL_TOKEN_CONNECT_EVENT) { |
| 80 |
return null; |
| 81 |
} |
| 82 |
return new ConnectEvent(in); |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public ConnectEvent[] newArray(int size) { |
| 87 |
return new ConnectEvent[size]; |
| 88 |
} |
| 89 |
}; |
| 90 |
|
| 91 |
@Override |
| 92 |
public int describeContents() { |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
public void writeToParcel(Parcel out, int flags) { |
| 98 |
|
| 99 |
out.writeInt(PARCEL_TOKEN_CONNECT_EVENT); |
| 100 |
out.writeString(mIpAddress); |
| 101 |
out.writeInt(mPort); |
| 102 |
out.writeString(mPackageName); |
| 103 |
out.writeLong(mTimestamp); |
| 104 |
out.writeLong(mId); |
| 105 |
} |
| 106 |
} |