android:value="com.android.settings.vpn2.VpnSettings" />
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
android:resource="@id/wireless_settings" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
</activity>
<activity android:name="Settings$DateTimeSettingsActivity"
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
- android:title="wireless_settings"
- android:key="@string/radio_controls_title">
+ android:title="@string/radio_controls_title">
<SwitchPreference
android:key="toggle_airplane"
mAppSwitches = (LinearLayout) mAppDetail.findViewById(R.id.app_switches);
mAppSettings = (Button) mAppDetail.findViewById(R.id.app_settings);
- mAppSettings.setOnClickListener(mAppSettingsListener);
mAppRestrict = new Switch(inflater.getContext());
mAppRestrict.setClickable(false);
}
}
+ mAppSettings.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (!isAdded()) {
+ return;
+ }
+
+ // TODO: target towards entire UID instead of just first package
+ getActivity().startActivityAsUser(mAppSettingsIntent,
+ new UserHandle(UserHandle.getUserId(uid)));
+ }
+ });
mAppSettings.setEnabled(matchFound);
mAppSettings.setVisibility(View.VISIBLE);
} else {
mAppSettingsIntent = null;
+ mAppSettings.setOnClickListener(null);
mAppSettings.setVisibility(View.GONE);
}
}
};
- private OnClickListener mAppSettingsListener = new OnClickListener() {
- @Override
- public void onClick(View v) {
- if (!isAdded()) return;
-
- // TODO: target torwards entire UID instead of just first package
- startActivity(mAppSettingsIntent);
- }
- };
-
private OnItemClickListener mListListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
+import android.content.pm.Signature;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
return tm.getSimCount() > 0;
}
+
+ /**
+ * Determine whether a package is a "system package", in which case certain things (like
+ * disabling notifications or disabling the package altogether) should be disallowed.
+ */
+ public static boolean isSystemPackage(PackageManager pm, PackageInfo pkg) {
+ if (sSystemSignature == null) {
+ sSystemSignature = new Signature[]{ getSystemSignature(pm) };
+ }
+ return sSystemSignature[0] != null && sSystemSignature[0].equals(getFirstSignature(pkg));
+ }
+
+ private static Signature[] sSystemSignature;
+
+ private static Signature getFirstSignature(PackageInfo pkg) {
+ if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
+ return pkg.signatures[0];
+ }
+ return null;
+ }
+
+ private static Signature getSystemSignature(PackageManager pm) {
+ try {
+ final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
+ return getFirstSignature(sys);
+ } catch (NameNotFoundException e) {
+ }
+ return null;
+ }
+
}
if (mServicesCategory.getPreferenceCount() == 0) {
if (mNoServicesMessagePreference == null) {
- mNoServicesMessagePreference = new Preference(getActivity()) {
- @Override
- protected void onBindView(View view) {
- super.onBindView(view);
- TextView summaryView = (TextView) view.findViewById(R.id.summary);
- String title = getString(R.string.accessibility_no_services_installed);
- summaryView.setText(title);
- }
- };
+ mNoServicesMessagePreference = new Preference(getActivity());
mNoServicesMessagePreference.setPersistent(false);
mNoServicesMessagePreference.setLayoutResource(
R.layout.text_description_preference);
mNoServicesMessagePreference.setSelectable(false);
+ mNoServicesMessagePreference.setSummary(
+ getString(R.string.accessibility_no_services_installed));
}
mServicesCategory.addPreference(mNoServicesMessagePreference);
}
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
+ mProfileNotAvailablePreference = new Preference(getActivity());
setHasOptionsMenu(true);
}
}
} else {
// Put a label instead of the accounts list
- synchronized (this) {
- if (mProfileNotAvailablePreference == null) {
- mProfileNotAvailablePreference = new Preference(getActivity());
- mProfileNotAvailablePreference.setEnabled(false);
- mProfileNotAvailablePreference.setIcon(R.drawable.empty_icon);
- mProfileNotAvailablePreference.setTitle(null);
- mProfileNotAvailablePreference.setSummary(
- R.string.managed_profile_not_available_label);
- }
- }
+ mProfileNotAvailablePreference.setEnabled(false);
+ mProfileNotAvailablePreference.setIcon(R.drawable.empty_icon);
+ mProfileNotAvailablePreference.setTitle(null);
+ mProfileNotAvailablePreference.setSummary(
+ R.string.managed_profile_not_available_label);
profileData.preferenceGroup.addPreference(mProfileNotAvailablePreference);
}
if (profileData.removeWorkProfilePreference != null) {
}
}
- private boolean isThisASystemPackage() {
- try {
- PackageInfo sys = mPm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
- return (mPackageInfo != null && mPackageInfo.signatures != null &&
- sys.signatures[0].equals(mPackageInfo.signatures[0]));
- } catch (PackageManager.NameNotFoundException e) {
- return false;
- }
- }
-
private boolean handleDisableable(Button button) {
boolean disableable = false;
// Try to prevent the user from bricking their phone
// by not allowing disabling of apps signed with the
// system cert and any launcher app in the system.
- if (mHomePackages.contains(mAppEntry.info.packageName) || isThisASystemPackage()) {
+ if (mHomePackages.contains(mAppEntry.info.packageName)
+ || Utils.isSystemPackage(mPm, mPackageInfo)) {
// Disable button for core system applications.
button.setText(R.string.disable_text);
} else if (mAppEntry.info.enabled) {
// this does not bode well
}
mNotificationSwitch.setChecked(enabled);
- if (isThisASystemPackage()) {
+ if (Utils.isSystemPackage(mPm, mPackageInfo)) {
mNotificationSwitch.setEnabled(false);
} else {
mNotificationSwitch.setEnabled(true);
parent.getPaddingEnd() - eat, parent.getPaddingBottom());
}
- private boolean isSystemApp(PackageInfo pkg) {
- if (mSystemSignature == null) {
- mSystemSignature = new Signature[]{ getSystemSignature() };
- }
- return mSystemSignature[0] != null && mSystemSignature[0].equals(getFirstSignature(pkg));
- }
-
- private static Signature getFirstSignature(PackageInfo pkg) {
- if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) {
- return pkg.signatures[0];
- }
- return null;
- }
-
- private Signature getSystemSignature() {
- final PackageManager pm = mContext.getPackageManager();
- try {
- final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES);
- return getFirstSignature(sys);
- } catch (NameNotFoundException e) {
- }
- return null;
- }
-
private static class ViewHolder {
ViewGroup row;
ImageView icon;
public boolean priority;
public boolean sensitive;
public boolean first; // first app in section
+ public boolean isSystem;
}
private static final Comparator<AppRow> mRowComparator = new Comparator<AppRow>() {
}
};
+
public static AppRow loadAppRow(PackageManager pm, PackageInfo pkg, Backend backend) {
final AppRow row = new AppRow();
row.pkg = pkg.packageName;
row.banned = backend.getNotificationsBanned(row.pkg, row.uid);
row.priority = backend.getHighPriority(row.pkg, row.uid);
row.sensitive = backend.getSensitive(row.pkg, row.uid);
+ row.isSystem = Utils.isSystemPackage(pm, pkg);
return row;
}
- public static void collectConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows) {
+ public static List<ResolveInfo> queryNotificationConfigActivities(PackageManager pm) {
if (DEBUG) Log.d(TAG, "APP_NOTIFICATION_PREFS_CATEGORY_INTENT is "
+ APP_NOTIFICATION_PREFS_CATEGORY_INTENT);
final List<ResolveInfo> resolveInfos = pm.queryIntentActivities(
APP_NOTIFICATION_PREFS_CATEGORY_INTENT,
- PackageManager.MATCH_DEFAULT_ONLY);
- if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities");
+ 0 //PackageManager.MATCH_DEFAULT_ONLY
+ );
+ return resolveInfos;
+ }
+ public static void collectConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows) {
+ final List<ResolveInfo> resolveInfos = queryNotificationConfigActivities(pm);
+ applyConfigActivities(pm, rows, resolveInfos);
+ }
+
+ public static void applyConfigActivities(PackageManager pm, ArrayMap<String, AppRow> rows,
+ List<ResolveInfo> resolveInfos) {
+ if (DEBUG) Log.d(TAG, "Found " + resolveInfos.size() + " preference activities"
+ + (resolveInfos.size() == 0 ? " ;_;" : ""));
for (ResolveInfo ri : resolveInfos) {
final ActivityInfo activityInfo = ri.activityInfo;
final ApplicationInfo appInfo = activityInfo.applicationInfo;
+ activityInfo.packageName);
continue;
}
- row.settingsIntent = new Intent(Intent.ACTION_MAIN)
+ row.settingsIntent = new Intent(APP_NOTIFICATION_PREFS_CATEGORY_INTENT)
.setClassName(activityInfo.packageName, activityInfo.name);
}
}
mRows.clear();
mSortedRows.clear();
- // collect all non-system apps
+ // collect all launchable apps, plus any packages that have notification settings
final PackageManager pm = mContext.getPackageManager();
- for (PackageInfo pkg : pm.getInstalledPackages(PackageManager.GET_SIGNATURES)) {
- if (pkg.applicationInfo == null || isSystemApp(pkg)) {
- if (DEBUG) Log.d(TAG, "Skipping " + pkg.packageName);
+ final List<ResolveInfo> resolvedApps = pm.queryIntentActivities(
+ new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
+ PackageManager.MATCH_DEFAULT_ONLY
+ );
+ final List<ResolveInfo> resolvedConfigActivities
+ = queryNotificationConfigActivities(pm);
+ resolvedApps.addAll(resolvedConfigActivities);
+
+ for (ResolveInfo info : resolvedApps) {
+ String pkgName = info.activityInfo.packageName;
+ if (mRows.containsKey(pkgName)) {
+ // we already have this app, thanks
+ continue;
+ }
+
+ PackageInfo pkg = null;
+ try {
+ pkg = pm.getPackageInfo(pkgName,
+ PackageManager.GET_SIGNATURES);
+ } catch (NameNotFoundException e) {
+ if (DEBUG) Log.d(TAG, "Skipping (NNFE): " + pkg.packageName);
+ continue;
+ }
+ if (info.activityInfo.applicationInfo == null) {
+ if (DEBUG) Log.d(TAG, "Skipping (no applicationInfo): " + pkg.packageName);
continue;
}
final AppRow row = loadAppRow(pm, pkg, mBackend);
- mRows.put(row.pkg, row);
+ mRows.put(pkgName, row);
}
- // collect config activities
- collectConfigActivities(pm, mRows);
+
+ // add config activities to the list
+ applyConfigActivities(pm, mRows, resolvedConfigActivities);
// sort rows
mSortedRows.addAll(mRows.values());
Collections.sort(mSortedRows, mRowComparator);
return;
}
+ // The DocID should contains more than the title string itself (you may have two settings
+ // with the same title). So we need to use a combination of the title and the screenTitle.
+ StringBuilder sb = new StringBuilder(updatedTitle);
+ sb.append(screenTitle);
+ int docId = sb.toString().hashCode();
+
ContentValues values = new ContentValues();
- values.put(IndexColumns.DOCID, updatedTitle.hashCode());
+ values.put(IndexColumns.DOCID, docId);
values.put(IndexColumns.LOCALE, locale);
values.put(IndexColumns.DATA_RANK, rank);
values.put(IndexColumns.DATA_TITLE, updatedTitle);
super.onCreate(bundle);
if (mSubInfoList == null) {
- mSubInfoList = SubscriptionManager.getActivatedSubInfoList(getActivity());
+ mSubInfoList = SubscriptionManager.getActiveSubInfoList();
}
createPreferences();
}
private void updateSimSlotValues() {
- SubscriptionManager.getAllSubInfoList(getActivity());
+ SubscriptionManager.getAllSubInfoList();
final PreferenceCategory simCards = (PreferenceCategory)findPreference(SIM_CARD_CATEGORY);
final PreferenceScreen prefScreen = getPreferenceScreen();
private void updateSmsValues() {
final DropDownPreference simPref = (DropDownPreference) findPreference(KEY_SMS);
- final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getPreferredSmsSubId());
+ final SubInfoRecord sir = findRecordBySubId(SubscriptionManager.getDefaultSmsSubId());
if (sir != null) {
simPref.setSelectedItem(sir.mSlotId + 1);
}
final Spinner displayNumbers =
(Spinner)dialogLayout.findViewById(R.id.display_numbers);
- SubscriptionManager.setDisplayNumberFormat(getActivity(),
+ SubscriptionManager.setDisplayNumberFormat(
displayNumbers.getSelectedItemPosition() == 0
? SubscriptionManager.DISPLAY_NUMBER_LAST
: SubscriptionManager.DISPLAY_NUMBER_FIRST, mSubInfoRecord.mSubId);
mSubInfoRecord.mDisplayName = nameText.getText().toString();
- SubscriptionManager.setDisplayName(getActivity(), mSubInfoRecord.mDisplayName,
+ SubscriptionManager.setDisplayName(mSubInfoRecord.mDisplayName,
mSubInfoRecord.mSubId);
updateAllOptions();
int userId = newUserInfo.id;
UserHandle user = new UserHandle(userId);
mUserManager.setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true, user);
- mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user);
+ // Change the setting before applying the DISALLOW_SHARE_LOCATION restriction, otherwise
+ // the putIntForUser() will fail.
Secure.putIntForUser(getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, userId);
+ mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user);
Bitmap bitmap = createBitmapFromDrawable(
USER_DRAWABLES[userId % UserSettings.USER_DRAWABLES.length]);
mUserManager.setUserIcon(userId, bitmap);
final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
if (configs != null) {
- savedNetworksExist = (configs.size() > 0);
+ // Update "Saved Networks" menu option.
+ if (savedNetworksExist != (configs.size() > 0)) {
+ savedNetworksExist = !savedNetworksExist;
+ if (context instanceof Activity) {
+ ((Activity) context).invalidateOptionsMenu();
+ }
+ }
for (WifiConfiguration config : configs) {
AccessPoint accessPoint = new AccessPoint(context, config);
if (lastInfo != null && lastState != null) {
private static final int WPS_TIMEOUT_S = 120;
private WifiManager mWifiManager;
- private WifiManager.WpsListener mWpsListener;
+ private WifiManager.WpsCallback mWpsListener;
private int mWpsSetup;
private final IntentFilter mFilter;
mContext = context;
mWpsSetup = wpsSetup;
- class WpsListener implements WifiManager.WpsListener {
- public void onStartSuccess(String pin) {
+ class WpsListener extends WifiManager.WpsCallback {
+
+ public void onStarted(String pin) {
if (pin != null) {
updateDialog(DialogState.WPS_START, String.format(
mContext.getString(R.string.wifi_wps_onstart_pin), pin));
R.string.wifi_wps_onstart_pbc));
}
}
- public void onCompletion() {
+
+ public void onSucceeded() {
updateDialog(DialogState.WPS_COMPLETE,
mContext.getString(R.string.wifi_wps_complete));
}
- public void onFailure(int reason) {
+ public void onFailed(int reason) {
String msg;
switch (reason) {
case WifiManager.WPS_OVERLAP_ERROR: