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

Commit c8c10ef4 authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/lineage-16.0' into v1-pie

parents 85f73035 22600b72
Loading
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import android.Manifest;
import android.annotation.Nullable;
import android.app.AppOpsManager;
@@ -2078,10 +2080,20 @@ public class SubscriptionController extends ISub.Stub {
     */
    @Override
    public String getSubscriptionProperty(int subId, String propKey, String callingPackage) {
        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
                mContext, subId, callingPackage, "getSubscriptionProperty")) {
        switch (propKey) {
            case "group_uuid":
                if (mContext.checkCallingOrSelfPermission(
                        Manifest.permission.READ_PRIVILEGED_PHONE_STATE) != PERMISSION_GRANTED) {
                    EventLog.writeEvent(0x534e4554, "213457638", Binder.getCallingUid());
                    return null;
                }
                break;
            default:
                if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mContext, subId,
                        callingPackage, "getSubscriptionProperty")) {
                    return null;
                }
        }
        String resultValue = null;
        ContentResolver resolver = mContext.getContentResolver();
        Cursor cursor = resolver.query(SubscriptionManager.CONTENT_URI,
+0 −6
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioAttributes;
import android.net.Uri;
import android.provider.Settings;
import android.telephony.SubscriptionManager;

@@ -117,7 +116,6 @@ public class NotificationChannelController {

    /**
     * migrate deprecated voicemail notification settings to initial notification channel settings
     * {@link VoicemailNotificationSettingsUtil#getRingTonePreference(Context)}}
     * {@link VoicemailNotificationSettingsUtil#getVibrationPreference(Context)}
     * notification settings are based on subId, only migrate if sub id matches.
     * otherwise fallback to predefined voicemail channel settings.
@@ -130,10 +128,6 @@ public class NotificationChannelController {
                NotificationManager.IMPORTANCE_DEFAULT);
        voiceMailChannel.enableVibration(
                VoicemailNotificationSettingsUtil.getVibrationPreference(context));
        Uri sound = VoicemailNotificationSettingsUtil.getRingTonePreference(context);
        voiceMailChannel.setSound(
                (sound == null) ? Settings.System.DEFAULT_NOTIFICATION_URI : sound,
                new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build());
        context.getSystemService(NotificationManager.class)
                .createNotificationChannel(voiceMailChannel);
    }
+4 −18
Original line number Diff line number Diff line
@@ -21,10 +21,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

public class VoicemailNotificationSettingsUtil {
    private static final String VOICEMAIL_NOTIFICATION_RINGTONE_SHARED_PREFS_KEY_PREFIX =
@@ -64,27 +62,15 @@ public class VoicemailNotificationSettingsUtil {
    }

   public static void setRingtoneUri(Context context, Uri ringtoneUri) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String ringtoneUriStr = ringtoneUri != null ? ringtoneUri.toString() : "";

        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(getVoicemailRingtoneSharedPrefsKey(), ringtoneUriStr);
        editor.commit();
        // Do nothing; we don't use the shared preference any more.
    }

    public static Uri getRingtoneUri(Context context) {
        final NotificationChannel channel = NotificationChannelController.getChannel(
                NotificationChannelController.CHANNEL_ID_VOICE_MAIL, context);
        return (channel != null) ? channel.getSound() : getRingTonePreference(context);
    }

    public static Uri getRingTonePreference(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        migrateVoicemailRingtoneSettingsIfNeeded(context, prefs);
        String uriString = prefs.getString(
                getVoicemailRingtoneSharedPrefsKey(),
                Settings.System.DEFAULT_NOTIFICATION_URI.toString());
        return !TextUtils.isEmpty(uriString) ? Uri.parse(uriString) : null;
        // Note: NEVER look at the shared preferences; this was migrated to the notification channel
        // in Android P.
        return (channel != null) ? channel.getSound() : null;
    }

    /**
+30 −0
Original line number Diff line number Diff line
@@ -422,4 +422,34 @@ public class SubscriptionControllerTest extends TelephonyTest {
                SubscriptionManager.WFC_IMS_ROAMING_MODE,
                mCallingPackage));
    }

    @Test
    @SmallTest
    public void testGetSubscriptionProperty() throws Exception {
        testInsertSim();
        ContentValues values = new ContentValues();
        values.put(SubscriptionManager.GROUP_UUID, 1);
        mFakeTelephonyProvider.update(SubscriptionManager.CONTENT_URI, values,
                SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID + "=" + 1, null);

        mContextFixture.removeCallingOrSelfPermission(ContextFixture.PERMISSION_ENABLE_ALL);
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE);

        // should succeed with read phone state permission
        String prop = mSubscriptionControllerUT.getSubscriptionProperty(1,
                SubscriptionManager.CB_EXTREME_THREAT_ALERT, mContext.getOpPackageName());

        assertNotEquals(null, prop);

        // group UUID requires privileged phone state permission
        prop = mSubscriptionControllerUT.getSubscriptionProperty(1, SubscriptionManager.GROUP_UUID,
                    mContext.getOpPackageName());
        assertEquals(null, prop);

        // group UUID should succeed once privileged phone state permission is granted
        mContextFixture.addCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE);
        prop = mSubscriptionControllerUT.getSubscriptionProperty(1, SubscriptionManager.GROUP_UUID,
                mContext.getOpPackageName());
        assertNotEquals(null, prop);
    }
}