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

Commit de060226 authored by Jason Monk's avatar Jason Monk
Browse files

Only register SPN receiver when we need to

Avoid crashing fugu by not registering this receiver when the uri
where we would store the data is not valid.

Bug: 18634568
Change-Id: I882eaa0dc6a312b4df7d5e39056ab5f8df844162
parent 3ec379cf
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony;

import android.content.BroadcastReceiver;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
@@ -224,8 +225,7 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        mContext.registerReceiver(mReceiver,
                new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
        registerReceiverIfNeeded();

        if (DBG) logdl("[SubscriptionController] init by Context");
    }
@@ -241,12 +241,24 @@ public class SubscriptionController extends ISub.Stub {
        if(ServiceManager.getService("isub") == null) {
                ServiceManager.addService("isub", this);
        }
        mContext.registerReceiver(mReceiver,
                new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
        registerReceiverIfNeeded();

        if (DBG) logdl("[SubscriptionController] init by Phone");
    }

    private void registerReceiverIfNeeded() {
        // We only need to register the broadcast receiver if the URI
        // where we are going to store the data is valid.
        // TODO: This can be removed once the SubscriptionController is not running
        // on devices that don't need it, such as TVs.
        if (mContext.getPackageManager().resolveContentProvider(
                SubscriptionManager.CONTENT_URI.getAuthority(), 0) != null) {
            if (DBG) logd("registering SPN updated receiver");
            mContext.registerReceiver(mReceiver,
                    new IntentFilter(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION));
        }
    }

    /**
     * Make sure the caller has the READ_PHONE_STATE permission.
     *