diff options
Diffstat (limited to 'packages/Keyguard')
11 files changed, 22 insertions, 861 deletions
diff --git a/packages/Keyguard/Android.mk b/packages/Keyguard/Android.mk index 1be44f9..96ed2e7 100644 --- a/packages/Keyguard/Android.mk +++ b/packages/Keyguard/Android.mk @@ -16,8 +16,7 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-subdir-Iaidl-files) \ - $(call all-proto-files-under,src) +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-subdir-Iaidl-files) LOCAL_MODULE := Keyguard @@ -27,9 +26,6 @@ LOCAL_PRIVILEGED_MODULE := true LOCAL_PROGUARD_FLAG_FILES := proguard.flags -LOCAL_PROTOC_OPTIMIZE_TYPE := nano -LOCAL_PROTO_JAVA_OUTPUT_PARAMS := optional_field_style=accessors - LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res include $(BUILD_STATIC_JAVA_LIBRARY) diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java index d2bf30c..ab18271 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardHostView.java @@ -71,6 +71,7 @@ public class KeyguardHostView extends KeyguardViewBase { private AppWidgetHost mAppWidgetHost; private AppWidgetManager mAppWidgetManager; private KeyguardWidgetPager mAppWidgetContainer; + // TODO remove transport control references, these don't exist anymore private KeyguardTransportControlView mTransportControl; private int mAppWidgetToShow; @@ -235,36 +236,6 @@ public class KeyguardHostView extends KeyguardViewBase { mKeyguardMultiUserSelectorView.finalizeActiveUserView(true); } } - @Override - public void onMusicClientIdChanged( - int clientGeneration, boolean clearing, android.app.PendingIntent intent) { - // Set transport state to invisible until we know music is playing (below) - if (DEBUGXPORT && (mClientGeneration != clientGeneration || clearing)) { - Log.v(TAG, (clearing ? "hide" : "show") + " transport, gen:" + clientGeneration); - } - mClientGeneration = clientGeneration; - final int newState = (clearing ? TRANSPORT_GONE - : (mTransportState == TRANSPORT_VISIBLE ? - TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE)); - if (newState != mTransportState) { - mTransportState = newState; - if (DEBUGXPORT) Log.v(TAG, "update widget: transport state changed"); - KeyguardHostView.this.post(mSwitchPageRunnable); - } - } - @Override - public void onMusicPlaybackStateChanged(int playbackState, long eventTime) { - if (DEBUGXPORT) Log.v(TAG, "music state changed: " + playbackState); - if (mTransportState != TRANSPORT_GONE) { - final int newState = (isMusicPlaying(playbackState) ? - TRANSPORT_VISIBLE : TRANSPORT_INVISIBLE); - if (newState != mTransportState) { - mTransportState = newState; - if (DEBUGXPORT) Log.v(TAG, "update widget: play state changed"); - KeyguardHostView.this.post(mSwitchPageRunnable); - } - } - } }; private static final boolean isMusicPlaying(int playbackState) { diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSimpleHostView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSimpleHostView.java index 3f6ced6..bc159cb 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardSimpleHostView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSimpleHostView.java @@ -25,6 +25,7 @@ public class KeyguardSimpleHostView extends KeyguardViewBase { public KeyguardSimpleHostView(Context context, AttributeSet attrs) { super(context, attrs); + KeyguardUpdateMonitor.getInstance(context).registerCallback(mUpdateCallback); } @Override @@ -62,4 +63,10 @@ public class KeyguardSimpleHostView extends KeyguardViewBase { // TODO Auto-generated method stub } + private KeyguardUpdateMonitorCallback mUpdateCallback = new KeyguardUpdateMonitorCallback() { + @Override + public void onUserSwitchComplete(int userId) { + getSecurityContainer().showPrimarySecurityScreen(false /* turning off */); + } + }; } diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java index 7918755..38316ff 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardStatusView.java @@ -166,6 +166,11 @@ public class KeyguardStatusView extends GridLayout { return info; } + @Override + public boolean hasOverlappingRendering() { + return false; + } + // DateFormat.getBestDateTimePattern is extremely expensive, and refresh is called often. // This is an optimization to ensure we only recompute the patterns when the inputs change. private static final class Patterns { diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java index 668e1ef..bf34705 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -91,8 +91,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private static final int MSG_KEYGUARD_VISIBILITY_CHANGED = 312; protected static final int MSG_BOOT_COMPLETED = 313; private static final int MSG_USER_SWITCH_COMPLETE = 314; - private static final int MSG_SET_CURRENT_CLIENT_ID = 315; - protected static final int MSG_SET_PLAYBACK_STATE = 316; protected static final int MSG_USER_INFO_CHANGED = 317; protected static final int MSG_REPORT_EMERGENCY_CALL_ACTION = 318; private static final int MSG_SCREEN_TURNED_ON = 319; @@ -184,12 +182,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { case MSG_BOOT_COMPLETED: handleBootCompleted(); break; - case MSG_SET_CURRENT_CLIENT_ID: - handleSetGenerationId(msg.arg1, msg.arg2 != 0, (PendingIntent) msg.obj); - break; - case MSG_SET_PLAYBACK_STATE: - handleSetPlaybackState(msg.arg1, msg.arg2, (Long) msg.obj); - break; case MSG_USER_INFO_CHANGED: handleUserInfoChanged(msg.arg1); break; @@ -206,8 +198,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } }; - private AudioManager mAudioManager; - private SparseBooleanArray mUserHasTrust = new SparseBooleanArray(); @Override @@ -257,49 +247,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { private DisplayClientState mDisplayClientState = new DisplayClientState(); - /** - * This currently implements the bare minimum required to enable showing and hiding - * KeyguardTransportControl. There's a lot of client state to maintain which is why - * KeyguardTransportControl maintains an independent connection while it's showing. - */ - private final IRemoteControlDisplay.Stub mRemoteControlDisplay = - new IRemoteControlDisplay.Stub() { - - public void setPlaybackState(int generationId, int state, long stateChangeTimeMs, - long currentPosMs, float speed) { - Message msg = mHandler.obtainMessage(MSG_SET_PLAYBACK_STATE, - generationId, state, stateChangeTimeMs); - mHandler.sendMessage(msg); - } - - public void setMetadata(int generationId, Bundle metadata) { - - } - - public void setTransportControlInfo(int generationId, int flags, int posCapabilities) { - - } - - public void setArtwork(int generationId, Bitmap bitmap) { - - } - - public void setAllMetadata(int generationId, Bundle metadata, Bitmap bitmap) { - - } - - public void setEnabled(boolean enabled) { - // no-op: this RemoteControlDisplay is not subject to being disabled. - } - - public void setCurrentClientId(int clientGeneration, PendingIntent mediaIntent, - boolean clearing) throws RemoteException { - Message msg = mHandler.obtainMessage(MSG_SET_CURRENT_CLIENT_ID, - clientGeneration, (clearing ? 1 : 0), mediaIntent); - mHandler.sendMessage(msg); - } - }; - private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { @@ -501,38 +448,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } - protected void handleSetGenerationId(int clientGeneration, boolean clearing, PendingIntent p) { - mDisplayClientState.clientGeneration = clientGeneration; - mDisplayClientState.clearing = clearing; - mDisplayClientState.intent = p; - if (DEBUG) - Log.v(TAG, "handleSetGenerationId(g=" + clientGeneration + ", clear=" + clearing + ")"); - for (int i = 0; i < mCallbacks.size(); i++) { - KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); - if (cb != null) { - cb.onMusicClientIdChanged(clientGeneration, clearing, p); - } - } - } - - protected void handleSetPlaybackState(int generationId, int playbackState, long eventTime) { - if (DEBUG) - Log.v(TAG, "handleSetPlaybackState(gen=" + generationId - + ", state=" + playbackState + ", t=" + eventTime + ")"); - mDisplayClientState.playbackState = playbackState; - mDisplayClientState.playbackEventTime = eventTime; - if (generationId == mDisplayClientState.clientGeneration) { - for (int i = 0; i < mCallbacks.size(); i++) { - KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); - if (cb != null) { - cb.onMusicPlaybackStateChanged(playbackState, eventTime); - } - } - } else { - Log.w(TAG, "Ignoring generation id " + generationId + " because it's not current"); - } - } - private void handleUserInfoChanged(int userId) { for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); @@ -694,8 +609,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { protected void handleBootCompleted() { if (mBootCompleted) return; mBootCompleted = true; - mAudioManager = new AudioManager(mContext); - mAudioManager.registerRemoteControlDisplay(mRemoteControlDisplay); for (int i = 0; i < mCallbacks.size(); i++) { KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get(); if (cb != null) { @@ -1013,12 +926,6 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { callback.onRefreshCarrierInfo(mTelephonyPlmn, mTelephonySpn); callback.onClockVisibilityChanged(); callback.onSimStateChanged(mSimState); - callback.onMusicClientIdChanged( - mDisplayClientState.clientGeneration, - mDisplayClientState.clearing, - mDisplayClientState.intent); - callback.onMusicPlaybackStateChanged(mDisplayClientState.playbackState, - mDisplayClientState.playbackEventTime); } public void sendKeyguardVisibilityChanged(boolean showing) { diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java index bcdf18f..01600d2 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitorCallback.java @@ -144,18 +144,6 @@ public class KeyguardUpdateMonitorCallback { public void onBootCompleted() { } /** - * Called when audio client attaches or detaches from AudioManager. - */ - public void onMusicClientIdChanged(int clientGeneration, boolean clearing, PendingIntent intent) { } - - /** - * Called when the audio playback state changes. - * @param playbackState - * @param eventTime - */ - public void onMusicPlaybackStateChanged(int playbackState, long eventTime) { } - - /** * Called when the emergency call button is pressed. */ void onEmergencyCallAction() { } diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardViewBase.java b/packages/Keyguard/src/com/android/keyguard/KeyguardViewBase.java index 3e444fa..8945b15 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardViewBase.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardViewBase.java @@ -341,11 +341,11 @@ public abstract class KeyguardViewBase extends FrameLayout implements SecurityCa } // Volume buttons should only function for music (local or remote). // TODO: Actually handle MUTE. - mAudioManager.adjustLocalOrRemoteStreamVolume( - AudioManager.STREAM_MUSIC, + mAudioManager.adjustSuggestedStreamVolume( keyCode == KeyEvent.KEYCODE_VOLUME_UP ? AudioManager.ADJUST_RAISE - : AudioManager.ADJUST_LOWER); + : AudioManager.ADJUST_LOWER /* direction */, + AudioManager.STREAM_MUSIC /* stream */, 0 /* flags */); // Don't execute default volume behavior return true; } else { @@ -376,17 +376,13 @@ public abstract class KeyguardViewBase extends FrameLayout implements SecurityCa } private void handleMediaKeyEvent(KeyEvent keyEvent) { - IAudioService audioService = IAudioService.Stub.asInterface( - ServiceManager.checkService(Context.AUDIO_SERVICE)); - if (audioService != null) { - try { - audioService.dispatchMediaKeyEvent(keyEvent); - } catch (RemoteException e) { - Log.e("KeyguardViewBase", "dispatchMediaKeyEvent threw exception " + e); + synchronized (this) { + if (mAudioManager == null) { + mAudioManager = (AudioManager) getContext().getSystemService( + Context.AUDIO_SERVICE); } - } else { - Slog.w("KeyguardViewBase", "Unable to find IAudioService for media key event"); } + mAudioManager.dispatchMediaKeyEvent(keyEvent); } @Override diff --git a/packages/Keyguard/src/com/android/keyguard/analytics/KeyguardAnalytics.java b/packages/Keyguard/src/com/android/keyguard/analytics/KeyguardAnalytics.java deleted file mode 100644 index 20af2f1..0000000 --- a/packages/Keyguard/src/com/android/keyguard/analytics/KeyguardAnalytics.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.keyguard.analytics; - -import com.google.protobuf.nano.CodedOutputByteBufferNano; -import com.google.protobuf.nano.MessageNano; - -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorEvent; -import android.hardware.SensorEventListener; -import android.hardware.SensorManager; -import android.os.AsyncTask; -import android.util.Log; -import android.view.MotionEvent; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -/** - * Tracks sessions, touch and sensor events in Keyguard. - * - * A session starts when the user is presented with the Keyguard and ends when the Keyguard is no - * longer visible to the user. - */ -public class KeyguardAnalytics implements SensorEventListener { - - private static final boolean DEBUG = false; - private static final String TAG = "KeyguardAnalytics"; - private static final long TIMEOUT_MILLIS = 11000; // 11 seconds. - - private static final int[] SENSORS = new int[] { - Sensor.TYPE_ACCELEROMETER, - Sensor.TYPE_GYROSCOPE, - Sensor.TYPE_PROXIMITY, - Sensor.TYPE_LIGHT, - Sensor.TYPE_ROTATION_VECTOR, - }; - - private Session mCurrentSession = null; - // Err on the side of caution, so logging is not started after a crash even tough the screen - // is off. - private boolean mScreenOn = false; - private boolean mHidden = false; - - private final SensorManager mSensorManager; - private final SessionTypeAdapter mSessionTypeAdapter; - private final File mAnalyticsFile; - - public KeyguardAnalytics(Context context, SessionTypeAdapter sessionTypeAdapter, - File analyticsFile) { - mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); - mSessionTypeAdapter = sessionTypeAdapter; - mAnalyticsFile = analyticsFile; - } - - public Callback getCallback() { - return mCallback; - } - - public interface Callback { - public void onShow(); - public void onHide(); - public void onScreenOn(); - public void onScreenOff(); - public boolean onTouchEvent(MotionEvent ev, int width, int height); - public void onSetOccluded(boolean hidden); - } - - public interface SessionTypeAdapter { - public int getSessionType(); - } - - private void sessionEntrypoint() { - if (mCurrentSession == null && mScreenOn && !mHidden) { - onSessionStart(); - } - } - - private void sessionExitpoint(int result) { - if (mCurrentSession != null) { - onSessionEnd(result); - } - } - - private void onSessionStart() { - int type = mSessionTypeAdapter.getSessionType(); - mCurrentSession = new Session(System.currentTimeMillis(), System.nanoTime(), type); - if (type == Session.TYPE_KEYGUARD_SECURE) { - mCurrentSession.setRedactTouchEvents(); - } - for (int sensorType : SENSORS) { - Sensor s = mSensorManager.getDefaultSensor(sensorType); - if (s != null) { - mSensorManager.registerListener(this, s, SensorManager.SENSOR_DELAY_GAME); - } - } - if (DEBUG) { - Log.d(TAG, "onSessionStart()"); - } - } - - private void onSessionEnd(int result) { - if (DEBUG) { - Log.d(TAG, String.format("onSessionEnd(success=%d)", result)); - } - mSensorManager.unregisterListener(this); - - Session session = mCurrentSession; - mCurrentSession = null; - - session.end(System.currentTimeMillis(), result); - queueSession(session); - } - - private void queueSession(final Session currentSession) { - if (DEBUG) { - Log.i(TAG, "Saving session."); - } - new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... params) { - try { - byte[] b = writeDelimitedProto(currentSession.toProto()); - OutputStream os = new FileOutputStream(mAnalyticsFile, true /* append */); - if (DEBUG) { - Log.d(TAG, String.format("Serialized size: %d kB.", b.length / 1024)); - } - try { - os.write(b); - os.flush(); - } finally { - try { - os.close(); - } catch (IOException e) { - Log.e(TAG, "Exception while closing file", e); - } - } - } catch (IOException e) { - Log.e(TAG, "Exception while writing file", e); - } - return null; - } - - private byte[] writeDelimitedProto(MessageNano proto) - throws IOException { - byte[] result = new byte[CodedOutputByteBufferNano.computeMessageSizeNoTag(proto)]; - CodedOutputByteBufferNano ob = CodedOutputByteBufferNano.newInstance(result); - ob.writeMessageNoTag(proto); - ob.checkNoSpaceLeft(); - return result; - } - }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); - } - - @Override - public synchronized void onSensorChanged(SensorEvent event) { - if (false) { - Log.v(TAG, String.format( - "onSensorChanged(name=%s, values[0]=%f)", - event.sensor.getName(), event.values[0])); - } - if (mCurrentSession != null) { - mCurrentSession.addSensorEvent(event, System.nanoTime()); - enforceTimeout(); - } - } - - private void enforceTimeout() { - if (System.currentTimeMillis() - mCurrentSession.getStartTimestampMillis() - > TIMEOUT_MILLIS) { - onSessionEnd(Session.RESULT_UNKNOWN); - if (DEBUG) { - Log.i(TAG, "Analytics timed out."); - } - } - } - - @Override - public void onAccuracyChanged(Sensor sensor, int accuracy) { - } - - private final Callback mCallback = new Callback() { - @Override - public void onShow() { - if (DEBUG) { - Log.d(TAG, "onShow()"); - } - synchronized (KeyguardAnalytics.this) { - sessionEntrypoint(); - } - } - - @Override - public void onHide() { - if (DEBUG) { - Log.d(TAG, "onHide()"); - } - synchronized (KeyguardAnalytics.this) { - sessionExitpoint(Session.RESULT_SUCCESS); - } - } - - @Override - public void onScreenOn() { - if (DEBUG) { - Log.d(TAG, "onScreenOn()"); - } - synchronized (KeyguardAnalytics.this) { - mScreenOn = true; - sessionEntrypoint(); - } - } - - @Override - public void onScreenOff() { - if (DEBUG) { - Log.d(TAG, "onScreenOff()"); - } - synchronized (KeyguardAnalytics.this) { - mScreenOn = false; - sessionExitpoint(Session.RESULT_FAILURE); - } - } - - @Override - public boolean onTouchEvent(MotionEvent ev, int width, int height) { - if (DEBUG) { - Log.v(TAG, "onTouchEvent(ev.action=" - + MotionEvent.actionToString(ev.getAction()) + ")"); - } - synchronized (KeyguardAnalytics.this) { - if (mCurrentSession != null) { - mCurrentSession.addMotionEvent(ev); - mCurrentSession.setTouchArea(width, height); - enforceTimeout(); - } - } - return true; - } - - @Override - public void onSetOccluded(boolean hidden) { - synchronized (KeyguardAnalytics.this) { - if (hidden != mHidden) { - if (DEBUG) { - Log.d(TAG, "onSetOccluded(" + hidden + ")"); - } - mHidden = hidden; - if (hidden) { - // Could have gone to camera on purpose / by falsing or an app could have - // launched on top of the lockscreen. - sessionExitpoint(Session.RESULT_UNKNOWN); - } else { - sessionEntrypoint(); - } - } - } - } - }; - -} diff --git a/packages/Keyguard/src/com/android/keyguard/analytics/PointerTracker.java b/packages/Keyguard/src/com/android/keyguard/analytics/PointerTracker.java deleted file mode 100644 index e68f751..0000000 --- a/packages/Keyguard/src/com/android/keyguard/analytics/PointerTracker.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.keyguard.analytics; - -import android.graphics.RectF; -import android.util.FloatMath; -import android.util.SparseArray; -import android.view.MotionEvent; - -import java.util.HashMap; -import java.util.Map; - -import static com.android.keyguard.analytics.KeyguardAnalyticsProtos.Session.TouchEvent.BoundingBox; - -/** - * Takes motion events and tracks the length and bounding box of each pointer gesture as well as - * the bounding box of the whole gesture. - */ -public class PointerTracker { - private SparseArray<Pointer> mPointerInfoMap = new SparseArray<Pointer>(); - private RectF mTotalBoundingBox = new RectF(); - - public void addMotionEvent(MotionEvent ev) { - if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) { - float x = ev.getX(); - float y = ev.getY(); - mTotalBoundingBox.set(x, y, x, y); - } - for (int i = 0; i < ev.getPointerCount(); i++) { - int id = ev.getPointerId(i); - Pointer pointer = getPointer(id); - float x = ev.getX(i); - float y = ev.getY(i); - boolean down = ev.getActionMasked() == MotionEvent.ACTION_DOWN - || (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN - && ev.getActionIndex() == i); - pointer.addPoint(x, y, down); - mTotalBoundingBox.union(x, y); - } - } - - public float getPointerLength(int id) { - return getPointer(id).length; - } - - public BoundingBox getBoundingBox() { - return boundingBoxFromRect(mTotalBoundingBox); - } - - public BoundingBox getPointerBoundingBox(int id) { - return boundingBoxFromRect(getPointer(id).boundingBox); - } - - private BoundingBox boundingBoxFromRect(RectF f) { - BoundingBox bb = new BoundingBox(); - bb.setHeight(f.height()); - bb.setWidth(f.width()); - return bb; - } - - private Pointer getPointer(int id) { - Pointer p = mPointerInfoMap.get(id); - if (p == null) { - p = new Pointer(); - mPointerInfoMap.put(id, p); - } - return p; - } - - private static class Pointer { - public float length; - public final RectF boundingBox = new RectF(); - - private float mLastX; - private float mLastY; - - public void addPoint(float x, float y, boolean down) { - float deltaX; - float deltaY; - if (down) { - boundingBox.set(x, y, x, y); - length = 0f; - deltaX = 0; - deltaY = 0; - } else { - deltaX = x - mLastX; - deltaY = y - mLastY; - } - mLastX = x; - mLastY = y; - length += FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY); - boundingBox.union(x, y); - } - } -} diff --git a/packages/Keyguard/src/com/android/keyguard/analytics/Session.java b/packages/Keyguard/src/com/android/keyguard/analytics/Session.java deleted file mode 100644 index 05f9165..0000000 --- a/packages/Keyguard/src/com/android/keyguard/analytics/Session.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.keyguard.analytics; - -import android.os.Build; -import android.util.Slog; -import android.view.MotionEvent; - -import java.util.ArrayList; - -import static com.android.keyguard.analytics.KeyguardAnalyticsProtos.Session.SensorEvent; -import static com.android.keyguard.analytics.KeyguardAnalyticsProtos.Session.TouchEvent; - -/** - * Records data about one keyguard session. - * - * The recorded data contains start and end of the session, whether it unlocked the device - * successfully, sensor data and touch data. - * - * If the keyguard is secure, the recorded touch data will correlate or contain the user pattern or - * PIN. If this is not desired, the touch coordinates can be redacted before serialization. - */ -public class Session { - - private static final String TAG = "KeyguardAnalytics"; - private static final boolean DEBUG = false; - - /** - * The user has failed to unlock the device in this session. - */ - public static final int RESULT_FAILURE = KeyguardAnalyticsProtos.Session.FAILURE; - /** - * The user has succeeded in unlocking the device in this session. - */ - public static final int RESULT_SUCCESS = KeyguardAnalyticsProtos.Session.SUCCESS; - - /** - * It is unknown how the session with the keyguard ended. - */ - public static final int RESULT_UNKNOWN = KeyguardAnalyticsProtos.Session.UNKNOWN; - - /** - * This session took place on an insecure keyguard. - */ - public static final int TYPE_KEYGUARD_INSECURE - = KeyguardAnalyticsProtos.Session.KEYGUARD_INSECURE; - - /** - * This session took place on an secure keyguard. - */ - public static final int TYPE_KEYGUARD_SECURE - = KeyguardAnalyticsProtos.Session.KEYGUARD_SECURE; - - /** - * This session took place during a fake wake up of the device. - */ - public static final int TYPE_RANDOM_WAKEUP = KeyguardAnalyticsProtos.Session.RANDOM_WAKEUP; - - - private final PointerTracker mPointerTracker = new PointerTracker(); - - private final long mStartTimestampMillis; - private final long mStartSystemTimeNanos; - private final int mType; - - private boolean mRedactTouchEvents; - private ArrayList<TouchEvent> mMotionEvents = new ArrayList<TouchEvent>(200); - private ArrayList<SensorEvent> mSensorEvents = new ArrayList<SensorEvent>(600); - private int mTouchAreaHeight; - private int mTouchAreaWidth; - - private long mEndTimestampMillis; - private int mResult; - private boolean mEnded; - - public Session(long startTimestampMillis, long startSystemTimeNanos, int type) { - mStartTimestampMillis = startTimestampMillis; - mStartSystemTimeNanos = startSystemTimeNanos; - mType = type; - } - - public void end(long endTimestampMillis, int result) { - mEnded = true; - mEndTimestampMillis = endTimestampMillis; - mResult = result; - } - - public void addMotionEvent(MotionEvent motionEvent) { - if (mEnded) { - return; - } - mPointerTracker.addMotionEvent(motionEvent); - mMotionEvents.add(protoFromMotionEvent(motionEvent)); - } - - public void addSensorEvent(android.hardware.SensorEvent eventOrig, long systemTimeNanos) { - if (mEnded) { - return; - } - SensorEvent event = protoFromSensorEvent(eventOrig, systemTimeNanos); - mSensorEvents.add(event); - if (DEBUG) { - Slog.v(TAG, String.format("addSensorEvent(name=%s, values[0]=%f", - event.getType(), event.values[0])); - } - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("Session{"); - sb.append("mType=").append(mType); - sb.append(", mStartTimestampMillis=").append(mStartTimestampMillis); - sb.append(", mStartSystemTimeNanos=").append(mStartSystemTimeNanos); - sb.append(", mEndTimestampMillis=").append(mEndTimestampMillis); - sb.append(", mResult=").append(mResult); - sb.append(", mRedactTouchEvents=").append(mRedactTouchEvents); - sb.append(", mTouchAreaHeight=").append(mTouchAreaHeight); - sb.append(", mTouchAreaWidth=").append(mTouchAreaWidth); - sb.append(", mMotionEvents=[size=").append(mMotionEvents.size()).append("]"); - sb.append(", mSensorEvents=[size=").append(mSensorEvents.size()).append("]"); - sb.append('}'); - return sb.toString(); - } - - public KeyguardAnalyticsProtos.Session toProto() { - KeyguardAnalyticsProtos.Session proto = new KeyguardAnalyticsProtos.Session(); - proto.setStartTimestampMillis(mStartTimestampMillis); - proto.setDurationMillis(mEndTimestampMillis - mStartTimestampMillis); - proto.setBuild(Build.FINGERPRINT); - proto.setResult(mResult); - proto.sensorEvents = mSensorEvents.toArray(proto.sensorEvents); - proto.touchEvents = mMotionEvents.toArray(proto.touchEvents); - proto.setTouchAreaWidth(mTouchAreaWidth); - proto.setTouchAreaHeight(mTouchAreaHeight); - proto.setType(mType); - if (mRedactTouchEvents) { - redactTouchEvents(proto.touchEvents); - } - return proto; - } - - private void redactTouchEvents(TouchEvent[] touchEvents) { - for (int i = 0; i < touchEvents.length; i++) { - TouchEvent t = touchEvents[i]; - for (int j = 0; j < t.pointers.length; j++) { - TouchEvent.Pointer p = t.pointers[j]; - p.clearX(); - p.clearY(); - } - t.setRedacted(true); - } - } - - private SensorEvent protoFromSensorEvent(android.hardware.SensorEvent ev, long sysTimeNanos) { - SensorEvent proto = new SensorEvent(); - proto.setType(ev.sensor.getType()); - proto.setTimeOffsetNanos(sysTimeNanos - mStartSystemTimeNanos); - proto.setTimestamp(ev.timestamp); - proto.values = ev.values.clone(); - return proto; - } - - private TouchEvent protoFromMotionEvent(MotionEvent ev) { - int count = ev.getPointerCount(); - TouchEvent proto = new TouchEvent(); - proto.setTimeOffsetNanos(ev.getEventTimeNano() - mStartSystemTimeNanos); - proto.setAction(ev.getActionMasked()); - proto.setActionIndex(ev.getActionIndex()); - proto.pointers = new TouchEvent.Pointer[count]; - for (int i = 0; i < count; i++) { - TouchEvent.Pointer p = new TouchEvent.Pointer(); - p.setX(ev.getX(i)); - p.setY(ev.getY(i)); - p.setSize(ev.getSize(i)); - p.setPressure(ev.getPressure(i)); - p.setId(ev.getPointerId(i)); - proto.pointers[i] = p; - if ((ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP && ev.getActionIndex() == i) - || ev.getActionMasked() == MotionEvent.ACTION_UP) { - p.boundingBox = mPointerTracker.getPointerBoundingBox(p.getId()); - p.setLength(mPointerTracker.getPointerLength(p.getId())); - } - } - if (ev.getActionMasked() == MotionEvent.ACTION_UP) { - proto.boundingBox = mPointerTracker.getBoundingBox(); - } - return proto; - } - - /** - * Discards the x / y coordinates of the touch events on serialization. Retained are the - * size of the individual and overall bounding boxes and the length of each pointer's gesture. - */ - public void setRedactTouchEvents() { - mRedactTouchEvents = true; - } - - public void setTouchArea(int width, int height) { - mTouchAreaWidth = width; - mTouchAreaHeight = height; - } - - public long getStartTimestampMillis() { - return mStartTimestampMillis; - } -} diff --git a/packages/Keyguard/src/com/android/keyguard/analytics/keyguard_analytics.proto b/packages/Keyguard/src/com/android/keyguard/analytics/keyguard_analytics.proto deleted file mode 100644 index 68b1590..0000000 --- a/packages/Keyguard/src/com/android/keyguard/analytics/keyguard_analytics.proto +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -syntax = "proto2"; - -package keyguard; - -option java_package = "com.android.keyguard.analytics"; -option java_outer_classname = "KeyguardAnalyticsProtos"; - -message Session { - message TouchEvent { - message BoundingBox { - optional float width = 1; - optional float height = 2; - } - - enum Action { - // Keep in sync with MotionEvent. - DOWN = 0; - UP = 1; - MOVE = 2; - CANCEL = 3; - OUTSIDE = 4; - POINTER_DOWN = 5; - POINTER_UP = 6; - } - - message Pointer { - optional float x = 1; - optional float y = 2; - optional float size = 3; - optional float pressure = 4; - optional int32 id = 5; - optional float length = 6; - // Bounding box of the pointer. Only set on UP or POINTER_UP event of this pointer. - optional BoundingBox boundingBox = 7; - } - - optional uint64 timeOffsetNanos = 1; - optional Action action = 2; - optional int32 actionIndex = 3; - repeated Pointer pointers = 4; - /* If true, the the x / y coordinates of the touch events were redacted. Retained are the - size of the individual and overall bounding boxes and the length of each pointer's - gesture. */ - optional bool redacted = 5; - // Bounding box of the whole gesture. Only set on UP event. - optional BoundingBox boundingBox = 6; - } - - message SensorEvent { - enum Type { - ACCELEROMETER = 1; - GYROSCOPE = 4; - LIGHT = 5; - PROXIMITY = 8; - ROTATION_VECTOR = 11; - } - - optional Type type = 1; - optional uint64 timeOffsetNanos = 2; - repeated float values = 3; - optional uint64 timestamp = 4; - } - - enum Result { - FAILURE = 0; - SUCCESS = 1; - UNKNOWN = 2; - } - - enum Type { - KEYGUARD_INSECURE = 0; - KEYGUARD_SECURE = 1; - RANDOM_WAKEUP = 2; - } - - optional uint64 startTimestampMillis = 1; - optional uint64 durationMillis = 2; - optional string build = 3; - optional Result result = 4; - repeated TouchEvent touchEvents = 5; - repeated SensorEvent sensorEvents = 6; - - optional int32 touchAreaWidth = 9; - optional int32 touchAreaHeight = 10; - optional Type type = 11; -} |