Methods Summary |
---|
private void | checkPermissions()
String message = String.format(
"Permission '%s' not granted to access ActivityRecognitionHardware",
HARDWARE_PERMISSION);
mContext.enforceCallingPermission(HARDWARE_PERMISSION, message);
|
public boolean | disableActivityEvent(java.lang.String activity, int eventType)
checkPermissions();
int activityType = getActivityType(activity);
if (activityType == INVALID_ACTIVITY_TYPE) {
return false;
}
int result = nativeDisableActivityEvent(activityType, eventType);
return result == NATIVE_SUCCESS_RESULT;
|
public boolean | enableActivityEvent(java.lang.String activity, int eventType, long reportLatencyNs)
checkPermissions();
int activityType = getActivityType(activity);
if (activityType == INVALID_ACTIVITY_TYPE) {
return false;
}
int result = nativeEnableActivityEvent(activityType, eventType, reportLatencyNs);
return result == NATIVE_SUCCESS_RESULT;
|
private java.lang.String[] | fetchSupportedActivities()
String[] supportedActivities = nativeGetSupportedActivities();
if (supportedActivities != null) {
return supportedActivities;
}
return new String[0];
|
public boolean | flush()
checkPermissions();
int result = nativeFlush();
return result == NATIVE_SUCCESS_RESULT;
|
private java.lang.String | getActivityName(int activityType)
if (activityType < 0 || activityType >= mSupportedActivities.length) {
String message = String.format(
"Invalid ActivityType: %d, SupportedActivities: %d",
activityType,
mSupportedActivities.length);
Log.e(TAG, message);
return null;
}
return mSupportedActivities[activityType];
|
private int | getActivityType(java.lang.String activity)
if (TextUtils.isEmpty(activity)) {
return INVALID_ACTIVITY_TYPE;
}
int supportedActivitiesLength = mSupportedActivities.length;
for (int i = 0; i < supportedActivitiesLength; ++i) {
if (activity.equals(mSupportedActivities[i])) {
return i;
}
}
return INVALID_ACTIVITY_TYPE;
|
public static android.hardware.location.ActivityRecognitionHardware | getInstance(android.content.Context context)
synchronized (sSingletonInstanceLock) {
if (sSingletonInstance == null) {
sSingletonInstance = new ActivityRecognitionHardware(context);
}
return sSingletonInstance;
}
|
public java.lang.String[] | getSupportedActivities()
checkPermissions();
return mSupportedActivities;
|
public boolean | isActivitySupported(java.lang.String activity)
checkPermissions();
int activityType = getActivityType(activity);
return activityType != INVALID_ACTIVITY_TYPE;
|
public static boolean | isSupported()
return nativeIsSupported();
|
private static native void | nativeClassInit()
|
private native int | nativeDisableActivityEvent(int activityType, int eventType)
|
private native int | nativeEnableActivityEvent(int activityType, int eventType, long reportLatenceNs)
|
private native int | nativeFlush()
|
private native java.lang.String[] | nativeGetSupportedActivities()
|
private native void | nativeInitialize()
|
private static native boolean | nativeIsSupported()
|
private native void | nativeRelease()
|
private void | onActivityChanged(android.hardware.location.ActivityRecognitionHardware$Event[] events)Called by the Activity-Recognition HAL.
if (events == null || events.length == 0) {
Log.d(TAG, "No events to broadcast for onActivityChanged.");
return;
}
int eventsLength = events.length;
ActivityRecognitionEvent activityRecognitionEventArray[] =
new ActivityRecognitionEvent[eventsLength];
for (int i = 0; i < eventsLength; ++i) {
Event event = events[i];
String activityName = getActivityName(event.activity);
activityRecognitionEventArray[i] =
new ActivityRecognitionEvent(activityName, event.type, event.timestamp);
}
ActivityChangedEvent activityChangedEvent =
new ActivityChangedEvent(activityRecognitionEventArray);
int size = mSinks.beginBroadcast();
for (int i = 0; i < size; ++i) {
IActivityRecognitionHardwareSink sink = mSinks.getBroadcastItem(i);
try {
sink.onActivityChanged(activityChangedEvent);
} catch (RemoteException e) {
Log.e(TAG, "Error delivering activity changed event.", e);
}
}
mSinks.finishBroadcast();
|
public boolean | registerSink(IActivityRecognitionHardwareSink sink)
checkPermissions();
return mSinks.register(sink);
|
public boolean | unregisterSink(IActivityRecognitionHardwareSink sink)
checkPermissions();
return mSinks.unregister(sink);
|