import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
+import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.INetworkManagementService;
import android.os.RemoteException;
import com.android.settings.location.LocationSettings;
import com.android.settings.nfc.AndroidBeam;
import com.android.settings.nfc.PaymentSettings;
+import com.android.settings.print.PrintJobSettingsFragment;
import com.android.settings.print.PrintServiceSettingsFragment;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.tts.TextToSpeechSettings;
private static final String SAVE_KEY_CURRENT_HEADER = "com.android.settings.CURRENT_HEADER";
private static final String SAVE_KEY_PARENT_HEADER = "com.android.settings.PARENT_HEADER";
+ static final int DIALOG_ONLY_ONE_HOME = 1;
+
+ private static boolean sShowNoHomeNotice = false;
+
private String mFragmentClass;
private int mTopLevelHeaderId;
private Header mFirstHeader;
NotificationAccessSettings.class.getName(),
ManageAccountsSettings.class.getName(),
PrintSettingsFragment.class.getName(),
+ PrintJobSettingsFragment.class.getName(),
TrustedCredentialsSettings.class.getName(),
PaymentSettings.class.getName(),
KeyboardLayoutPickerFragment.class.getName()
// uiOptions for fragments also defined as activities in manifest.
if (WifiSettings.class.getName().equals(fragmentName) ||
WifiP2pSettings.class.getName().equals(fragmentName) ||
- WifiDisplaySettings.class.getName().equals(fragmentName) ||
BluetoothSettings.class.getName().equals(fragmentName) ||
DreamSettings.class.getName().equals(fragmentName) ||
LocationSettings.class.getName().equals(fragmentName) ||
*/
@Override
public void onBuildHeaders(List<Header> headers) {
- loadHeadersFromResource(R.xml.settings_headers, headers);
- updateHeaderList(headers);
+ if (!onIsHidingHeaders()) {
+ loadHeadersFromResource(R.xml.settings_headers, headers);
+ updateHeaderList(headers);
+ }
}
private void updateHeaderList(List<Header> target) {
int headerIndex = i + 1;
i = insertAccountsHeaders(target, headerIndex);
} else if (id == R.id.home_settings) {
- updateHomeSettingHeaders(header);
+ if (!updateHomeSettingHeaders(header)) {
+ target.remove(i);
+ }
} else if (id == R.id.user_settings) {
if (!UserHandle.MU_ENABLED
|| !UserManager.supportsMultipleUsers()
target.remove(i);
}
} else if (id == R.id.nfc_payment_settings) {
- if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC_HCE)) {
+ if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
target.remove(i);
+ } else {
+ // Only show if NFC is on and we have the HCE feature
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
+ if (!adapter.isEnabled() || !getPackageManager().hasSystemFeature(
+ PackageManager.FEATURE_NFC_HOST_CARD_EMULATION)) {
+ target.remove(i);
+ }
}
} else if (id == R.id.development_settings) {
if (!showDev) {
}
}
accountHeaders.add(accHeader);
+ mAuthenticatorHelper.preloadDrawableForType(this, accountType);
}
// Sort by label
return headerIndex;
}
- private boolean isSystemApp(ResolveInfo ri) {
- return ((ri.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
- }
+ private boolean updateHomeSettingHeaders(Header header) {
+ // Once we decide to show Home settings, keep showing it forever
+ SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
+ if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
+ return true;
+ }
- private void updateHomeSettingHeaders(Header header) {
- final PackageManager pm = getPackageManager();
- final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
try {
- ComponentName currentHome = pm.getHomeActivities(homeApps);
- ResolveInfo iconSource = null;
- if (currentHome == null) {
- // no current default, so find the system home app and use that
- for (int which = 0; which < homeApps.size(); which++) {
- ResolveInfo ri = homeApps.get(which);
- if (isSystemApp(ri)) {
- iconSource = ri;
- break;
- }
+ final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
+ getPackageManager().getHomeActivities(homeApps);
+ if (homeApps.size() < 2) {
+ // When there's only one available home app, omit this settings
+ // category entirely at the top level UI. If the user just
+ // uninstalled the penultimate home app candidiate, we also
+ // now tell them about why they aren't seeing 'Home' in the list.
+ if (sShowNoHomeNotice) {
+ sShowNoHomeNotice = false;
+ NoHomeDialogFragment.show(this);
}
+ return false;
} else {
- // find the current-home entry in the returned set
- for (int which = 0; which < homeApps.size(); which++) {
- ResolveInfo ri = homeApps.get(which);
- ComponentName riName = new ComponentName(ri.activityInfo.packageName,
- ri.activityInfo.name);
- if (riName.equals(currentHome)) {
- iconSource = ri;
- break;
- }
+ // Okay, we're allowing the Home settings category. Tell it, when
+ // invoked via this front door, that we'll need to be told about the
+ // case when the user uninstalls all but one home app.
+ if (header.fragmentArguments == null) {
+ header.fragmentArguments = new Bundle();
}
- }
- if (iconSource != null) {
- if (header.extras == null) {
- header.extras = new Bundle();
- }
- header.extras.putParcelable(HomeSettings.CURRENT_HOME, iconSource.activityInfo);
- } else {
- Log.v(LOG_TAG, "No home app icon found");
+ header.fragmentArguments.putBoolean(HomeSettings.HOME_SHOW_NOTICE, true);
}
} catch (Exception e) {
// Can't look up the home activity; bail on configuring the icon
Log.w(LOG_TAG, "Problem looking up home activity!", e);
}
+
+ sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
+ return true;
}
private void getMetaData() {
return super.getNextButton();
}
+ public static class NoHomeDialogFragment extends DialogFragment {
+ public static void show(Activity parent) {
+ final NoHomeDialogFragment dialog = new NoHomeDialogFragment();
+ dialog.show(parent.getFragmentManager(), null);
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return new AlertDialog.Builder(getActivity())
+ .setMessage(R.string.only_one_home_message)
+ .setPositiveButton(android.R.string.ok, null)
+ .create();
+ }
+ }
+
private static class HeaderAdapter extends ArrayAdapter<Header> {
static final int HEADER_TYPE_CATEGORY = 0;
static final int HEADER_TYPE_NORMAL = 1;
holder.divider_.setVisibility(View.VISIBLE);
boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null;
if (isManaged) {
- holder.button_.setImageResource(R.drawable.ic_qs_certificate_info);
+ holder.button_.setImageResource(R.drawable.ic_settings_about);
} else {
holder.button_.setImageResource(
android.R.drawable.stat_notify_error);
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
setHeaderIcon(holder, icon);
- } else if (header.extras != null &&
- header.extras.containsKey(HomeSettings.CURRENT_HOME)) {
- ActivityInfo ai = header.extras.getParcelable(HomeSettings.CURRENT_HOME);
- Drawable icon = ai.loadIcon(getContext().getPackageManager());
- setHeaderIcon(holder, icon);
} else {
holder.icon.setImageResource(header.iconRes);
}
invalidateHeaders();
}
+ public static void requestHomeNotice() {
+ sShowNoHomeNotice = true;
+ }
+
/*
* Settings subclasses for launching independently.
*/
public static class TrustedCredentialsSettingsActivity extends Settings { /* empty */ }
public static class PaymentSettingsActivity extends Settings { /* empty */ }
public static class PrintSettingsActivity extends Settings { /* empty */ }
+ public static class PrintJobSettingsActivity extends Settings { /* empty */ }
}