diff options
| author | 2020-02-17 20:21:46 +0000 | |
|---|---|---|
| committer | 2020-02-18 20:32:54 +0000 | |
| commit | 4bf1747be70abb12a98e1063f911bfa25711d3cc (patch) | |
| tree | a9a448de8bea1e9470f7c3fd3ded450e3d970146 | |
| parent | b55d7214b0f3dad360dc6813bb709fe848647c9e (diff) | |
Add metrics for work tab in intent resolver and share sheet.
Also includes a metric for cross profile app autolaunch.
Fixes: 149696928
Test: manual
Change-Id: Ic8f9819819d9d18d8616eb974580696fcbc26c36
6 files changed, 81 insertions, 2 deletions
diff --git a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java index e8f84aacb7c9..b4a0208ccc91 100644 --- a/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/AbstractMultiProfilePagerAdapter.java @@ -20,6 +20,7 @@ import android.annotation.IntDef; import android.annotation.Nullable; import android.annotation.StringRes; import android.app.AppGlobals; +import android.app.admin.DevicePolicyEventLogger; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; @@ -27,6 +28,7 @@ import android.content.pm.IPackageManager; import android.content.pm.ResolveInfo; import android.os.UserHandle; import android.os.UserManager; +import android.stats.devicepolicy.DevicePolicyEnums; import android.view.View; import android.view.ViewGroup; import android.widget.Button; @@ -251,6 +253,8 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { abstract @Nullable ViewGroup getInactiveAdapterView(); + abstract String getMetricsCategory(); + /** * Rebuilds the tab that is currently visible to the user. * <p>Returns {@code true} if rebuild has completed. @@ -282,6 +286,10 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { UserHandle listUserHandle = activeListAdapter.getUserHandle(); if (listUserHandle == mWorkProfileUserHandle && mInjector.isQuietModeEnabled(mWorkProfileUserHandle)) { + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESOLVER_EMPTY_STATE_WORK_APPS_DISABLED) + .setStrings(getMetricsCategory()) + .write(); showEmptyState(activeListAdapter, R.drawable.ic_work_apps_off, R.string.resolver_turn_on_work_apps, @@ -294,11 +302,19 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { if (!mInjector.hasCrossProfileIntents(activeListAdapter.getIntents(), UserHandle.myUserId(), listUserHandle.getIdentifier())) { if (listUserHandle == mPersonalProfileUserHandle) { + DevicePolicyEventLogger.createEvent( + DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_PERSONAL) + .setStrings(getMetricsCategory()) + .write(); showEmptyState(activeListAdapter, R.drawable.ic_sharing_disabled, R.string.resolver_cant_share_with_personal_apps, R.string.resolver_cant_share_cross_profile_explanation); } else { + DevicePolicyEventLogger.createEvent( + DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_SHARING_TO_WORK) + .setStrings(getMetricsCategory()) + .write(); showEmptyState(activeListAdapter, R.drawable.ic_sharing_disabled, R.string.resolver_cant_share_with_work_apps, @@ -315,6 +331,12 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter { UserHandle listUserHandle = listAdapter.getUserHandle(); if (UserHandle.myUserId() == listUserHandle.getIdentifier() || !hasAppsInOtherProfile(listAdapter)) { + if (mWorkProfileUserHandle != null) { + DevicePolicyEventLogger.createEvent( + DevicePolicyEnums.RESOLVER_EMPTY_STATE_NO_APPS_RESOLVED) + .setStrings(getMetricsCategory()) + .write(); + } showEmptyState(listAdapter, R.drawable.ic_no_apps, R.string.resolver_no_apps_available, diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index dc801a996dbb..bc4c849dade0 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -2699,6 +2699,11 @@ public class ChooserActivity extends ResolverActivity implements @Override protected void resetButtonBar() {} + @Override + protected String getMetricsCategory() { + return METRICS_CATEGORY_CHOOSER; + } + /** * Adapter for all types of items and targets in ShareSheet. * Note that ranked sections like Direct Share - while appearing grid-like - are handled on the diff --git a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java index e3501422f915..d4404023c4f4 100644 --- a/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ChooserMultiProfilePagerAdapter.java @@ -165,6 +165,11 @@ public class ChooserMultiProfilePagerAdapter extends AbstractMultiProfilePagerAd return getListViewForIndex(1 - getCurrentPage()); } + @Override + String getMetricsCategory() { + return ResolverActivity.METRICS_CATEGORY_CHOOSER; + } + class ChooserProfileDescriptor extends ProfileDescriptor { private ChooserActivity.ChooserGridAdapter chooserGridAdapter; private RecyclerView recyclerView; diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 5dc8b0b2b21d..dfd1926ccc2b 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -33,6 +33,7 @@ import android.app.ActivityThread; import android.app.VoiceInteractor.PickOptionRequest; import android.app.VoiceInteractor.PickOptionRequest.Option; import android.app.VoiceInteractor.Prompt; +import android.app.admin.DevicePolicyEventLogger; import android.compat.annotation.UnsupportedAppUsage; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -60,6 +61,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.MediaStore; import android.provider.Settings; +import android.stats.devicepolicy.DevicePolicyEnums; import android.text.TextUtils; import android.util.Log; import android.util.Slog; @@ -84,6 +86,7 @@ import android.widget.Toast; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.app.AbstractMultiProfilePagerAdapter.Profile; +import com.android.internal.app.chooser.ChooserTargetInfo; import com.android.internal.app.chooser.DisplayResolveInfo; import com.android.internal.app.chooser.TargetInfo; import com.android.internal.content.PackageMonitor; @@ -99,6 +102,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; + /** * This activity is displayed when the system attempts to start an Intent for * which there is more than one matching activity, allowing the user to decide @@ -152,6 +156,8 @@ public class ResolverActivity extends Activity implements private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args"; private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; private static final String OPEN_LINKS_COMPONENT_KEY = "app_link_state"; + protected static final String METRICS_CATEGORY_RESOLVER = "intent_resolver"; + protected static final String METRICS_CATEGORY_CHOOSER = "intent_chooser"; /** * TODO(arangelov): Remove a couple of weeks after work/personal tabs are finalized. @@ -1197,12 +1203,14 @@ public class ResolverActivity extends Activity implements if (!mSafeForwardingMode) { if (cti.startAsUser(this, null, currentUserHandle)) { onActivityStarted(cti); + maybeLogCrossProfileTargetLaunch(cti, currentUserHandle); } return; } try { if (cti.startAsCaller(this, null, currentUserHandle.getIdentifier())) { onActivityStarted(cti); + maybeLogCrossProfileTargetLaunch(cti, currentUserHandle); } } catch (RuntimeException e) { String launchedFromPackage; @@ -1218,6 +1226,18 @@ public class ResolverActivity extends Activity implements } } + private void maybeLogCrossProfileTargetLaunch(TargetInfo cti, UserHandle currentUserHandle) { + if (!hasWorkProfile() || currentUserHandle == getUser()) { + return; + } + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESOLVER_CROSS_PROFILE_TARGET_OPENED) + .setBoolean(currentUserHandle == getPersonalProfileUserHandle()) + .setStrings(getMetricsCategory(), + cti instanceof ChooserTargetInfo ? "direct_share" : "other_target") + .write(); + } + public boolean startAsCallerImpl(Intent intent, Bundle options, boolean ignoreTargetSecurity, int userId) { @@ -1414,7 +1434,8 @@ public class ResolverActivity extends Activity implements * - The target app has declared it supports cross-profile communication via manifest metadata */ private boolean maybeAutolaunchIfCrossProfileSupported() { - int count = mMultiProfilePagerAdapter.getActiveListAdapter().getUnfilteredCount(); + ResolverListAdapter activeListAdapter = mMultiProfilePagerAdapter.getActiveListAdapter(); + int count = activeListAdapter.getUnfilteredCount(); if (count != 1) { return false; } @@ -1423,7 +1444,7 @@ public class ResolverActivity extends Activity implements if (inactiveListAdapter.getUnfilteredCount() != 1) { return false; } - TargetInfo activeProfileTarget = mMultiProfilePagerAdapter.getActiveListAdapter() + TargetInfo activeProfileTarget = activeListAdapter .targetInfoForPosition(0, false); TargetInfo inactiveProfileTarget = inactiveListAdapter.targetInfoForPosition(0, false); if (!Objects.equals(activeProfileTarget.getResolvedComponentName(), @@ -1438,6 +1459,11 @@ public class ResolverActivity extends Activity implements return false; } + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESOLVER_AUTOLAUNCH_CROSS_PROFILE_TARGET) + .setBoolean(activeListAdapter.getUserHandle() == getPersonalProfileUserHandle()) + .setStrings(getMetricsCategory()) + .write(); safelyStartActivity(activeProfileTarget); finish(); return true; @@ -1519,6 +1545,11 @@ public class ResolverActivity extends Activity implements viewPager.setCurrentItem(1); } setupViewVisibilities(); + DevicePolicyEventLogger + .createEvent(DevicePolicyEnums.RESOLVER_SWITCH_TABS) + .setInt(viewPager.getCurrentItem()) + .setStrings(getMetricsCategory()) + .write(); }); viewPager.setVisibility(View.VISIBLE); @@ -1686,6 +1717,10 @@ public class ResolverActivity extends Activity implements && Objects.equals(lhs.activityInfo.packageName, rhs.activityInfo.packageName); } + protected String getMetricsCategory() { + return METRICS_CATEGORY_RESOLVER; + } + @Override // ResolverListCommunicator public void onHandlePackagesChanged(ResolverListAdapter listAdapter) { if (listAdapter == mMultiProfilePagerAdapter.getActiveListAdapter()) { diff --git a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java index 96dc83a3f683..21e7fd9fcca6 100644 --- a/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java +++ b/core/java/com/android/internal/app/ResolverMultiProfilePagerAdapter.java @@ -150,6 +150,11 @@ public class ResolverMultiProfilePagerAdapter extends AbstractMultiProfilePagerA return getListViewForIndex(1 - getCurrentPage()); } + @Override + String getMetricsCategory() { + return ResolverActivity.METRICS_CATEGORY_RESOLVER; + } + class ResolverProfileDescriptor extends ProfileDescriptor { private ResolverListAdapter resolverListAdapter; final ListView listView; diff --git a/core/proto/android/stats/devicepolicy/device_policy_enums.proto b/core/proto/android/stats/devicepolicy/device_policy_enums.proto index 782b2694c453..3d8108d2a4c8 100644 --- a/core/proto/android/stats/devicepolicy/device_policy_enums.proto +++ b/core/proto/android/stats/devicepolicy/device_policy_enums.proto @@ -179,4 +179,11 @@ enum EventId { PROVISIONING_DPC_SETUP_STARTED = 152; PROVISIONING_DPC_SETUP_COMPLETED = 153; PROVISIONING_ORGANIZATION_OWNED_MANAGED_PROFILE = 154; + RESOLVER_CROSS_PROFILE_TARGET_OPENED = 155; + RESOLVER_SWITCH_TABS = 156; + RESOLVER_EMPTY_STATE_WORK_APPS_DISABLED = 157; + RESOLVER_EMPTY_STATE_NO_SHARING_TO_PERSONAL= 158; + RESOLVER_EMPTY_STATE_NO_SHARING_TO_WORK= 159; + RESOLVER_EMPTY_STATE_NO_APPS_RESOLVED= 160; + RESOLVER_AUTOLAUNCH_CROSS_PROFILE_TARGET = 161; } |