| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.location; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
@SystemApi |
| 29 |
public class MemoryRegion implements Parcelable{ |
| 30 |
|
| 31 |
private int mSizeBytes; |
| 32 |
private int mSizeBytesFree; |
| 33 |
private boolean mIsReadable; |
| 34 |
private boolean mIsWritable; |
| 35 |
private boolean mIsExecutable; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public int getCapacityBytes() { |
| 43 |
return mSizeBytes; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public int getFreeCapacityBytes() { |
| 52 |
return mSizeBytesFree; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public boolean isReadable() { |
| 61 |
return mIsReadable; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public boolean isWritable() { |
| 70 |
return mIsWritable; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public boolean isExecutable() { |
| 80 |
return mIsExecutable; |
| 81 |
} |
| 82 |
|
| 83 |
@NonNull |
| 84 |
@Override |
| 85 |
public String toString() { |
| 86 |
String mask = ""; |
| 87 |
|
| 88 |
if (isReadable()) { |
| 89 |
mask += "r"; |
| 90 |
} else { |
| 91 |
mask += "-"; |
| 92 |
} |
| 93 |
|
| 94 |
if (isWritable()) { |
| 95 |
mask += "w"; |
| 96 |
} else { |
| 97 |
mask += "-"; |
| 98 |
} |
| 99 |
|
| 100 |
if (isExecutable()) { |
| 101 |
mask += "x"; |
| 102 |
} else { |
| 103 |
mask += "-"; |
| 104 |
} |
| 105 |
|
| 106 |
String retVal = "[ " + mSizeBytesFree + "/ " + mSizeBytes + " ] : " + mask; |
| 107 |
|
| 108 |
return retVal; |
| 109 |
} |
| 110 |
|
| 111 |
@Override |
| 112 |
public boolean equals(@Nullable Object object) { |
| 113 |
if (object == this) { |
| 114 |
return true; |
| 115 |
} |
| 116 |
|
| 117 |
boolean isEqual = false; |
| 118 |
if (object instanceof MemoryRegion) { |
| 119 |
MemoryRegion other = (MemoryRegion) object; |
| 120 |
isEqual = (other.getCapacityBytes() == mSizeBytes) |
| 121 |
&& (other.getFreeCapacityBytes() == mSizeBytesFree) |
| 122 |
&& (other.isReadable() == mIsReadable) |
| 123 |
&& (other.isWritable() == mIsWritable) |
| 124 |
&& (other.isExecutable() == mIsExecutable); |
| 125 |
} |
| 126 |
|
| 127 |
return isEqual; |
| 128 |
} |
| 129 |
|
| 130 |
@Override |
| 131 |
public int describeContents() { |
| 132 |
return 0; |
| 133 |
} |
| 134 |
|
| 135 |
@Override |
| 136 |
public void writeToParcel(Parcel dest, int flags) { |
| 137 |
dest.writeInt(mSizeBytes); |
| 138 |
dest.writeInt(mSizeBytesFree); |
| 139 |
dest.writeInt(mIsReadable ? 1 : 0); |
| 140 |
dest.writeInt(mIsWritable ? 1 : 0); |
| 141 |
dest.writeInt(mIsExecutable ? 1 : 0); |
| 142 |
} |
| 143 |
|
| 144 |
public MemoryRegion(Parcel source) { |
| 145 |
mSizeBytes = source.readInt(); |
| 146 |
mSizeBytesFree = source.readInt(); |
| 147 |
mIsReadable = source.readInt() != 0; |
| 148 |
mIsWritable = source.readInt() != 0; |
| 149 |
mIsExecutable = source.readInt() != 0; |
| 150 |
} |
| 151 |
|
| 152 |
public static final @android.annotation.NonNull Parcelable.Creator<MemoryRegion> CREATOR |
| 153 |
= new Parcelable.Creator<MemoryRegion>() { |
| 154 |
public MemoryRegion createFromParcel(Parcel in) { |
| 155 |
return new MemoryRegion(in); |
| 156 |
} |
| 157 |
|
| 158 |
public MemoryRegion[] newArray(int size) { |
| 159 |
return new MemoryRegion[size]; |
| 160 |
} |
| 161 |
}; |
| 162 |
|
| 163 |
} |