Merge "Add metrics for status bar" into oc-mr1-dev
This commit is contained in:
@@ -44,7 +44,11 @@
|
||||
<item><xliff:g id="id">@string/status_bar_zen</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_mute</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_volume</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_vpn</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_ethernet</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_wifi</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_mobile</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_airplane</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_cdma_eri</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_data_connection</xliff:g></item>
|
||||
<item><xliff:g id="id">@string/status_bar_phone_evdo_signal</xliff:g></item>
|
||||
@@ -81,6 +85,10 @@
|
||||
<string translatable="false" name="status_bar_alarm_clock">alarm_clock</string>
|
||||
<string translatable="false" name="status_bar_secure">secure</string>
|
||||
<string translatable="false" name="status_bar_clock">clock</string>
|
||||
<string translatable="false" name="status_bar_mobile">mobile</string>
|
||||
<string translatable="false" name="status_bar_vpn">vpn</string>
|
||||
<string translatable="false" name="status_bar_ethernet">ethernet</string>
|
||||
<string translatable="false" name="status_bar_airplane">airplane</string>
|
||||
|
||||
<!-- Flag indicating whether the surface flinger has limited
|
||||
alpha compositing functionality in hardware. If set, the window
|
||||
|
||||
@@ -49,6 +49,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
|
||||
import com.android.systemui.statusbar.policy.IconLogger;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
import com.android.systemui.tuner.TunerService.Tunable;
|
||||
|
||||
@@ -150,7 +151,9 @@ public class BatteryMeterView extends LinearLayout implements
|
||||
public void onTuningChanged(String key, String newValue) {
|
||||
if (StatusBarIconController.ICON_BLACKLIST.equals(key)) {
|
||||
ArraySet<String> icons = StatusBarIconController.getIconBlacklist(newValue);
|
||||
setVisibility(icons.contains(mSlotBattery) ? View.GONE : View.VISIBLE);
|
||||
boolean hidden = icons.contains(mSlotBattery);
|
||||
Dependency.get(IconLogger.class).onIconVisibility(mSlotBattery, !hidden);
|
||||
setVisibility(hidden ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ import com.android.systemui.statusbar.policy.FlashlightController;
|
||||
import com.android.systemui.statusbar.policy.FlashlightControllerImpl;
|
||||
import com.android.systemui.statusbar.policy.HotspotController;
|
||||
import com.android.systemui.statusbar.policy.HotspotControllerImpl;
|
||||
import com.android.systemui.statusbar.policy.IconLogger;
|
||||
import com.android.systemui.statusbar.policy.IconLoggerImpl;
|
||||
import com.android.systemui.statusbar.policy.KeyguardMonitor;
|
||||
import com.android.systemui.statusbar.policy.KeyguardMonitorImpl;
|
||||
import com.android.systemui.statusbar.policy.LocationController;
|
||||
@@ -297,6 +299,9 @@ public class Dependency extends SystemUI {
|
||||
|
||||
mProviders.put(PowerUI.WarningsUI.class, () -> new PowerNotificationWarnings(mContext));
|
||||
|
||||
mProviders.put(IconLogger.class, () -> new IconLoggerImpl(mContext,
|
||||
getDependency(BG_LOOPER), getDependency(MetricsLogger.class)));
|
||||
|
||||
// Put all dependencies above here so the factory can override them if it wants.
|
||||
SystemUIFactory.getInstance().injectDependencies(mProviders, mContext);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ package com.android.systemui.qs.tileimpl;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_QS_CLICK;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_QS_LONG_PRESS;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_QS_SECONDARY_CLICK;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_CONTEXT;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_QS_POSITION;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_QS_VALUE;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_ACTION;
|
||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import android.R.attr;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -45,6 +45,8 @@ import com.android.systemui.plugins.qs.DetailAdapter;
|
||||
import com.android.systemui.plugins.qs.QSIconView;
|
||||
import com.android.systemui.plugins.qs.QSTile;
|
||||
import com.android.systemui.plugins.qs.QSTile.State;
|
||||
import com.android.systemui.qs.PagedTileLayout;
|
||||
import com.android.systemui.qs.PagedTileLayout.TilePage;
|
||||
import com.android.systemui.qs.QSHost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -180,9 +182,19 @@ public abstract class QSTileImpl<TState extends State> implements QSTile {
|
||||
logMaker.addTaggedData(FIELD_QS_VALUE, ((BooleanState) mState).value ? 1 : 0);
|
||||
}
|
||||
return logMaker.setSubtype(getMetricsCategory())
|
||||
.addTaggedData(FIELD_CONTEXT, isFullQs())
|
||||
.addTaggedData(FIELD_QS_POSITION, mHost.indexOf(mTileSpec));
|
||||
}
|
||||
|
||||
private int isFullQs() {
|
||||
for (Object listener : mListeners) {
|
||||
if (TilePage.class.equals(listener.getClass())) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void showDetail(boolean show) {
|
||||
mHandler.obtainMessage(H.SHOW_DETAIL, show ? 1 : 0, 0).sendToTarget();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.android.systemui.statusbar.phone.SignalDrawable;
|
||||
import com.android.systemui.statusbar.phone.StatusBarIconController;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver;
|
||||
import com.android.systemui.statusbar.policy.IconLogger;
|
||||
import com.android.systemui.statusbar.policy.NetworkController;
|
||||
import com.android.systemui.statusbar.policy.NetworkController.IconState;
|
||||
import com.android.systemui.statusbar.policy.NetworkControllerImpl;
|
||||
@@ -65,6 +66,7 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
private static final String SLOT_MOBILE = "mobile";
|
||||
private static final String SLOT_WIFI = "wifi";
|
||||
private static final String SLOT_ETHERNET = "ethernet";
|
||||
private static final String SLOT_VPN = "vpn";
|
||||
|
||||
private final NetworkController mNetworkController;
|
||||
private final SecurityController mSecurityController;
|
||||
@@ -117,6 +119,8 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
private boolean mActivityEnabled;
|
||||
private boolean mForceBlockWifi;
|
||||
|
||||
private final IconLogger mIconLogger = Dependency.get(IconLogger.class);
|
||||
|
||||
public SignalClusterView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -447,14 +451,15 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
private void apply() {
|
||||
if (mWifiGroup == null) return;
|
||||
|
||||
mVpn.setVisibility(mVpnVisible ? View.VISIBLE : View.GONE);
|
||||
if (mVpnVisible) {
|
||||
if (mLastVpnIconId != mVpnIconId) {
|
||||
setIconForView(mVpn, mVpnIconId);
|
||||
mLastVpnIconId = mVpnIconId;
|
||||
}
|
||||
mIconLogger.onIconShown(SLOT_VPN);
|
||||
mVpn.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_VPN);
|
||||
mVpn.setVisibility(View.GONE);
|
||||
}
|
||||
if (DEBUG) Log.d(TAG, String.format("vpn: %s", mVpnVisible ? "VISIBLE" : "GONE"));
|
||||
@@ -466,8 +471,10 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
mLastEthernetIconId = mEthernetIconId;
|
||||
}
|
||||
mEthernetGroup.setContentDescription(mEthernetDescription);
|
||||
mIconLogger.onIconShown(SLOT_ETHERNET);
|
||||
mEthernetGroup.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_ETHERNET);
|
||||
mEthernetGroup.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -481,9 +488,11 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
setIconForView(mWifiDark, mWifiStrengthId);
|
||||
mLastWifiStrengthId = mWifiStrengthId;
|
||||
}
|
||||
mIconLogger.onIconShown(SLOT_WIFI);
|
||||
mWifiGroup.setContentDescription(mWifiDescription);
|
||||
mWifiGroup.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_WIFI);
|
||||
mWifiGroup.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -505,6 +514,11 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
}
|
||||
}
|
||||
}
|
||||
if (anyMobileVisible) {
|
||||
mIconLogger.onIconShown(SLOT_MOBILE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_MOBILE);
|
||||
}
|
||||
|
||||
if (mIsAirplaneMode) {
|
||||
if (mLastAirplaneIconId != mAirplaneIconId) {
|
||||
@@ -512,8 +526,10 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
mLastAirplaneIconId = mAirplaneIconId;
|
||||
}
|
||||
mAirplane.setContentDescription(mAirplaneContentDescription);
|
||||
mIconLogger.onIconShown(SLOT_AIRPLANE);
|
||||
mAirplane.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_AIRPLANE);
|
||||
mAirplane.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -529,7 +545,13 @@ public class SignalClusterView extends LinearLayout implements NetworkController
|
||||
mWifiSignalSpacer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mNoSimsCombo.setVisibility(mNoSimsVisible ? View.VISIBLE : View.GONE);
|
||||
if (mNoSimsVisible) {
|
||||
mIconLogger.onIconShown(SLOT_MOBILE);
|
||||
mNoSimsCombo.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mIconLogger.onIconHidden(SLOT_MOBILE);
|
||||
mNoSimsCombo.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
boolean anythingVisible = mNoSimsVisible || mWifiVisible || mIsAirplaneMode
|
||||
|| anyMobileVisible || mVpnVisible || mEthernetVisible;
|
||||
|
||||
@@ -20,12 +20,8 @@ import android.content.Context;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.internal.statusbar.StatusBarIcon;
|
||||
@@ -38,6 +34,7 @@ import com.android.systemui.statusbar.StatusBarIconView;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
|
||||
import com.android.systemui.statusbar.policy.DarkIconDispatcher;
|
||||
import com.android.systemui.statusbar.policy.IconLogger;
|
||||
import com.android.systemui.tuner.TunerService;
|
||||
import com.android.systemui.tuner.TunerService.Tunable;
|
||||
|
||||
@@ -61,6 +58,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
private final ArrayList<IconManager> mIconGroups = new ArrayList<>();
|
||||
|
||||
private final ArraySet<String> mIconBlacklist = new ArraySet<>();
|
||||
private final IconLogger mIconLogger = Dependency.get(IconLogger.class);
|
||||
|
||||
public StatusBarIconControllerImpl(Context context) {
|
||||
super(context.getResources().getStringArray(
|
||||
@@ -122,6 +120,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
int viewIndex = getViewIndex(index);
|
||||
boolean blocked = mIconBlacklist.contains(slot);
|
||||
|
||||
mIconLogger.onIconVisibility(getSlot(index), icon.visible);
|
||||
mIconGroups.forEach(l -> l.onIconAdded(viewIndex, slot, blocked, icon));
|
||||
}
|
||||
|
||||
@@ -174,6 +173,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
if (getIcon(index) == null) {
|
||||
return;
|
||||
}
|
||||
mIconLogger.onIconHidden(getSlot(index));
|
||||
super.removeIcon(index);
|
||||
int viewIndex = getViewIndex(index);
|
||||
mIconGroups.forEach(l -> l.onRemoveIcon(viewIndex));
|
||||
@@ -196,6 +196,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
|
||||
|
||||
private void handleSet(int index, StatusBarIcon icon) {
|
||||
int viewIndex = getViewIndex(index);
|
||||
mIconLogger.onIconVisibility(getSlot(index), icon.visible);
|
||||
mIconGroups.forEach(l -> l.onSetIcon(viewIndex, icon));
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
@@ -193,8 +192,9 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
|
||||
}
|
||||
|
||||
private void updateClockVisibility() {
|
||||
int visibility = (mClockVisibleByPolicy && mClockVisibleByUser)
|
||||
? View.VISIBLE : View.GONE;
|
||||
boolean visible = mClockVisibleByPolicy && mClockVisibleByUser;
|
||||
Dependency.get(IconLogger.class).onIconVisibility("clock", visible);
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
setVisibility(visibility);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.systemui.statusbar.policy;
|
||||
|
||||
public interface IconLogger {
|
||||
|
||||
void onIconShown(String tag);
|
||||
void onIconHidden(String tag);
|
||||
|
||||
default void onIconVisibility(String tag, boolean visible) {
|
||||
if (visible) {
|
||||
onIconShown(tag);
|
||||
} else {
|
||||
onIconHidden(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.systemui.statusbar.policy;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_NUM_STATUS_ICONS;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_STATUS_ICONS;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.STATUS_BAR_ICONS_CHANGED;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.TYPE_ACTION;
|
||||
|
||||
import android.content.Context;
|
||||
import android.metrics.LogMaker;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class IconLoggerImpl implements IconLogger {
|
||||
|
||||
// Minimum ms between log statements.
|
||||
// NonFinalForTesting
|
||||
@VisibleForTesting
|
||||
protected static long MIN_LOG_INTERVAL = 1000;
|
||||
|
||||
private final Context mContext;
|
||||
private final Handler mHandler;
|
||||
private final MetricsLogger mLogger;
|
||||
private final ArraySet<String> mIcons = new ArraySet<>();
|
||||
private final List<String> mIconIndex;
|
||||
private long mLastLog = System.currentTimeMillis();
|
||||
|
||||
public IconLoggerImpl(Context context, Looper bgLooper, MetricsLogger logger) {
|
||||
mContext = context;
|
||||
mHandler = new Handler(bgLooper);
|
||||
mLogger = logger;
|
||||
String[] icons = mContext.getResources().getStringArray(
|
||||
com.android.internal.R.array.config_statusBarIcons);
|
||||
mIconIndex = Arrays.asList(icons);
|
||||
doLog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIconShown(String tag) {
|
||||
synchronized (mIcons) {
|
||||
if (mIcons.contains(tag)) return;
|
||||
mIcons.add(tag);
|
||||
}
|
||||
if (!mHandler.hasCallbacks(mLog)) {
|
||||
mHandler.postDelayed(mLog, MIN_LOG_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onIconHidden(String tag) {
|
||||
synchronized (mIcons) {
|
||||
if (!mIcons.contains(tag)) return;
|
||||
mIcons.remove(tag);
|
||||
}
|
||||
if (!mHandler.hasCallbacks(mLog)) {
|
||||
mHandler.postDelayed(mLog, MIN_LOG_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
private void doLog() {
|
||||
long time = System.currentTimeMillis();
|
||||
long timeSinceLastLog = time - mLastLog;
|
||||
mLastLog = time;
|
||||
|
||||
ArraySet<String> icons;
|
||||
synchronized (mIcons) {
|
||||
icons = new ArraySet<>(mIcons);
|
||||
}
|
||||
mLogger.write(new LogMaker(STATUS_BAR_ICONS_CHANGED)
|
||||
.setType(TYPE_ACTION)
|
||||
.setLatency(timeSinceLastLog)
|
||||
.addTaggedData(FIELD_NUM_STATUS_ICONS, icons.size())
|
||||
.addTaggedData(FIELD_STATUS_ICONS, getBitField(icons)));
|
||||
}
|
||||
|
||||
private int getBitField(ArraySet<String> icons) {
|
||||
int iconsVisible = 0;
|
||||
for (String icon : icons) {
|
||||
int index = mIconIndex.indexOf(icon);
|
||||
if (index >= 0) {
|
||||
iconsVisible |= (1 << index);
|
||||
}
|
||||
}
|
||||
return iconsVisible;
|
||||
}
|
||||
|
||||
private final Runnable mLog = this::doLog;
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.systemui.statusbar.policy;
|
||||
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_NUM_STATUS_ICONS;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.FIELD_STATUS_ICONS;
|
||||
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent
|
||||
.NOTIFICATION_SINCE_CREATE_MILLIS;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static java.lang.Thread.sleep;
|
||||
|
||||
import android.metrics.LogMaker;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
import android.testing.TestableLooper.MessageHandler;
|
||||
import android.testing.TestableLooper.RunWithLooper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper
|
||||
public class IconLoggerImplTest extends SysuiTestCase {
|
||||
|
||||
private MetricsLogger mMetricsLogger;
|
||||
private IconLoggerImpl mIconLogger;
|
||||
private TestableLooper mTestableLooper;
|
||||
private MessageHandler mMessageHandler;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
IconLoggerImpl.MIN_LOG_INTERVAL = 5; // Low interval for testing
|
||||
mMetricsLogger = mock(MetricsLogger.class);
|
||||
mTestableLooper = TestableLooper.get(this);
|
||||
mMessageHandler = mock(MessageHandler.class);
|
||||
mTestableLooper.setMessageHandler(mMessageHandler);
|
||||
String[] iconArray = new String[] {
|
||||
"test_icon_1",
|
||||
"test_icon_2",
|
||||
};
|
||||
mContext.getOrCreateTestableResources().addOverride(
|
||||
com.android.internal.R.array.config_statusBarIcons, iconArray);
|
||||
mIconLogger = new IconLoggerImpl(mContext, mTestableLooper.getLooper(), mMetricsLogger);
|
||||
when(mMessageHandler.onMessageHandled(any())).thenReturn(true);
|
||||
clearInvocations(mMetricsLogger);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIconShown() throws InterruptedException {
|
||||
// Should only get one message, for the same icon shown twice.
|
||||
mIconLogger.onIconShown("test_icon_2");
|
||||
mIconLogger.onIconShown("test_icon_2");
|
||||
|
||||
// There should be some delay before execute.
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mMessageHandler, never()).onMessageHandled(any());
|
||||
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mMessageHandler, times(1)).onMessageHandled(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIconHidden() throws InterruptedException {
|
||||
// Add the icon so that it can be removed.
|
||||
mIconLogger.onIconShown("test_icon_2");
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
clearInvocations(mMessageHandler);
|
||||
|
||||
// Should only get one message, for the same icon shown twice.
|
||||
mIconLogger.onIconHidden("test_icon_2");
|
||||
mIconLogger.onIconHidden("test_icon_2");
|
||||
|
||||
// There should be some delay before execute.
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mMessageHandler, never()).onMessageHandled(any());
|
||||
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
verify(mMessageHandler, times(1)).onMessageHandled(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog() throws InterruptedException {
|
||||
mIconLogger.onIconShown("test_icon_2");
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verify(mMetricsLogger).write(argThat(maker -> {
|
||||
if (IconLoggerImpl.MIN_LOG_INTERVAL >
|
||||
(long) maker.getTaggedData(NOTIFICATION_SINCE_CREATE_MILLIS)) {
|
||||
Log.e("IconLoggerImplTest", "Invalid latency "
|
||||
+ maker.getTaggedData(NOTIFICATION_SINCE_CREATE_MILLIS));
|
||||
return false;
|
||||
}
|
||||
if (1 != (int) maker.getTaggedData(FIELD_NUM_STATUS_ICONS)) {
|
||||
Log.e("IconLoggerImplTest", "Invalid icon count "
|
||||
+ maker.getTaggedData(FIELD_NUM_STATUS_ICONS));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitField() throws InterruptedException {
|
||||
mIconLogger.onIconShown("test_icon_2");
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verify(mMetricsLogger).write(argThat(maker -> {
|
||||
if ((1 << 1) != (int) maker.getTaggedData(FIELD_STATUS_ICONS)) {
|
||||
Log.e("IconLoggerImplTest", "Invalid bitfield " + Integer.toHexString(
|
||||
(Integer) maker.getTaggedData(FIELD_NUM_STATUS_ICONS)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
|
||||
mIconLogger.onIconShown("test_icon_1");
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verify(mMetricsLogger).write(argThat(maker -> {
|
||||
if ((1 << 1 | 1 << 0) != (int) maker.getTaggedData(FIELD_STATUS_ICONS)) {
|
||||
Log.e("IconLoggerImplTest", "Invalid bitfield " + Integer.toHexString(
|
||||
(Integer) maker.getTaggedData(FIELD_NUM_STATUS_ICONS)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
|
||||
mIconLogger.onIconHidden("test_icon_2");
|
||||
sleep(10);
|
||||
mTestableLooper.processAllMessages();
|
||||
|
||||
verify(mMetricsLogger).write(argThat(maker -> {
|
||||
if ((1 << 0) != (int) maker.getTaggedData(FIELD_STATUS_ICONS)) {
|
||||
Log.e("IconLoggerImplTest", "Invalid bitfield " + Integer.toHexString(
|
||||
(Integer) maker.getTaggedData(FIELD_STATUS_ICONS)));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -3527,6 +3527,7 @@ message MetricsEvent {
|
||||
NOTIFICATION_SNOOZED_CRITERIA = 832;
|
||||
|
||||
// FIELD - The context (source) from which an action is performed
|
||||
// For QS, this is a boolean of whether the panel is expanded
|
||||
FIELD_CONTEXT = 833;
|
||||
|
||||
// ACTION: Settings advanced button is expanded
|
||||
@@ -4287,6 +4288,18 @@ message MetricsEvent {
|
||||
// OS: O MR
|
||||
APPLICATIONS_STORAGE_PHOTOS = 1092;
|
||||
|
||||
// ACTION: Logged when the status bar icons change.
|
||||
// OS: O MR
|
||||
STATUS_BAR_ICONS_CHANGED = 1093;
|
||||
|
||||
// FIELD: Bitfield indicating which icons are shown.
|
||||
// OS: O MR
|
||||
FIELD_STATUS_ICONS = 1094;
|
||||
|
||||
// FIELD: Number of status icons currently shown.
|
||||
// OS: O MR
|
||||
FIELD_NUM_STATUS_ICONS = 1095;
|
||||
|
||||
// Add new aosp constants above this line.
|
||||
// END OF AOSP CONSTANTS
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.app.ActivityThread;
|
||||
import android.app.StatusBarManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
@@ -957,6 +956,10 @@ public class StatusBarManagerService extends IStatusBarService.Stub {
|
||||
this, in, out, err, args, callback, resultReceiver);
|
||||
}
|
||||
|
||||
public String[] getStatusBarIcons() {
|
||||
return mContext.getResources().getStringArray(R.array.config_statusBarIcons);
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// Can be called from any thread
|
||||
// ================================================================================
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.io.PrintWriter;
|
||||
|
||||
public class StatusBarShellCommand extends ShellCommand {
|
||||
|
||||
private final IStatusBarService mInterface;
|
||||
private final StatusBarManagerService mInterface;
|
||||
|
||||
public StatusBarShellCommand(StatusBarManagerService service) {
|
||||
mInterface = service;
|
||||
@@ -54,6 +54,8 @@ public class StatusBarShellCommand extends ShellCommand {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
pw.println(String.valueOf(TileService.isQuickSettingsSupported()));
|
||||
return 0;
|
||||
case "get-status-icons":
|
||||
return runGetStatusIcons();
|
||||
default:
|
||||
return handleDefaultCommands(cmd);
|
||||
}
|
||||
@@ -94,6 +96,14 @@ public class StatusBarShellCommand extends ShellCommand {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int runGetStatusIcons() {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
for (String icon : mInterface.getStatusBarIcons()) {
|
||||
pw.println(icon);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHelp() {
|
||||
final PrintWriter pw = getOutPrintWriter();
|
||||
@@ -122,5 +132,8 @@ public class StatusBarShellCommand extends ShellCommand {
|
||||
pw.println(" check-support");
|
||||
pw.println(" Check if this device supports QS + APIs");
|
||||
pw.println("");
|
||||
pw.println(" get-status-icons");
|
||||
pw.println(" Print the list of status bar icons and the order they appear in");
|
||||
pw.println("");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user