import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.os.UserHandle;
-import android.support.v14.preference.PreferenceFragment;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.Preference.OnPreferenceClickListener;
-import android.support.v7.preference.PreferenceGroup;
-import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
import android.util.Log;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceClickListener;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.R;
-import com.android.settings.SettingsActivity;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.location.LocationSettings;
import com.android.settings.utils.LocalClassLoaderContextThemeWrapper;
import com.android.settingslib.accounts.AuthenticatorHelper;
+import com.android.settingslib.core.instrumentation.Instrumentable;
/**
* Class to load the preference screen to be added to the settings page for the specific account
private AuthenticatorHelper mAuthenticatorHelper;
private UserHandle mUserHandle;
- private PreferenceFragment mFragment;
+ private PreferenceFragmentCompat mFragment;
- public AccountTypePreferenceLoader(PreferenceFragment fragment,
+ public AccountTypePreferenceLoader(PreferenceFragmentCompat fragment,
AuthenticatorHelper authenticatorHelper, UserHandle userHandle) {
mFragment = fragment;
mAuthenticatorHelper = authenticatorHelper;
// startPreferencePanel() there. In order to inject the title string there, more
// dirty further hack is still needed. It's much easier and cleaner to listen to
// preference click event here directly.
- if (intent.getAction().equals(
- android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
+ if (TextUtils.equals(intent.getAction(),
+ android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
// The OnPreferenceClickListener overrides the click event completely. No intent
// will get fired.
pref.setOnPreferenceClickListener(new FragmentStarter(
ActivityInfo resolvedActivityInfo = resolveInfo.activityInfo;
ApplicationInfo resolvedAppInfo = resolvedActivityInfo.applicationInfo;
try {
- if (resolvedActivityInfo.exported) {
- if (resolvedActivityInfo.permission == null) {
- return true; // exported activity without permission.
- } else if (pm.checkPermission(resolvedActivityInfo.permission,
- authDesc.packageName) == PackageManager.PERMISSION_GRANTED) {
- return true;
- }
- }
+ // Allows to launch only authenticator owned activities.
ApplicationInfo authenticatorAppInf = pm.getApplicationInfo(authDesc.packageName, 0);
return resolvedAppInfo.uid == authenticatorAppInf.uid;
} catch (NameNotFoundException e) {
@Override
public boolean onPreferenceClick(Preference preference) {
- ((SettingsActivity) mFragment.getActivity()).startPreferencePanel(mFragment,
- mClass, null, mTitleRes, null, null, 0);
+ final int metricsCategory = (mFragment instanceof Instrumentable)
+ ? ((Instrumentable) mFragment).getMetricsCategory()
+ : Instrumentable.METRICS_CATEGORY_UNKNOWN;
+ new SubSettingLauncher(preference.getContext())
+ .setTitleRes(mTitleRes)
+ .setDestination(mClass)
+ .setSourceMetricsCategory(metricsCategory)
+ .launch();
+
// Hack: announce that the Google account preferences page is launching the location
// settings
if (mClass.equals(LocationSettings.class.getName())) {