Expose read/write property permissions in car-lib
Added getReadPermission() and getWritePermission() for a given propId
Bug: 116101770
Test: Embedded Kitchen Sink
Change-Id: I8964f81bcfc229b03d250b7c0faf476539bcb09d
(cherry picked from commit f6b01f1c1d9f860c19fd095e9d07be52ebe4cdcb)
diff --git a/car-lib/src/android/car/hardware/property/CarPropertyManager.java b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
index 373c23a..62d6c38 100644
--- a/car-lib/src/android/car/hardware/property/CarPropertyManager.java
+++ b/car-lib/src/android/car/hardware/property/CarPropertyManager.java
@@ -246,6 +246,44 @@
}
/**
+ *
+ * @param propId Property ID to query
+ *
+ * @return String Permission needed to read this property. NULL if propId not available.
+ */
+ public String getReadPermission(int propId) throws CarNotConnectedException {
+ if (mDbg) {
+ Log.d(mTag, "getReadPermission, propId: 0x" + toHexString(propId));
+ }
+ try {
+ String permission = mService.getReadPermission(propId);
+ return permission;
+ } catch (RemoteException e) {
+ Log.e(mTag, "getReadPermission failed with " + e.toString(), e);
+ throw new CarNotConnectedException(e);
+ }
+ }
+
+ /**
+ *
+ * @param propId Property ID to query
+ *
+ * @return String Permission needed to write this property. NULL if propId not available.
+ */
+ public String getWritePermission(int propId) throws CarNotConnectedException {
+ if (mDbg) {
+ Log.d(mTag, "getWritePermission, propId: 0x" + toHexString(propId));
+ }
+ try {
+ String permission = mService.getWritePermission(propId);
+ return permission;
+ } catch (RemoteException e) {
+ Log.e(mTag, "getWritePermission failed with " + e.toString(), e);
+ throw new CarNotConnectedException(e);
+ }
+ }
+
+ /**
* Check whether a given property is available or disabled based on the car's current state.
* @return true if STATUS_AVAILABLE, false otherwise (eg STATUS_UNAVAILABLE)
* @throws CarNotConnectedException
diff --git a/car-lib/src/android/car/hardware/property/ICarProperty.aidl b/car-lib/src/android/car/hardware/property/ICarProperty.aidl
index 3e7e5c9..ab5ad7e 100644
--- a/car-lib/src/android/car/hardware/property/ICarProperty.aidl
+++ b/car-lib/src/android/car/hardware/property/ICarProperty.aidl
@@ -34,4 +34,8 @@
CarPropertyValue getProperty(int prop, int zone) = 3;
void setProperty(in CarPropertyValue prop) = 4;
+
+ String getReadPermission(int propId) = 5;
+
+ String getWritePermission(int propId) = 6;
}
diff --git a/service/src/com/android/car/CarPropertyService.java b/service/src/com/android/car/CarPropertyService.java
index a01d4b8..35fd295 100644
--- a/service/src/com/android/car/CarPropertyService.java
+++ b/service/src/com/android/car/CarPropertyService.java
@@ -317,6 +317,26 @@
}
@Override
+ public String getReadPermission(int propId) {
+ if (mConfigs.get(propId) == null) {
+ // Property ID does not exist
+ Log.e(TAG, "getReadPermission: propId is not in config list:0x" + toHexString(propId));
+ return null;
+ }
+ return mHal.getReadPermission(propId);
+ }
+
+ @Override
+ public String getWritePermission(int propId) {
+ if (mConfigs.get(propId) == null) {
+ // Property ID does not exist
+ Log.e(TAG, "getWritePermission: propId is not in config list:0x" + toHexString(propId));
+ return null;
+ }
+ return mHal.getWritePermission(propId);
+ }
+
+ @Override
public void setProperty(CarPropertyValue prop) {
int propId = prop.getPropertyId();
if (mConfigs.get(propId) == null) {
diff --git a/tests/EmbeddedKitchenSinkApp/res/layout/property.xml b/tests/EmbeddedKitchenSinkApp/res/layout/property.xml
index f8f6f79..3841e07 100644
--- a/tests/EmbeddedKitchenSinkApp/res/layout/property.xml
+++ b/tests/EmbeddedKitchenSinkApp/res/layout/property.xml
@@ -51,7 +51,7 @@
android:id="@+id/tvGetPropertyValue"
android:gravity="center"
android:layout_height="wrap_content"
- android:layout_weight="2"
+ android:layout_weight="3"
android:layout_width="0dp"
android:textSize="@dimen/propertyValueTextSize"/>
</LinearLayout>
diff --git a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/property/PropertyTestFragment.java b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/property/PropertyTestFragment.java
index d4b5a02..13da4bb 100644
--- a/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/property/PropertyTestFragment.java
+++ b/tests/EmbeddedKitchenSinkApp/src/com/google/android/car/kitchensink/property/PropertyTestFragment.java
@@ -120,7 +120,9 @@
} else {
mGetValue.setText("Timestamp=" + value.getTimestamp()
+ "\nstatus=" + value.getStatus()
- + "\nvalue=" + value.getValue());
+ + "\nvalue=" + value.getValue()
+ + "\nread=" + mMgr.getReadPermission(propId)
+ + "\nwrite=" + mMgr.getWritePermission(propId));
}
} catch (Exception e) {
Log.e(TAG, "Failed to get property", e);