Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d26227f authored by Danesh M's avatar Danesh M
Browse files

Settings : Filter settings for secondary users

Filter blacklist/whisperpush for secondary user
Filter default sms if user can't sms/call
Filter phone ringtone/vibrate on calls for secondary user

issue-id: CYNGNOS-904

Change-Id: I008215f885e819bd3229a4f9a6c6ca6fc09df6c5
(cherry picked from commit 3e67d92b)
parent 9c48c7f3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.provider.MediaStore;
import android.provider.OpenableColumns;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;

@@ -303,9 +302,10 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
    // === Phone & notification ringtone ===

    private void initRingtones(PreferenceCategory root) {
        boolean isOwner = Utils.isUserOwner();
        DefaultRingtonePreference phoneRingtonePreference =
                (DefaultRingtonePreference) root.findPreference(KEY_PHONE_RINGTONE);
        if (phoneRingtonePreference != null && !mVoiceCapable) {
        if (phoneRingtonePreference != null && (!mVoiceCapable || !isOwner)) {
            root.removePreference(phoneRingtonePreference);
            mPhoneRingtonePreferences = null;
        } else {
@@ -437,7 +437,7 @@ public class SoundSettings extends SettingsPreferenceFragment implements Indexab
            Log.i(TAG, "Preference not found: " + KEY_VIBRATE_WHEN_RINGING);
            return;
        }
        if (!mVoiceCapable) {
        if (!mVoiceCapable || !Utils.isUserOwner()) {
            root.removePreference(mVibrateWhenRinging);
            mVibrateWhenRinging = null;
            return;
+14 −0
Original line number Diff line number Diff line
@@ -1390,4 +1390,18 @@ public final class Utils {
        }
        return !TextUtils.isEmpty(name);
    }

    public static boolean isUserOwner() {
        return UserHandle.myUserId() == UserHandle.USER_OWNER;
    }

    public static boolean canUserMakeCallsSms(Context context) {
        UserManager userManager = UserManager.get(context);
        UserHandle userHandle = new UserHandle(UserHandle.myUserId());
        boolean callSmsNotAllowed = userManager.hasUserRestriction(
                userManager.DISALLOW_OUTGOING_CALLS, userHandle);
        callSmsNotAllowed &= userManager.hasUserRestriction(
                UserManager.DISALLOW_SMS, userHandle);
        return !callSmsNotAllowed;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ public class WirelessSettings extends SettingsPreferenceFragment

        mSmsApplicationPreference = (AppListPreference) findPreference(KEY_SMS_APPLICATION);
        // Restricted users cannot currently read/write SMS.
        if (isRestrictedUser) {
        if (isRestrictedUser || !Utils.canUserMakeCallsSms(activity)) {
            removePreference(KEY_SMS_APPLICATION);
        } else {
            mSmsApplicationPreference.setOnPreferenceChangeListener(this);
+8 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
    private static final String KEY_WHISPERPUSH = "whisperpush";
    private static final String WHISPERPUSH_ORIGINAL = "org.whispersystems.whisperpush";
    private static final String WHISPERPUSH_UPDATE = "org.whispersystems.whisperpush2";
    private static final String KEY_STATS = "cmstats";

    private PreferenceScreen mBlacklist;
    private Preference mWhisperPush;
@@ -62,8 +63,14 @@ public class PrivacySettings extends SettingsPreferenceFragment implements Index
        // Add package manager to check if features are available
        PackageManager pm = getPackageManager();

        boolean isOwner = Utils.isUserOwner();
        if (!isOwner) {
            PreferenceScreen root = getPreferenceScreen();
            root.removePreference(findPreference(KEY_STATS));
        }

        // Determine options based on device telephony support
        if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) || !isOwner) {
            // No telephony, remove dependent options
            PreferenceScreen root = getPreferenceScreen();
            root.removePreference(mBlacklist);