am e2383800: am 607d3271: Merge "Fix exceptions in ActivityRecognition platform stack." into lmp-dev
* commit 'e23838004e5db510c6e86919b2dcf16e67e3339b': Fix exceptions in ActivityRecognition platform stack.
This commit is contained in:
@@ -76,4 +76,17 @@ public class ActivityChangedEvent implements Parcelable {
|
||||
parcel.writeInt(activityRecognitionEventArray.length);
|
||||
parcel.writeTypedArray(activityRecognitionEventArray, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("[ ActivityChangedEvent:");
|
||||
|
||||
for (ActivityRecognitionEvent event : mActivityRecognitionEvents) {
|
||||
builder.append("\n ");
|
||||
builder.append(event.toString());
|
||||
}
|
||||
builder.append("\n]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,4 +75,13 @@ public class ActivityRecognitionEvent implements Parcelable {
|
||||
parcel.writeInt(mEventType);
|
||||
parcel.writeLong(mTimestampNs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"Activity='%s', EventType=%s, TimestampNs=%s",
|
||||
mActivity,
|
||||
mEventType,
|
||||
mTimestampNs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ public class ActivityRecognitionHardware extends IActivityRecognitionHardware.St
|
||||
* Called by the Activity-Recognition HAL.
|
||||
*/
|
||||
private void onActivityChanged(Event[] events) {
|
||||
int size = mSinks.beginBroadcast();
|
||||
if (size == 0 || events == null || events.length == 0) {
|
||||
if (events == null || events.length == 0) {
|
||||
Log.d(TAG, "No events to broadcast for onActivityChanged.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,6 +151,7 @@ public class ActivityRecognitionHardware extends IActivityRecognitionHardware.St
|
||||
ActivityChangedEvent activityChangedEvent =
|
||||
new ActivityChangedEvent(activityRecognitionEventArray);
|
||||
|
||||
int size = mSinks.beginBroadcast();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
IActivityRecognitionHardwareSink sink = mSinks.getBroadcastItem(i);
|
||||
try {
|
||||
@@ -181,8 +182,8 @@ public class ActivityRecognitionHardware extends IActivityRecognitionHardware.St
|
||||
return INVALID_ACTIVITY_TYPE;
|
||||
}
|
||||
|
||||
int supporteActivitiesLength = mSupportedActivities.length;
|
||||
for (int i = 0; i < supporteActivitiesLength; ++i) {
|
||||
int supportedActivitiesLength = mSupportedActivities.length;
|
||||
for (int i = 0; i < supportedActivitiesLength; ++i) {
|
||||
if (activity.equals(mSupportedActivities[i])) {
|
||||
return i;
|
||||
}
|
||||
@@ -198,7 +199,7 @@ public class ActivityRecognitionHardware extends IActivityRecognitionHardware.St
|
||||
mContext.enforceCallingPermission(HARDWARE_PERMISSION, message);
|
||||
}
|
||||
|
||||
private static String[] fetchSupportedActivities() {
|
||||
private String[] fetchSupportedActivities() {
|
||||
String[] supportedActivities = nativeGetSupportedActivities();
|
||||
if (supportedActivities != null) {
|
||||
return supportedActivities;
|
||||
@@ -211,14 +212,15 @@ public class ActivityRecognitionHardware extends IActivityRecognitionHardware.St
|
||||
static { nativeClassInit(); }
|
||||
|
||||
private static native void nativeClassInit();
|
||||
private static native void nativeInitialize();
|
||||
private static native void nativeRelease();
|
||||
private static native boolean nativeIsSupported();
|
||||
private static native String[] nativeGetSupportedActivities();
|
||||
private static native int nativeEnableActivityEvent(
|
||||
|
||||
private native void nativeInitialize();
|
||||
private native void nativeRelease();
|
||||
private native String[] nativeGetSupportedActivities();
|
||||
private native int nativeEnableActivityEvent(
|
||||
int activityType,
|
||||
int eventType,
|
||||
long reportLatenceNs);
|
||||
private static native int nativeDisableActivityEvent(int activityType, int eventType);
|
||||
private static native int nativeFlush();
|
||||
private native int nativeDisableActivityEvent(int activityType, int eventType);
|
||||
private native int nativeFlush();
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ static void activity_callback(
|
||||
JNIEnv* env = NULL;
|
||||
int result = attach_thread(&env);
|
||||
if (result != JNI_OK) {
|
||||
ALOGE("Unable to attach thread with JNI.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -215,7 +216,7 @@ static jobjectArray get_supported_activities(JNIEnv* env, jobject obj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jclass string_class = env->FindClass("java/lang/String;");
|
||||
jclass string_class = env->FindClass("java/lang/String");
|
||||
if (string_class == NULL) {
|
||||
ALOGE("Unable to find String class for supported activities.");
|
||||
return NULL;
|
||||
@@ -229,14 +230,8 @@ static jobjectArray get_supported_activities(JNIEnv* env, jobject obj) {
|
||||
|
||||
for (int i = 0; i < list_size; ++i) {
|
||||
const char* string_ptr = const_cast<const char*>(list[i]);
|
||||
jsize string_length = strlen(string_ptr);
|
||||
jstring string = env->NewString((const jchar*) string_ptr, string_length);
|
||||
jstring string = env->NewStringUTF(string_ptr);
|
||||
env->SetObjectArrayElement(string_array, i, string);
|
||||
|
||||
// log debugging information in case we need to try to trace issues with the strings
|
||||
if (string_length) {
|
||||
ALOGD("Invalid activity (index=%d) name size: %d", i, string_length);
|
||||
}
|
||||
}
|
||||
|
||||
return string_array;
|
||||
|
||||
@@ -40,4 +40,17 @@ public class ActivityChangedEvent {
|
||||
public Iterable<ActivityRecognitionEvent> getActivityRecognitionEvents() {
|
||||
return mActivityRecognitionEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("[ ActivityChangedEvent:");
|
||||
|
||||
for (ActivityRecognitionEvent event : mActivityRecognitionEvents) {
|
||||
builder.append("\n ");
|
||||
builder.append(event.toString());
|
||||
}
|
||||
builder.append("\n]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,4 +41,30 @@ public class ActivityRecognitionEvent {
|
||||
public long getTimestampNs() {
|
||||
return mTimestampNs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String eventString;
|
||||
switch (mEventType) {
|
||||
case ActivityRecognitionProvider.EVENT_TYPE_ENTER:
|
||||
eventString = "Enter";
|
||||
break;
|
||||
case ActivityRecognitionProvider.EVENT_TYPE_EXIT:
|
||||
eventString = "Exit";
|
||||
break;
|
||||
case ActivityRecognitionProvider.EVENT_TYPE_FLUSH_COMPLETE:
|
||||
eventString = "FlushComplete";
|
||||
break;
|
||||
default:
|
||||
eventString = "<Invalid>";
|
||||
break;
|
||||
}
|
||||
|
||||
return String.format(
|
||||
"Activity='%s', EventType=%s(%s), TimestampNs=%s",
|
||||
mActivity,
|
||||
eventString,
|
||||
mEventType,
|
||||
mTimestampNs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@ import android.util.Log;
|
||||
* @hide
|
||||
*/
|
||||
public class ActivityRecognitionProxy {
|
||||
private final String TAG = "ActivityRecognitionProxy";
|
||||
private static final String TAG = "ActivityRecognitionProxy";
|
||||
|
||||
private final ServiceWatcher mServiceWatcher;
|
||||
private final ActivityRecognitionHardware mActivityRecognitionHardware;
|
||||
|
||||
@@ -85,6 +86,7 @@ public class ActivityRecognitionProxy {
|
||||
|
||||
// try to bind the provider
|
||||
if (!activityRecognitionProxy.mServiceWatcher.start()) {
|
||||
Log.e(TAG, "ServiceWatcher could not start.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user