1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.hardware.location; 18 19 import android.annotation.SystemApi; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * @hide 25 */ 26 @SystemApi 27 public class MemoryRegion implements Parcelable{ 28 29 private int mSizeBytes; 30 private int mSizeBytesFree; 31 private boolean mIsReadable; 32 private boolean mIsWritable; 33 private boolean mIsExecutable; 34 35 /** 36 * get the capacity of the memory region in bytes 37 * 38 * @return int - the memory capacity in bytes 39 */ getCapacityBytes()40 public int getCapacityBytes() { 41 return mSizeBytes; 42 } 43 44 /** 45 * get the free capacity of the memory region in bytes 46 * 47 * @return int - free bytes 48 */ getFreeCapacityBytes()49 public int getFreeCapacityBytes() { 50 return mSizeBytesFree; 51 } 52 53 /** 54 * Is the memory readable 55 * 56 * @return boolean - true if memory is readable, false otherwise 57 */ isReadable()58 public boolean isReadable() { 59 return mIsReadable; 60 } 61 62 /** 63 * Is the memory writable 64 * 65 * @return boolean - true if memory is writable, false otherwise 66 */ isWritable()67 public boolean isWritable() { 68 return mIsWritable; 69 } 70 71 /** 72 * Is the memory executable 73 * 74 * @return boolean - true if memory is executable, false 75 * otherwise 76 */ isExecutable()77 public boolean isExecutable() { 78 return mIsExecutable; 79 } 80 81 @Override toString()82 public String toString() { 83 String mask = ""; 84 85 if (isReadable()) { 86 mask += "r"; 87 } else { 88 mask += "-"; 89 } 90 91 if (isWritable()) { 92 mask += "w"; 93 } else { 94 mask += "-"; 95 } 96 97 if (isExecutable()) { 98 mask += "x"; 99 } else { 100 mask += "-"; 101 } 102 103 String retVal = "[ " + mSizeBytesFree + "/ " + mSizeBytes + " ] : " + mask; 104 105 return retVal; 106 } 107 108 @Override describeContents()109 public int describeContents() { 110 return 0; 111 } 112 113 @Override writeToParcel(Parcel dest, int flags)114 public void writeToParcel(Parcel dest, int flags) { 115 dest.writeInt(mSizeBytes); 116 dest.writeInt(mSizeBytesFree); 117 dest.writeInt(mIsReadable ? 1 : 0); 118 dest.writeInt(mIsWritable ? 1 : 0); 119 dest.writeInt(mIsExecutable ? 1 : 0); 120 } 121 MemoryRegion(Parcel source)122 public MemoryRegion(Parcel source) { 123 mSizeBytes = source.readInt(); 124 mSizeBytesFree = source.readInt(); 125 mIsReadable = source.readInt() != 0; 126 mIsWritable = source.readInt() != 0; 127 mIsExecutable = source.readInt() != 0; 128 } 129 130 public static final Parcelable.Creator<MemoryRegion> CREATOR 131 = new Parcelable.Creator<MemoryRegion>() { 132 public MemoryRegion createFromParcel(Parcel in) { 133 return new MemoryRegion(in); 134 } 135 136 public MemoryRegion[] newArray(int size) { 137 return new MemoryRegion[size]; 138 } 139 }; 140 141 } 142