Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | package com.android.internal.logging.legacy; |
| 17 | |
| 18 | import android.util.Log; |
| 19 | |
Chris Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 20 | import android.metrics.LogMaker; |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 21 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 22 | |
| 23 | /** |
| 24 | * Parse the Android lockscreen gesture logs. |
| 25 | * @hide |
| 26 | */ |
| 27 | public class StatusBarStateParser extends TagParser { |
| 28 | private static final String TAG = "StatusBarStateParser"; |
| 29 | private static final int EVENTLOG_TAG = 36004; |
| 30 | |
| 31 | // source of truth is com.android.systemui.statusbar.StatusBarState |
| 32 | public static final int SHADE = 0; |
| 33 | public static final int KEYGUARD = 1; |
| 34 | public static final int SHADE_LOCKED = 2; |
| 35 | |
| 36 | @Override |
| 37 | public int getTag() { |
| 38 | return EVENTLOG_TAG; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public void parseEvent(TronLogger logger, long eventTimeMs, Object[] operands) { |
| 43 | final boolean debug = Util.debug(); |
| 44 | if (operands.length >= 6) { |
| 45 | try { |
| 46 | // [state, isShowing, isOccluded, isBouncerShowing, isSecure, isCurrentlyInsecure] |
| 47 | int state = ((Integer) operands[0]).intValue(); |
| 48 | boolean isBouncerShowing = (((Integer) operands[3]).intValue()) == 1; |
| 49 | int isSecure = ((Integer) operands[4]).intValue(); |
| 50 | |
| 51 | int view = MetricsEvent.LOCKSCREEN; |
| 52 | int type = MetricsEvent.TYPE_OPEN; |
| 53 | if (state == SHADE) { |
| 54 | type = MetricsEvent.TYPE_CLOSE; |
| 55 | } else if (isBouncerShowing) { |
| 56 | view = MetricsEvent.BOUNCER; |
| 57 | } |
| 58 | |
Chris Wren | b623714 | 2017-01-23 16:42:58 -0500 | [diff] [blame] | 59 | LogMaker proto = logger.obtain(); |
Chris Wren | 26ca65d | 2016-11-29 10:43:28 -0500 | [diff] [blame] | 60 | proto.setCategory(view); |
| 61 | proto.setType(type); |
| 62 | proto.setTimestamp(eventTimeMs); |
| 63 | proto.setSubtype(isSecure); |
| 64 | logger.addEvent(proto); |
| 65 | } catch (ClassCastException e) { |
| 66 | if (debug) { |
| 67 | Log.e(TAG, "unexpected operand type: ", e); |
| 68 | } |
| 69 | } |
| 70 | } else if (debug) { |
| 71 | Log.w(TAG, "wrong number of operands: " + operands.length); |
| 72 | } |
| 73 | } |
| 74 | } |