<!-- hiding for now.
<Preference
android:key="background_check"
+ android:fragment="com.android.settings.applications.BackgroundCheckSummary"
android:title="@string/background_check_pref" />
-->
<Preference
android:key="inactive_apps"
- android:title="@string/inactive_apps_title" />
+ android:title="@string/inactive_apps_title"
+ android:fragment="com.android.settings.fuelgauge.InactiveApps"/>
<SwitchPreference
android:key="force_allow_on_external"
import android.widget.ImageView;
import android.widget.TextView;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.InstalledAppDetails;
if (includeAppInfo) {
AppInfoBase.startAppInfoFragment(InstalledAppDetails.class,
R.string.application_info_label, pkgName, uid, activity,
- INSTALLED_APP_DETAILS);
+ INSTALLED_APP_DETAILS, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
} else {
activity.finish();
}
void addDashboardCategoryPreferences() {
final PreferenceScreen screen = getPreferenceScreen();
final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
- getActivity(), getPrefContext(), CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
+ getActivity(), getPrefContext(), getMetricsCategory(),
+ CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
if (tilePrefs != null) {
for (Preference preference : tilePrefs) {
screen.addPreference(preference);
writeUSBAudioOptions();
} else if (preference == mForceResizable) {
writeForceResizableOptions();
- } else if (INACTIVE_APPS_KEY.equals(preference.getKey())) {
- startInactiveAppsFragment();
- } else if (BACKGROUND_CHECK_KEY.equals(preference.getKey())) {
- startBackgroundCheckFragment();
} else if (preference == mBluetoothDisableAbsVolume) {
writeBluetoothDisableAbsVolumeOptions();
} else if (preference == mWebViewMultiprocess) {
return false;
}
- private void startInactiveAppsFragment() {
- ((SettingsActivity) getActivity()).startPreferencePanel(
- InactiveApps.class.getName(),
- null, R.string.inactive_apps_title, null, null, 0);
- }
-
- private void startBackgroundCheckFragment() {
- ((SettingsActivity) getActivity()).startPreferencePanel(
- BackgroundCheckSummary.class.getName(),
- null, R.string.background_check_title, null, null, 0);
- }
-
private boolean showKeyguardConfirmation(Resources resources, int requestCode) {
return new ChooseLockSettingsHelper(getActivity(), this).launchConfirmationActivity(
requestCode, resources.getString(R.string.oem_unlock_enable));
private void showFinalConfirmation() {
Bundle args = new Bundle();
args.putBoolean(ERASE_EXTERNAL_EXTRA, mExternalStorage.isChecked());
- ((SettingsActivity) getActivity()).startPreferencePanel(MasterClearConfirm.class.getName(),
+ ((SettingsActivity) getActivity()).startPreferencePanel(
+ this, MasterClearConfirm.class.getName(),
args, R.string.master_clear_confirm_title, null, null, 0);
}
SubscriptionInfo subscription = mSubscriptions.get(selectedIndex);
args.putInt(PhoneConstants.SUBSCRIPTION_KEY, subscription.getSubscriptionId());
}
- ((SettingsActivity) getActivity()).startPreferencePanel(ResetNetworkConfirm.class.getName(),
+ ((SettingsActivity) getActivity()).startPreferencePanel(
+ this, ResetNetworkConfirm.class.getName(),
args, R.string.reset_network_confirm_title, null, null, 0);
}
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
if (mDashboardFeatureProvider.isEnabled()) {
final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
- getActivity(), getPrefContext(), CategoryKey.CATEGORY_SECURITY);
+ getActivity(), getPrefContext(), getMetricsCategory(),
+ CategoryKey.CATEGORY_SECURITY);
int numSecurityStatusPrefs = 0;
if (tilePrefs != null && !tilePrefs.isEmpty()) {
for (Preference preference : tilePrefs) {
import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settings.backup.BackupSettingsActivity;
import com.android.settings.core.gateway.SettingsGateway;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.core.instrumentation.SharedPreferencesLogger;
import com.android.settings.dashboard.DashboardContainerFragment;
import com.android.settings.dashboard.DashboardFeatureProvider;
public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
/**
+ * The metrics category constant for logging source when a setting fragment is opened.
+ */
+ public static final String EXTRA_SOURCE_METRICS_CATEGORY = ":settings:source_metrics";
+
+ /**
* When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
* this extra can also be specified to supply a Bundle of arguments to pass
* to that fragment when it is instantiated during the initial creation
private boolean mSearchMenuItemExpanded = false;
private SearchResultsSummary mSearchResultsFragment;
private SearchFeatureProvider mSearchFeatureProvider;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
// Categories
private ArrayList<DashboardCategory> mCategories = new ArrayList<>();
@Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
- startPreferencePanel(pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
+ startPreferencePanel(caller, pref.getFragment(), pref.getExtras(), -1, pref.getTitle(),
null, 0);
return true;
}
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
mSearchFeatureProvider = factory.getSearchFeatureProvider();
+ mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
// Should happen before any call to getIntent()
getMetaData();
* @param resultRequestCode If resultTo is non-null, this is the caller's
* request code to be received with the result.
*/
- public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
- CharSequence titleText, Fragment resultTo, int resultRequestCode) {
+ public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
+ int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
String title = null;
if (titleRes < 0) {
if (titleText != null) {
}
}
Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
- titleRes, title, mIsShortcut);
+ titleRes, title, mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller));
}
/**
* @param titleText Optional text of the title of this fragment.
* @param userHandle The user for which the panel has to be started.
*/
- public void startPreferencePanelAsUser(String fragmentClass, Bundle args, int titleRes,
- CharSequence titleText, UserHandle userHandle) {
+ public void startPreferencePanelAsUser(Fragment caller, String fragmentClass,
+ Bundle args, int titleRes, CharSequence titleText, UserHandle userHandle) {
// This is a workaround.
//
// Calling startWithFragmentAsUser() without specifying FLAG_ACTIVITY_NEW_TASK to the intent
// another check here to call startPreferencePanel() instead of startWithFragmentAsUser()
// when we're calling it as the same user.
if (userHandle.getIdentifier() == UserHandle.myUserId()) {
- startPreferencePanel(fragmentClass, args, titleRes, titleText, null, 0);
+ startPreferencePanel(caller, fragmentClass, args, titleRes, titleText, null, 0);
} else {
String title = null;
if (titleRes < 0) {
title = "";
}
}
- Utils.startWithFragmentAsUser(this, fragmentClass, args,
- titleRes, title, mIsShortcut, userHandle);
+ Utils.startWithFragmentAsUser(this, fragmentClass, args, titleRes, title,
+ mIsShortcut, mMetricsFeatureProvider.getMetricsCategory(caller), userHandle);
}
}
final Activity activity = getActivity();
if (activity instanceof SettingsActivity) {
SettingsActivity sa = (SettingsActivity) activity;
- sa.startPreferencePanel(fragmentClass, extras, titleRes, null, caller, requestCode);
+ sa.startPreferencePanel(
+ caller, fragmentClass, extras, titleRes, null, caller, requestCode);
return true;
} else {
Log.w(TAG,
args.putString(UserDictionaryAddWordContents.EXTRA_SHORTCUT, editingShortcut);
args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale);
SettingsActivity sa = (SettingsActivity) getActivity();
- sa.startPreferencePanel(
+ sa.startPreferencePanel(this,
com.android.settings.inputmethod.UserDictionaryAddWordFragment.class.getName(),
args, R.string.user_dict_settings_add_dialog_title, null, null, 0);
}
/**
* Returns the default link's IP addresses, if any, taking into account IPv4 and IPv6 style
* addresses.
- * @param context the application context
* @return the formatted and newline-separated IP addresses, or null if none.
*/
public static String getDefaultIpAddresses(ConnectivityManager cm) {
* @param titleResId resource id for the String to display for the title of this set
* of preferences.
* @param title String to display for the title of this set of preferences.
+ * @param metricsCategory The current metricsCategory for logging source when fragment starts
*/
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, int titleResId,
- CharSequence title) {
+ CharSequence title, int metricsCategory) {
startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
- null /* titleResPackageName */, titleResId, title, false /* not a shortcut */);
+ null /* titleResPackageName */, titleResId, title, false /* not a shortcut */,
+ metricsCategory);
}
/**
* @param titleResId resource id for the String to display for the title of this set
* of preferences.
* @param title String to display for the title of this set of preferences.
+ * @param metricsCategory The current metricsCategory for logging source when fragment starts
*/
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
- CharSequence title) {
+ CharSequence title, int metricsCategory) {
startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
- titleResPackageName, titleResId, title, false /* not a shortcut */);
+ titleResPackageName, titleResId, title, false /* not a shortcut */,
+ metricsCategory);
}
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, int titleResId,
- CharSequence title, boolean isShortcut) {
+ CharSequence title, boolean isShortcut, int metricsCategory) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
- null /* titleResPackageName */, titleResId, title, isShortcut);
+ null /* titleResPackageName */, titleResId, title, isShortcut, metricsCategory);
if (resultTo == null) {
context.startActivity(intent);
} else {
public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, String titleResPackageName, int titleResId,
- CharSequence title, boolean isShortcut) {
+ CharSequence title, boolean isShortcut, int metricsCategory) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResPackageName,
- titleResId, title, isShortcut);
+ titleResId, title, isShortcut, metricsCategory);
if (resultTo == null) {
context.startActivity(intent);
} else {
}
public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args,
- int titleResId, CharSequence title, boolean isShortcut,
- UserHandle userHandle) {
- // workaround to avoid crash in b/17523189
- if (userHandle.getIdentifier() == UserHandle.myUserId()) {
- startWithFragment(context, fragmentName, args, null, 0, titleResId, title, isShortcut);
- } else {
- Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
- null /* titleResPackageName */, titleResId, title, isShortcut);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- context.startActivityAsUser(intent, userHandle);
- }
- }
-
- public static void startWithFragmentAsUser(Context context, String fragmentName, Bundle args,
- String titleResPackageName, int titleResId, CharSequence title, boolean isShortcut,
+ int titleResId, CharSequence title, boolean isShortcut, int metricsCategory,
UserHandle userHandle) {
// workaround to avoid crash in b/17523189
if (userHandle.getIdentifier() == UserHandle.myUserId()) {
- startWithFragment(context, fragmentName, args, null, 0, titleResPackageName, titleResId,
- title, isShortcut);
+ startWithFragment(context, fragmentName, args, null, 0, titleResId, title, isShortcut,
+ metricsCategory);
} else {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args,
- titleResPackageName, titleResId, title, isShortcut);
+ null /* titleResPackageName */, titleResId, title, isShortcut, metricsCategory);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivityAsUser(intent, userHandle);
* @param titleResId Optional title resource id to show for this item.
* @param title Optional title to show for this item.
* @param isShortcut tell if this is a Launcher Shortcut or not
+ * @param sourceMetricsCategory The context (source) from which an action is performed
* @return Returns an Intent that can be launched to display the given
* fragment.
*/
public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
Bundle args, String titleResPackageName, int titleResId, CharSequence title,
- boolean isShortcut) {
+ boolean isShortcut, int sourceMetricsCategory) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(context, SubSettings.class);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
+ intent.putExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY, sourceMetricsCategory);
return intent;
}
return null;
}
- public static boolean isPackageEnabled(Context context, String packageName) {
- try {
- return context.getPackageManager().getApplicationInfo(packageName, 0).enabled;
- } catch (NameNotFoundException e) {
- // Thrown by PackageManager.getApplicationInfo if the package does not exist
- }
- return false;
- }
-
public static boolean isPackageDirectBootAware(Context context, String packageName) {
try {
final ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
}
@Override
- public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
- CharSequence titleText, Fragment resultTo, int resultRequestCode) {
+ public void startPreferencePanel(Fragment caller, String fragmentClass, Bundle args,
+ int titleRes, CharSequence titleText, Fragment resultTo, int resultRequestCode) {
// Set the title.
if (!TextUtils.isEmpty(titleText)) {
setTitle(titleText);
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnPause;
import com.android.settings.core.lifecycle.events.OnResume;
private int mAccountProfileOrder = ORDER_ACCOUNT_PROFILES;
private AccountRestrictionHelper mHelper;
private DashboardFeatureProvider mDashboardFeatureProvider;
+ private MetricsFeatureProvider mMetricsFeatureProvider;
/**
* Holds data related to the accounts belonging to one profile.
if (mAuthorities != null) {
mAuthoritiesCount = mAuthorities.length;
}
- mDashboardFeatureProvider =
- FeatureFactory.getFactory(mContext).getDashboardFeatureProvider(mContext);
+ final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
+ mDashboardFeatureProvider = featureFactory.getDashboardFeatureProvider(mContext);
+ mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
mIAEnabled = mDashboardFeatureProvider.isEnabled();
mHelper = helper;
}
if (preference == profileData.managedProfilePreference) {
Bundle arguments = new Bundle();
arguments.putParcelable(Intent.EXTRA_USER, profileData.userInfo.getUserHandle());
- ((SettingsActivity) mParent.getActivity()).startPreferencePanel(
+ ((SettingsActivity) mParent.getActivity()).startPreferencePanel(mParent,
ManagedProfileSettings.class.getName(), arguments,
R.string.managed_profile_settings_title, null, null, 0);
return true;
UserHandle userHandle) {
final String[] accountTypes = helper.getEnabledAccountTypes();
final ArrayList<AccountTypePreference> accountTypePreferences =
- new ArrayList<AccountTypePreference>(accountTypes.length);
+ new ArrayList<>(accountTypes.length);
for (int i = 0; i < accountTypes.length; i++) {
final String accountType = accountTypes[i];
titleResId);
fragmentArguments.putParcelable(EXTRA_USER, userHandle);
accountTypePreferences.add(new AccountTypePreference(
- prefContext, account.name, titleResPackageName, titleResId, label,
+ prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent),
+ account.name, titleResPackageName, titleResId, label,
AccountDetailDashboardFragment.class.getName(), fragmentArguments, icon));
}
} else if (skipToAccount) {
fragmentArguments.putParcelable(EXTRA_USER, userHandle);
accountTypePreferences.add(new AccountTypePreference(
- prefContext, label, titleResPackageName,
- titleResId, AccountSyncSettings.class.getName(), fragmentArguments, icon));
+ prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent),
+ label, titleResPackageName, titleResId, AccountSyncSettings.class.getName(),
+ fragmentArguments, icon));
} else {
final Bundle fragmentArguments = new Bundle();
fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
fragmentArguments.putParcelable(EXTRA_USER, userHandle);
accountTypePreferences.add(new AccountTypePreference(
-
- prefContext, label, titleResPackageName,
- titleResId, ManageAccountsSettings.class.getName(), fragmentArguments, icon));
+ prefContext, mMetricsFeatureProvider.getMetricsCategory(mParent), label,
+ titleResPackageName, titleResId, ManageAccountsSettings.class.getName(),
+ fragmentArguments, icon));
}
helper.preloadDrawableForType(mContext, accountType);
}
import android.os.UserHandle;
import android.support.v7.preference.Preference;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
args.putParcelable(AccountSyncSettings.ACCOUNT_KEY, mAccount);
args.putParcelable(EXTRA_USER, mUserHandle);
Utils.startWithFragment(mContext, AccountSyncSettings.class.getName(), args, null, 0, -1,
- mAccount.name);
+ mAccount.name, MetricsProto.MetricsEvent.ACCOUNT);
return true;
}
*/
private final Bundle mFragmentArguments;
- public AccountTypePreference(Context context, CharSequence title, String titleResPackageName,
- int titleResId, String fragment, Bundle fragmentArguments, Drawable icon) {
- this(context, title, titleResPackageName, titleResId, null, fragment, fragmentArguments,
- icon);
+ private final int mMetricsCategory;
+
+ public AccountTypePreference(Context context, int metricsCategory, CharSequence title,
+ String titleResPackageName, int titleResId, String fragment, Bundle fragmentArguments,
+ Drawable icon) {
+ this(context, metricsCategory, title, titleResPackageName, titleResId, null, fragment,
+ fragmentArguments, icon);
}
- public AccountTypePreference(Context context, CharSequence title, String titleResPackageName,
- int titleResId, CharSequence summary, String fragment, Bundle fragmentArguments,
- Drawable icon) {
+ public AccountTypePreference(Context context, int metricsCategory, CharSequence title,
+ String titleResPackageName, int titleResId, CharSequence summary, String fragment,
+ Bundle fragmentArguments, Drawable icon) {
super(context);
mTitle = title;
mTitleResPackageName = titleResPackageName;
mSummary = summary;
mFragment = fragment;
mFragmentArguments = fragmentArguments;
+ mMetricsCategory = metricsCategory;
setWidgetLayoutResource(R.layout.account_type_preference);
setTitle(title);
}
Utils.startWithFragment(getContext(), mFragment, mFragmentArguments,
null /* resultTo */, 0 /* resultRequestCode */, mTitleResPackageName,
- mTitleResId, null /* title */);
+ mTitleResId, null /* title */, mMetricsCategory);
return true;
}
return false;
@Override
public boolean onPreferenceClick(Preference preference) {
- ((SettingsActivity) mFragment.getActivity()).startPreferencePanel(
+ ((SettingsActivity) mFragment.getActivity()).startPreferencePanel(mFragment,
mClass, null, mTitleRes, null, null, 0);
// Hack: announce that the Google account preferences page is launching the location
// settings
Bundle args = new Bundle();
args.putParcelable(AccountSyncSettings.ACCOUNT_KEY, acctPref.getAccount());
args.putParcelable(EXTRA_USER, mUserHandle);
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
AccountSyncSettings.class.getCanonicalName(), args,
R.string.account_sync_settings_title, acctPref.getAccount().name,
this, REQUEST_SHOW_SYNC_SETTINGS);
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.instantapps.InstantAppDetails;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.applications.ApplicationsState;
import java.lang.annotation.Retention;
private final Context mContext;
private final Fragment mFragment;
+ private final int mMetricsCategory;
private final View mAppHeader;
private Drawable mIcon;
public AppHeaderController(Context context, Fragment fragment, View appHeader) {
mContext = context;
mFragment = fragment;
+ mMetricsCategory = FeatureFactory.getFactory(context).getMetricsFeatureProvider()
+ .getMetricsCategory(fragment);
if (appHeader != null) {
mAppHeader = appHeader;
} else {
button.setImageResource(com.android.settings.R.drawable.ic_info);
button.setOnClickListener(v -> AppInfoBase.startAppInfoFragment(
InstalledAppDetails.class, R.string.application_info_label,
- mPackageName, mUid, mFragment, 0));
+ mPackageName, mUid, mFragment, 0 /* request */, mMetricsCategory));
button.setVisibility(View.VISIBLE);
}
return;
}
public static void startAppInfoFragment(Class<?> fragment, int titleRes,
- String pkg, int uid, Fragment source, int request) {
- startAppInfoFragment(fragment, titleRes, pkg, uid, source.getActivity(), request);
+ String pkg, int uid, Fragment source, int request, int sourceMetricsCategory) {
+ startAppInfoFragment(fragment, titleRes, pkg, uid, source.getActivity(), request,
+ sourceMetricsCategory);
}
public static void startAppInfoFragment(Class<?> fragment, int titleRes,
- String pkg, int uid, Activity source, int request) {
+ String pkg, int uid, Activity source, int request, int sourceMetricsCategory) {
Bundle args = new Bundle();
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkg);
args.putInt(AppInfoBase.ARG_PACKAGE_UID, uid);
Intent intent = Utils.onBuildStartFragmentIntent(source, fragment.getName(),
- args, null, titleRes, null, false);
+ args, null, titleRes, null, false, sourceMetricsCategory);
source.startActivityForResultAsUser(intent, request,
new UserHandle(UserHandle.getUserId(uid)));
}
args.putString(AppOpsDetails.ARG_PACKAGE_NAME, mCurrentPkgName);
SettingsActivity sa = (SettingsActivity) getActivity();
- sa.startPreferencePanel(AppOpsDetails.class.getName(), args,
+ sa.startPreferencePanel(this, AppOpsDetails.class.getName(), args,
R.string.app_ops_settings, null, this, RESULT_APP_DETAILS);
}
-
+
@Override public void onListItemClick(ListView l, View v, int position, long id) {
AppOpEntry entry = mAdapter.getItem(position);
if (entry != null) {
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.ActivityInfo;
import android.content.pm.ComponentInfo;
-import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
import android.content.pm.UserInfo;
import android.os.RemoteException;
import android.os.UserHandle;
private void convert() {
SettingsActivity sa = (SettingsActivity) getActivity();
- sa.startPreferencePanel(ConfirmConvertToFbe.class.getName(), null,
+ sa.startPreferencePanel(this, ConfirmConvertToFbe.class.getName(), null,
R.string.convert_to_file_encryption, null, null, 0);
}
args.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, true);
SettingsActivity sa = (SettingsActivity) caller.getActivity();
- sa.startPreferencePanel(fragment.getName(), args, -1, title, caller, SUB_INFO_FRAGMENT);
+ sa.startPreferencePanel(caller, fragment.getName(), args, -1, title, caller,
+ SUB_INFO_FRAGMENT);
}
/*
startAppInfoFragment(AppDataUsage.class, getString(R.string.app_data_usage));
} else if (preference == mBatteryPreference) {
BatteryEntry entry = new BatteryEntry(getActivity(), null, mUserManager, mSipper);
- PowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(),
+ PowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(), this,
mBatteryHelper, BatteryStats.STATS_SINCE_CHARGED, entry, true, false);
} else {
return false;
package com.android.settings.applications;
import android.app.Activity;
-import android.app.usage.StorageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.UserManager;
import android.preference.PreferenceFrameLayout;
import android.text.TextUtils;
-import android.text.format.Formatter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
private void startAppInfoFragment(Class<?> fragment, int titleRes) {
AppInfoBase.startAppInfoFragment(fragment, titleRes, mCurrentPkgName, mCurrentUid, this,
- INSTALLED_APP_DETAILS);
+ INSTALLED_APP_DETAILS, getMetricsCategory());
}
@Override
return true;
case R.id.advanced:
if (mListType == LIST_TYPE_NOTIFICATION) {
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
ConfigureNotificationSettings.class.getName(), null,
R.string.configure_notification_settings, null, this, ADVANCED_SETTINGS);
} else {
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
AdvancedAppSettings.class.getName(), null, R.string.configure_apps,
null, this, ADVANCED_SETTINGS);
}
ApplicationsState.AppEntry entry = ((DomainAppPreference) preference).mEntry;
AppInfoBase.startAppInfoFragment(AppLaunchSettings.class, R.string.auto_launch_label,
entry.info.packageName, entry.info.uid, this,
- INSTALLED_APP_DETAILS);
+ INSTALLED_APP_DETAILS, getMetricsCategory());
return true;
}
return false;
memInfo.usedWeight * memInfo.weightToRam);
args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, memInfo.totalScale);
args.putBoolean(AppHeader.EXTRA_HIDE_INFO_BUTTON, !includeAppInfo);
- activity.startPreferencePanel(ProcessStatsDetail.class.getName(), args,
+ activity.startPreferencePanel(null, ProcessStatsDetail.class.getName(), args,
R.string.memory_usage, null, null, 0);
}
}
args.putBoolean(RunningServiceDetails.KEY_BACKGROUND, mAdapter.mShowBackground);
SettingsActivity sa = (SettingsActivity) mOwner.getActivity();
- sa.startPreferencePanel(RunningServiceDetails.class.getName(), args,
+ sa.startPreferencePanel(null, RunningServiceDetails.class.getName(), args,
R.string.runningservicedetails_settings_title, null, null, 0);
}
}
import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.Preference;
+
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
Bundle bundle = new Bundle();
bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, mPrefKey);
Utils.startWithFragment(getContext(), mTarget.getName(), bundle, null, 0,
- mTitle, null);
+ mTitle, null, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
}
}
public void onClick() {
final SettingsActivity activity =
(SettingsActivity) BluetoothSettings.this.getActivity();
- activity.startPreferencePanel(ScanningSettings.class.getName(), null,
+ activity.startPreferencePanel(BluetoothSettings.this,
+ ScanningSettings.class.getName(), null,
R.string.location_scanning_screen_title, null, null, 0);
}
});
import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
import com.android.settings.core.lifecycle.ObservablePreferenceFragment;
import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.widget.PreferenceDividerDecoration;
import com.android.settings.survey.SurveyMixin;
+import com.android.settings.widget.PreferenceDividerDecoration;
/**
* Instrumented fragment that logs visibility state.
private final PreferenceDividerDecoration mDividerDecoration =
new PreferenceDividerDecoration();
+ private final VisibilityLoggerMixin mVisibilityLoggerMixin;
+
public InstrumentedPreferenceFragment() {
// Mixin that logs visibility change for activity.
- getLifecycle().addObserver(new VisibilityLoggerMixin(getMetricsCategory()));
+ mVisibilityLoggerMixin = new VisibilityLoggerMixin(getMetricsCategory());
+ getLifecycle().addObserver(mVisibilityLoggerMixin);
getLifecycle().addObserver(new SurveyMixin(this, getClass().getSimpleName()));
}
}
@Override
+ public void onResume() {
+ mVisibilityLoggerMixin.setSourceMetricsCategory(getActivity());
+ super.onResume();
+ }
+
+ @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
*/
public class EventLogWriter implements LogWriter {
- public void visible(Context context, int category) {
- MetricsLogger.visible(context, category);
+ public void visible(Context context, int source, int category) {
+ final LogMaker logMaker = new LogMaker(category)
+ .setType(MetricsProto.MetricsEvent.TYPE_OPEN)
+ .addTaggedData(MetricsProto.MetricsEvent.FIELD_CONTEXT, source);
+ MetricsLogger.action(logMaker);
}
public void hidden(Context context, int category) {
/**
* Logs a visibility event when view becomes visible.
*/
- void visible(Context context, int category);
+ void visible(Context context, int source, int category);
/**
* Logs a visibility event when view becomes hidden.
package com.android.settings.core.instrumentation;
import android.content.Context;
-import android.metrics.LogMaker;
+
+import com.android.internal.logging.nano.MetricsProto;
import java.util.ArrayList;
import java.util.List;
mLoggerWriters.add(new SettingSuggestionsLogWriter());
}
- public void visible(Context context, int category) {
+ public void visible(Context context, int source, int category) {
for (LogWriter writer : mLoggerWriters) {
- writer.visible(context, category);
+ writer.visible(context, source, category);
}
}
writer.histogram(context, name, bucket);
}
}
+
+ public int getMetricsCategory(Object object) {
+ if (object == null || !(object instanceof Instrumentable)) {
+ return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
+ }
+ return ((Instrumentable) object).getMetricsCategory();
+ }
}
private EventStore mEventStore;
@Override
- public void visible(Context context, int category) {
+ public void visible(Context context, int source, int category) {
}
@Override
package com.android.settings.core.instrumentation;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.SettingsActivity;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.core.lifecycle.events.OnAttach;
import com.android.settings.core.lifecycle.events.OnPause;
*/
public class VisibilityLoggerMixin implements LifecycleObserver, OnResume, OnPause, OnAttach {
+ private static final String TAG = "VisibilityLoggerMixin";
+
private final int mMetricsCategory;
private MetricsFeatureProvider mMetricsFeature;
+ private int mSourceMetricsCategory = MetricsProto.MetricsEvent.VIEW_UNKNOWN;
public VisibilityLoggerMixin(int metricsCategory) {
// MetricsFeature will be set during onAttach.
@Override
public void onResume() {
if (mMetricsFeature != null && mMetricsCategory != METRICS_CATEGORY_UNKNOWN) {
- mMetricsFeature.visible(null /* context */, mMetricsCategory);
+ mMetricsFeature.visible(null /* context */, mSourceMetricsCategory, mMetricsCategory);
}
}
mMetricsFeature.hidden(null /* context */, mMetricsCategory);
}
}
+
+ /**
+ * Sets source metrics category for this logger. Source is the caller that opened this UI.
+ */
+ public void setSourceMetricsCategory(Activity activity) {
+ if (mSourceMetricsCategory != MetricsProto.MetricsEvent.VIEW_UNKNOWN || activity == null) {
+ return;
+ }
+ final Intent intent = activity.getIntent();
+ if (intent == null) {
+ return;
+ }
+ mSourceMetricsCategory = intent.getIntExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY,
+ MetricsProto.MetricsEvent.VIEW_UNKNOWN);
+ }
}
package com.android.settings.dashboard;
import android.app.Activity;
+import android.app.Fragment;
import android.content.Context;
import android.support.v7.preference.Preference;
*
* @param activity Activity hosting the preference
* @param context UI context to inflate preference
+ * @param sourceMetricsCategory The context (source) from which an action is performed
* @param key Value from CategoryKey
* @deprecated Pages implementing {@code DashboardFragment} should use
* {@link #getTilesForCategory(String)} instead. Using this method will not get the benefit
* of auto-ordering, progressive disclosure, auto-refreshing summary text etc.
*/
@Deprecated
- List<Preference> getPreferencesForCategory(Activity activity, Context context, String key);
+ List<Preference> getPreferencesForCategory(Activity activity, Context context,
+ int sourceMetricsCategory, String key);
/**
* Get all tiles, grouped by category.
List<DashboardCategory> getAllCategories();
/**
- * Returns a priority group for tile. priority level is grouped into hundreds. tiles with
- * priority 100 - 199 belongs to priority level 100, tiles with priority 200 - 299 is in
- * group 200, and so on.
- */
- int getPriorityGroup(Preference preference);
-
- /**
* Returns an unique string key for the tile.
*/
String getDashboardKeyForTile(Tile tile);
* Binds preference to data provided by tile.
*
* @param activity If tile contains intent to launch, it will be launched from this activity
+ * @param sourceMetricsCategory The context (source) from which an action is performed
* @param pref The preference to bind data
* @param tile The binding data
* @param key They key for preference. If null, we will generate one from tile data
* @param baseOrder The order offset value. When binding, pref's order is determined by
* both this value and tile's own priority.
*/
- void bindPreferenceToTile(Activity activity, Preference pref, Tile tile, String key,
- int baseOrder);
+ void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
+ Tile tile, String key, int baseOrder);
/**
* Returns a {@link ProgressiveDisclosureMixin} for specified fragment.
@Override
public List<Preference> getPreferencesForCategory(Activity activity, Context context,
- String key) {
+ int sourceMetricsCategory, String key) {
if (!isEnabled()) {
return null;
}
final List<Preference> preferences = new ArrayList<>();
for (Tile tile : tiles) {
final Preference pref = new Preference(context);
- bindPreferenceToTile(activity, pref, tile, null /* key */,
+ bindPreferenceToTile(activity, sourceMetricsCategory, pref, tile, null /* key */,
Preference.DEFAULT_ORDER /* baseOrder */);
preferences.add(pref);
}
}
@Override
- public int getPriorityGroup(Preference preference) {
- return preference.getOrder() / 100;
- }
-
- @Override
public String getDashboardKeyForTile(Tile tile) {
if (tile == null || tile.intent == null) {
return null;
}
@Override
- public void bindPreferenceToTile(Activity activity, Preference pref, Tile tile, String key,
- int baseOrder) {
+ public void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
+ Tile tile, String key, int baseOrder) {
pref.setTitle(tile.title);
if (!TextUtils.isEmpty(key)) {
pref.setKey(key);
pref.setFragment(clsName);
} else if (tile.intent != null) {
final Intent intent = new Intent(tile.intent);
+ intent.putExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY, sourceMetricsCategory);
if (action != null) {
intent.setAction(action);
}
// Have the key already, will rebind.
final Preference preference = mProgressiveDisclosureMixin.findPreference(
screen, key);
- mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), preference, tile, key,
- mPlaceholderPreferenceController.getOrder());
+ mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
+ preference, tile, key, mPlaceholderPreferenceController.getOrder());
} else {
// Don't have this key, add it.
final Preference pref = new Preference(getPrefContext());
- mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), pref, tile, key,
- mPlaceholderPreferenceController.getOrder());
+ mDashboardFeatureProvider.bindPreferenceToTile(getActivity(), getMetricsCategory(),
+ pref, tile, key, mPlaceholderPreferenceController.getOrder());
mProgressiveDisclosureMixin.addPreference(screen, pref);
mDashboardTilePrefKeys.add(key);
}
((SettingsDrawerActivity) getActivity()).addCategoryListener(this);
mSummaryLoader.setListening(true);
+ final int metricsCategory = getMetricsCategory();
for (Condition c : mConditionManager.getConditions()) {
if (c.shouldShow()) {
- mMetricsFeatureProvider.visible(getContext(), c.getMetricsConstant());
+ mMetricsFeatureProvider.visible(getContext(), metricsCategory,
+ c.getMetricsConstant());
}
}
if (DEBUG_TIMING) {
Bundle args = new Bundle();
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
- Utils.startWithFragment(sa, className, args, null, 0, -1, screenTitle);
+ Utils.startWithFragment(sa, className, args, null, 0, -1, screenTitle,
+ getMetricsCategory());
} else {
final Intent intent = new Intent(action);
@Override
public void onPrimaryClick() {
Utils.startWithFragment(mManager.getContext(), BatterySaverSettings.class.getName(), null,
- null, 0, R.string.battery_saver, null);
+ null, 0, R.string.battery_saver, null, MetricsEvent.DASHBOARD_SUMMARY);
}
@Override
@Override
public void onPrimaryClick() {
Utils.startWithFragment(mManager.getContext(), TetherSettings.class.getName(), null, null,
- 0, R.string.tether_settings_title_all, null);
+ 0, R.string.tether_settings_title_all, null, MetricsEvent.DASHBOARD_SUMMARY);
}
@Override
@Override
public void onPrimaryClick() {
Utils.startWithFragment(mManager.getContext(), NightDisplaySettings.class.getName(), null,
- null, 0, R.string.night_display_title, null);
+ null, 0, R.string.night_display_title, null, MetricsEvent.DASHBOARD_SUMMARY);
}
@Override
import android.os.RemoteException;
import android.support.v7.preference.Preference;
import android.util.AttributeSet;
+
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.datausage.CellDataPreference.DataStateListener;
Bundle args = new Bundle();
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
return Utils.onBuildStartFragmentIntent(getContext(), BillingCycleSettings.class.getName(),
- args, null, 0, getTitle(), false);
+ args, null, 0, getTitle(), false, MetricsProto.MetricsEvent.VIEW_UNKNOWN);
}
private final DataStateListener mListener = new DataStateListener() {
import android.telephony.SubscriptionManager;
import android.text.format.Formatter;
import android.util.AttributeSet;
+
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.Utils;
import com.android.settingslib.net.DataUsageController;
import com.android.settings.R;
args.putParcelable(DataUsageList.EXTRA_NETWORK_TEMPLATE, mTemplate);
args.putInt(DataUsageList.EXTRA_SUB_ID, mSubId);
return Utils.onBuildStartFragmentIntent(getContext(), DataUsageList.class.getName(), args,
- getContext().getPackageName(), 0, getTitle(), false);
+ getContext().getPackageName(), 0, getTitle(), false,
+ MetricsProto.MetricsEvent.VIEW_UNKNOWN);
}
}
args.putString(ManageApplications.EXTRA_VOLUME_NAME, mVolume.getDescription());
intent = Utils.onBuildStartFragmentIntent(getActivity(),
ManageApplications.class.getName(), args, null, R.string.apps_storage, null,
- false);
+ false, getMetricsCategory());
} break;
case R.string.storage_detail_images: {
final Bundle args = new Bundle();
args.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
Intent intent = Utils.onBuildStartFragmentIntent(getActivity(),
- StorageDashboardFragment.class.getName(), args, null, R.string.apps_storage, null,
- false);
+ StorageDashboardFragment.class.getName(), args, null, R.string.apps_storage,
+ null, false, getMetricsCategory());
intent.putExtra(SettingsDrawerActivity.EXTRA_SHOW_MENU, true);
getActivity().startActivity(intent);
finish();
import com.android.settings.applications.ManageApplications;
import com.android.settings.applications.PackageManagerWrapperImpl;
import com.android.settings.core.PreferenceController;
+import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.deviceinfo.StorageMeasurement;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
static final String FILES_KEY = "pref_files";
private final Fragment mFragment;
+ private final MetricsFeatureProvider mMetricsFeatureProvider;
private final StorageVolumeProvider mSvp;
private VolumeInfo mVolume;
private final int mUserId;
mFragment = hostFragment;
mVolume = volume;
mSvp = svp;
-
+ mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
UserManager um = mContext.getSystemService(UserManager.class);
mUserId = um.getUserHandle();
}
args.putInt(ManageApplications.EXTRA_STORAGE_TYPE, ManageApplications.STORAGE_TYPE_MUSIC);
return Utils.onBuildStartFragmentIntent(mContext,
ManageApplications.class.getName(), args, null, R.string.audio_storage_title, null,
- false);
+ false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
}
private Intent getAppsIntent() {
args.putString(ManageApplications.EXTRA_VOLUME_NAME, mVolume.getDescription());
return Utils.onBuildStartFragmentIntent(mContext,
ManageApplications.class.getName(), args, null, R.string.apps_storage, null,
- false);
+ false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
}
private Intent getGamesIntent() {
Settings.GamesStorageActivity.class.getName());
return Utils.onBuildStartFragmentIntent(mContext,
ManageApplications.class.getName(), args, null, R.string.game_storage_settings,
- null, false);
+ null, false, mMetricsFeatureProvider.getMetricsCategory(mFragment));
}
private Intent getFilesIntent() {
import android.os.Process;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
+import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceCategory;
R.string.battery_desc_camera,
};
- public static void startBatteryDetailPage(
- SettingsActivity caller, BatteryStatsHelper helper, int statsType, BatteryEntry entry,
- boolean showLocationButton, boolean includeAppInfo) {
+ public static void startBatteryDetailPage(SettingsActivity caller,
+ PreferenceFragment fragment, BatteryStatsHelper helper, int statsType,
+ BatteryEntry entry, boolean showLocationButton, boolean includeAppInfo) {
// Initialize mStats if necessary.
helper.getStats();
args.putIntArray(PowerUsageDetail.EXTRA_DETAIL_TYPES, types);
args.putDoubleArray(PowerUsageDetail.EXTRA_DETAIL_VALUES, values);
- caller.startPreferencePanelAsUser(PowerUsageDetail.class.getName(), args,
+ caller.startPreferencePanelAsUser(fragment, PowerUsageDetail.class.getName(), args,
R.string.details_title, null, new UserHandle(userId));
}
args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mPackages[0]);
SettingsActivity sa = (SettingsActivity) getActivity();
- sa.startPreferencePanel(InstalledAppDetails.class.getName(), args,
+ sa.startPreferencePanel(this, InstalledAppDetails.class.getName(), args,
R.string.application_info_label, null, null, 0);
}
SettingsActivity sa = (SettingsActivity)getActivity();
switch (action) {
case ACTION_DISPLAY_SETTINGS:
- sa.startPreferencePanel(DisplaySettings.class.getName(), null,
+ sa.startPreferencePanel(this, DisplaySettings.class.getName(), null,
R.string.display_settings_title, null, null, 0);
break;
case ACTION_WIFI_SETTINGS:
- sa.startPreferencePanel(WifiSettings.class.getName(), null,
+ sa.startPreferencePanel(this, WifiSettings.class.getName(), null,
R.string.wifi_settings, null, null, 0);
break;
case ACTION_BLUETOOTH_SETTINGS:
- sa.startPreferencePanel(BluetoothSettings.class.getName(), null,
+ sa.startPreferencePanel(this, BluetoothSettings.class.getName(), null,
R.string.bluetooth_settings, null, null, 0);
break;
case ACTION_WIRELESS_SETTINGS:
- sa.startPreferencePanel(WirelessSettings.class.getName(), null,
+ sa.startPreferencePanel(this, WirelessSettings.class.getName(), null,
R.string.radio_controls_title, null, null, 0);
break;
case ACTION_APP_DETAILS:
startApplicationDetailsActivity();
break;
case ACTION_LOCATION_SETTINGS:
- sa.startPreferencePanel(LocationSettings.class.getName(), null,
+ sa.startPreferencePanel(this, LocationSettings.class.getName(), null,
R.string.location_settings_title, null, null, 0);
break;
case ACTION_FORCE_STOP:
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
-import android.widget.Toast;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.os.BatterySipper;
import com.android.internal.os.BatterySipper.DrainType;
}
PowerGaugePreference pgp = (PowerGaugePreference) preference;
BatteryEntry entry = pgp.getInfo();
- PowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(), mStatsHelper,
- mStatsType, entry, true, true);
+ PowerUsageDetail.startBatteryDetailPage((SettingsActivity) getActivity(), this,
+ mStatsHelper, mStatsType, entry, true, true);
return super.onPreferenceTreeClick(preference);
}
Bundle args = new Bundle();
args.putString(ManageApplications.EXTRA_CLASSNAME,
HighPowerApplicationsActivity.class.getName());
- sa.startPreferencePanel(ManageApplications.class.getName(), args,
+ sa.startPreferencePanel(this, ManageApplications.class.getName(), args,
R.string.high_power_apps, null, null, 0);
return true;
case MENU_ADDITIONAL_BATTERY_INFO:
if (featureProvider.isAdvancedUiEnabled()) {
Utils.startWithFragment(getContext(), PowerUsageAdvanced.class.getName(), null,
- null, 0, R.string.advanced_battery_title, null);
+ null, 0, R.string.advanced_battery_title, null, getMetricsCategory());
} else {
mStatsHelper.storeStatsHistoryInFile(BatteryHistoryDetail.BATTERY_HISTORY_FILE);
Bundle args = new Bundle(2);
args.putParcelable(BatteryHistoryDetail.EXTRA_BROADCAST,
mStatsHelper.getBatteryBroadcast());
Utils.startWithFragment(getContext(), BatteryHistoryDetail.class.getName(), args,
- null, 0, R.string.history_details_title, null);
+ null, 0, R.string.history_details_title, null, getMetricsCategory());
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
activity.startPreferencePanel(
+ LocationSettings.this,
LocationMode.class.getName(), null,
R.string.location_mode_screen_title, null, LocationSettings.this,
0);
switch (item.getItemId()) {
case MENU_SCANNING:
activity.startPreferencePanel(
+ this,
ScanningSettings.class.getName(), null,
R.string.location_scanning_screen_title, null, LocationSettings.this,
0);
Bundle args = new Bundle();
args.putString(InstalledAppDetails.ARG_PACKAGE_NAME, mPackage);
((SettingsActivity) getActivity()).startPreferencePanelAsUser(
+ LocationSettings.this,
InstalledAppDetails.class.getName(), args,
R.string.application_info_label, null, mUserHandle);
return true;
import android.view.Menu;
import android.view.MenuItem;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.ResetNetwork;
import com.android.settings.Utils;
if (item != null) {
item.setOnMenuItemClickListener(target -> {
Utils.startWithFragment(mContext, ResetNetwork.class.getName(), null, null,
- 0, R.string.reset_network_title, null);
+ 0, R.string.reset_network_title, null,
+ MetricsProto.MetricsEvent.SETTINGS_NETWORK_CATEGORY);
return true;
});
}
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
ChannelNotificationSettings.class.getName(),
- channelArgs, null, 0, null, false);
+ channelArgs, null, 0, null, false, getMetricsCategory());
channelPref.setIntent(channelIntent);
channelPref.setOnPreferenceChangeListener(
import android.text.TextUtils;
import android.util.Log;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsActivity;
import com.android.settings.Utils;
import com.android.settings.dashboard.SiteMapManager;
final Bundle args = new Bundle();
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
final Intent intent = Utils.onBuildStartFragmentIntent(mContext,
- className, args, null, 0, screenTitle, false);
+ className, args, null, 0, screenTitle, false,
+ MetricsProto.MetricsEvent.DASHBOARD_SEARCH_RESULTS);
payload = new IntentPayload(intent);
} else {
final Intent intent = new Intent(action);
if (userId == UserPreference.USERID_GUEST_DEFAULTS) {
Bundle extras = new Bundle();
extras.putBoolean(UserDetailsSettings.EXTRA_USER_GUEST, true);
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
UserDetailsSettings.class.getName(),
extras, R.string.user_guest, null, null, 0);
return;
Bundle extras = new Bundle();
extras.putInt(RestrictedProfileSettings.EXTRA_USER_ID, userId);
extras.putBoolean(RestrictedProfileSettings.EXTRA_NEW_USER, newUser);
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
RestrictedProfileSettings.class.getName(),
extras, R.string.user_restrictions_title, null,
null, 0);
} else if (mUserCaps.mIsAdmin) {
Bundle extras = new Bundle();
extras.putInt(UserDetailsSettings.EXTRA_USER_ID, userId);
- ((SettingsActivity) getActivity()).startPreferencePanel(
+ ((SettingsActivity) getActivity()).startPreferencePanel(this,
UserDetailsSettings.class.getName(),
extras,
-1, /* No title res id */
}
};
- public static void show(Context context, AppPreference pref) {
+ public static void show(Context context, AppPreference pref, int sourceMetricsCategory) {
Bundle args = new Bundle();
args.putString(ARG_PACKAGE_NAME, pref.getPackageName());
Utils.startWithFragmentAsUser(context, AppManagementFragment.class.getName(), args, -1,
- pref.getLabel(), false, new UserHandle(pref.getUserId()));
+ pref.getLabel(), false, sourceMetricsCategory, new UserHandle(pref.getUserId()));
}
@Override
ConfigDialogFragment.show(VpnSettings.this, pref.getProfile(), true /* editing */,
true /* exists */);
} else if (p instanceof AppPreference) {
- AppPreference pref = (AppPreference) p;;
- AppManagementFragment.show(getPrefContext(), pref);
+ AppPreference pref = (AppPreference) p;
+ AppManagementFragment.show(getPrefContext(), pref, getMetricsCategory());
}
}
};
@Override
public void onClick() {
final SettingsActivity activity = (SettingsActivity) getActivity();
- activity.startPreferencePanel(ScanningSettings.class.getName(), null,
- R.string.location_scanning_screen_title, null, null, 0);
+ activity.startPreferencePanel(WifiSettings.this,
+ ScanningSettings.class.getName(),
+ null, R.string.location_scanning_screen_title, null, null, 0);
}
};
mStatusMessagePreference.setText(
doReturn(mActivity).when(mSettings).getActivity();
when(mPreferenceManager.getContext()).thenReturn(mContext);
when(mFeatureFactory.dashboardFeatureProvider.getPreferencesForCategory(
- mActivity, mContext, CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
+ mActivity, mContext, mSettings.getMetricsCategory(),
+ CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT))
.thenReturn(preferences);
mSettings.onAttach(mContext);
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.FakeFeatureFactory;
FakeFeatureFactory.setupForTest(mContext);
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
-
+ when(mFactory.metricsFeatureProvider.getMetricsCategory(any(Object.class)))
+ .thenReturn(MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY);
mAppInfoWithHeader = new TestFragment();
}
@Test
public void testAppHeaderIsAdded() {
+ final AppHeaderController appHeaderController = new AppHeaderController(
+ ShadowApplication.getInstance().getApplicationContext(),
+ mAppInfoWithHeader,
+ null);
when(mFactory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
when(mFactory.applicationFeatureProvider.newAppHeaderController(mAppInfoWithHeader, null))
- .thenReturn(new AppHeaderController(
- ShadowApplication.getInstance().getApplicationContext(),
- mAppInfoWithHeader,
- null));
+ .thenReturn(appHeaderController);
mAppInfoWithHeader.onActivityCreated(null);
verify(mAppInfoWithHeader.mScreen).addPreference(any(LayoutPreference.class));
import com.android.settings.Settings;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowResources.SettingsShadowTheme;
+import com.android.settings.testutils.shadow.ShadowEventLogWriter;
import com.android.settingslib.applications.ApplicationsState;
import org.junit.Before;
import org.junit.Test;
shadows = {
SettingsShadowResources.class,
SettingsShadowTheme.class,
- ShadowDynamicIndexableContentMonitor.class
+ ShadowDynamicIndexableContentMonitor.class,
+ ShadowEventLogWriter.class
})
public class ManageApplicationsTest {
@Mock private UserManager mUserManager;
private Looper mBgLooper;
-
private ManageApplications mFragment;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mState.getBackgroundLooper()).thenReturn(mBgLooper);
mFragment = new ManageApplications();
+ ReflectionHelpers.setField(mFragment, "mLifecycle", new Lifecycle());
}
@Test
*/
package com.android.settings.core.instrumentation;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.SettingsActivity;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
+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;
@RunWith(SettingsRobolectricTestRunner.class)
mMixin.onResume();
verify(mMetricsFeature, times(1))
- .visible(any(Context.class), eq(TestInstrumentable.TEST_METRIC));
+ .visible(any(Context.class), eq(MetricsProto.MetricsEvent.VIEW_UNKNOWN),
+ eq(TestInstrumentable.TEST_METRIC));
+ }
+
+ @Test
+ public void shouldLogVisibleWithSource() {
+ final Intent sourceIntent = new Intent()
+ .putExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY,
+ MetricsProto.MetricsEvent.SETTINGS_GESTURES);
+ final Activity activity = mock(Activity.class);
+ when(activity.getIntent()).thenReturn(sourceIntent);
+ mMixin.setSourceMetricsCategory(activity);
+ mMixin.onResume();
+
+ verify(mMetricsFeature, times(1))
+ .visible(any(Context.class), eq(MetricsProto.MetricsEvent.SETTINGS_GESTURES),
+ eq(TestInstrumentable.TEST_METRIC));
}
@Test
tile.metaData = new Bundle();
tile.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
tile.priority = 10;
- mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
+ preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getTitle()).isEqualTo(tile.title);
assertThat(preference.getSummary()).isEqualTo(tile.summary);
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
- mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
+ preference, tile, "123", Preference.DEFAULT_ORDER);
assertThat(preference.getFragment()).isNull();
assertThat(preference.getOnPreferenceClickListener()).isNotNull();
when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
- mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
+ preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null);
verify(mActivity).getFragmentManager();
when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
- mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
+ preference, tile, "123", Preference.DEFAULT_ORDER);
preference.getOnPreferenceClickListener().onPreferenceClick(null);
verify(mFeatureFactory.metricsFeatureProvider).action(
any(Context.class),
final Tile tile = new Tile();
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
- mImpl.bindPreferenceToTile(mActivity, preference, tile, null /* key */
- , Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
+ preference, tile, null /*key */, Preference.DEFAULT_ORDER);
assertThat(preference.getKey()).isNotNull();
assertThat(preference.getOrder()).isEqualTo(Preference.DEFAULT_ORDER);
tile.key = "key";
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
- mImpl.bindPreferenceToTile(mActivity, preference, tile, null /* key */
- , Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
+ preference, tile, null /* key */, Preference.DEFAULT_ORDER);
assertThat(preference.getKey()).isEqualTo(tile.key);
}
final Tile tile = new Tile();
tile.metaData = new Bundle();
tile.priority = 10;
- mImpl.bindPreferenceToTile(mActivity, preference, tile, "123", baseOrder);
+ mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
+ preference, tile, "123", baseOrder);
assertThat(preference.getOrder()).isEqualTo(-tile.priority + baseOrder);
}
tile.metaData = new Bundle();
tile.metaData.putString("com.android.settings.intent.action", "TestAction");
tile.userHandle = null;
- mImpl.bindPreferenceToTile(activity, preference, tile, "123", Preference.DEFAULT_ORDER);
+ mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
+ preference, tile, "123", Preference.DEFAULT_ORDER);
preference.performClick();
ShadowActivity shadowActivity = shadowOf(activity);
- assertThat(shadowActivity.getNextStartedActivityForResult().intent.getAction())
+ final Intent launchIntent = shadowActivity.getNextStartedActivityForResult().intent;
+ assertThat(launchIntent.getAction())
.isEqualTo("TestAction");
+ assertThat(launchIntent.getIntExtra(SettingsActivity.EXTRA_SOURCE_METRICS_CATEGORY, 0))
+ .isEqualTo(MetricsProto.MetricsEvent.SETTINGS_GESTURES);
}
@Test
final DashboardFeatureProviderImpl mSpy = spy(mImpl);
when(mSpy.isEnabled()).thenReturn(false);
- assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
+ assertThat(mSpy.getPreferencesForCategory(null, null,
+ MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(null);
- assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
+ assertThat(mSpy.getPreferencesForCategory(null, null,
+ MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
when(mCategoryManager.getTilesByCategory(mActivity, CategoryKey.CATEGORY_HOMEPAGE))
.thenReturn(new DashboardCategory());
- assertThat(mSpy.getPreferencesForCategory(null, null, CategoryKey.CATEGORY_HOMEPAGE))
+ assertThat(mSpy.getPreferencesForCategory(null, null,
+ MetricsProto.MetricsEvent.SETTINGS_GESTURES, CategoryKey.CATEGORY_HOMEPAGE))
.isNull();
}
assertThat(mSpy.getPreferencesForCategory(mActivity,
ShadowApplication.getInstance().getApplicationContext(),
+ MetricsProto.MetricsEvent.SETTINGS_GESTURES,
CategoryKey.CATEGORY_HOMEPAGE).isEmpty())
.isFalse();
}
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
+import com.android.settings.core.instrumentation.VisibilityLoggerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.drawer.DashboardCategory;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
import java.util.List;
mControllers = new ArrayList<>();
when(mPreferenceManager.getContext()).thenReturn(mContext);
+ ReflectionHelpers.setField(
+ this, "mVisibilityLoggerMixin", mock(VisibilityLoggerMixin.class));
}
@Override
--- /dev/null
+/*
+ * 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.settings.testutils.shadow;
+
+
+import android.content.Context;
+
+import com.android.settings.core.instrumentation.EventLogWriter;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(value = EventLogWriter.class, callThroughByDefault = false)
+public class ShadowEventLogWriter {
+ @Implementation
+ public void visible(Context context, int source, int category) {
+
+ }
+}