Add logging for settings
- Log when navigating from Settings to injected tiles.
- Log when user creates a new widget shortcut
Fix: 33209678
Fix: 30137094
Test: RunSettingsRoboTests
Change-Id: I1e0f4e00709c392cde2550fafe53890836387c99
diff --git a/src/com/android/settings/CreateShortcut.java b/src/com/android/settings/CreateShortcut.java
index 726bf0a..56ab34a 100644
--- a/src/com/android/settings/CreateShortcut.java
+++ b/src/com/android/settings/CreateShortcut.java
@@ -39,7 +39,9 @@
import android.widget.ImageView;
import android.widget.ListView;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.Settings.TetherSettingsActivity;
+import com.android.settings.overlay.FeatureFactory;
import java.util.ArrayList;
import java.util.List;
@@ -56,7 +58,8 @@
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
- ListItem item = itemForPosition(position);
+ final ListItem item = itemForPosition(position);
+ logCreateShortcut(item.resolveInfo);
setResult(RESULT_OK, createResultIntent(intentForPosition(position),
item.resolveInfo, item.label));
finish();
@@ -89,6 +92,15 @@
return intent;
}
+ private void logCreateShortcut(ResolveInfo info) {
+ if (info == null || info.activityInfo == null) {
+ return;
+ }
+ FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(
+ this, MetricsProto.MetricsEvent.ACTION_SETTINGS_CREATE_SHORTCUT,
+ info.activityInfo.name);
+ }
+
private Bitmap createIcon(int resource) {
Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material);
View view = LayoutInflater.from(context).inflate(R.layout.shortcut_badge, null);
@@ -165,7 +177,7 @@
continue;
}
updates.add(new ShortcutInfo.Builder(mContext, info.getId())
- .setShortLabel(ri.loadLabel(pm)).build());
+ .setShortLabel(ri.loadLabel(pm)).build());
}
if (!updates.isEmpty()) {
sm.updateShortcuts(updates);
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 179b31b..51613c7 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -69,7 +69,6 @@
import com.android.settingslib.drawer.SettingsDrawerActivity;
import com.android.settingslib.drawer.Tile;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 98026bc..223d050 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -27,7 +27,10 @@
import android.text.TextUtils;
import android.util.Log;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsActivity;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.drawer.CategoryManager;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.drawer.ProfileSelectDialog;
@@ -49,18 +52,20 @@
protected final Context mContext;
-
+ private final MetricsFeatureProvider mMetricsFeatureProvider;
private final CategoryManager mCategoryManager;
public DashboardFeatureProviderImpl(Context context) {
mContext = context.getApplicationContext();
mCategoryManager = CategoryManager.get(context, getExtraIntentAction());
+ mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@VisibleForTesting
DashboardFeatureProviderImpl(Context context, CategoryManager categoryManager) {
mContext = context.getApplicationContext();
mCategoryManager = categoryManager;
+ mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
}
@Override
@@ -205,11 +210,26 @@
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent) {
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
if (tile.userHandle == null) {
+ logStartActivity(intent);
activity.startActivityForResult(intent, 0);
} else if (tile.userHandle.size() == 1) {
+ logStartActivity(intent);
activity.startActivityForResultAsUser(intent, 0, tile.userHandle.get(0));
} else {
ProfileSelectDialog.show(activity.getFragmentManager(), tile);
}
}
+
+ private void logStartActivity(Intent intent) {
+ if (intent == null) {
+ return;
+ }
+ final ComponentName cn = intent.getComponent();
+ if (cn == null) {
+ return;
+ }
+ mMetricsFeatureProvider.action(mContext,
+ MetricsProto.MetricsEvent.ACTION_SETTINGS_TILE_CLICK,
+ cn.flattenToString());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index 7dd66e2..af720cb 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -27,9 +27,11 @@
import android.os.UserManager;
import android.support.v7.preference.Preference;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.CategoryKey;
import com.android.settingslib.drawer.CategoryManager;
import com.android.settingslib.drawer.DashboardCategory;
@@ -68,12 +70,15 @@
private UserManager mUserManager;
@Mock
private CategoryManager mCategoryManager;
+ private FakeFeatureFactory mFeatureFactory;
private DashboardFeatureProviderImpl mImpl;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ FakeFeatureFactory.setupForTest(mActivity);
+ mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
mImpl = new DashboardFeatureProviderImpl(mActivity);
}
@@ -157,7 +162,10 @@
mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null);
-
+ verify(mFeatureFactory.metricsFeatureProvider).action(
+ any(Context.class),
+ eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_TILE_CLICK),
+ eq(tile.intent.getComponent().flattenToString()));
verify(mActivity)
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
}