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

Commit e8329e1e authored by Ethan Chen's avatar Ethan Chen Committed by Ricardo Cerqueira
Browse files

Settings(MSIM): Disable MultiSimSettings activity if unsupported

* If this activity is launched on a non-multi-SIM it will crash.
* Because the activity is disabled, MultiSimSettings will become
  unavailable until the device is restarted.

Change-Id: I39eb1b41836833694be7469026abd95430691b52
parent 604d7ad5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1931,5 +1931,12 @@
            android:name=".cyanogenmod.LtoService">
        </service>

        <!-- Disable MultiSIM settings if not available. -->
        <receiver android:name=".deviceinfo.msim.DisableMSimReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

    </application>
</manifest>
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The CyanogenMod Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.deviceinfo.msim;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.telephony.MSimTelephonyManager;
import android.util.Log;

// We want to disable multi-SIM activities if it is unsupported. This
// receiver runs when BOOT_COMPLETED intent is received.
public class DisableMSimReceiver extends BroadcastReceiver {
    private static final String TAG = "DisableMSimReceiver";
    private static final String ACTIVITIES[] = {
        "com.android.settings.MultiSimSettings",
    };

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "enabling/disabling multisim activities");
        for (String activity : ACTIVITIES) {
            enableComponent(context, activity,
                    MSimTelephonyManager.getDefault().isMultiSimEnabled());
        }
    }

    private void enableComponent(Context context, String klass, boolean enable) {
        ComponentName name = new ComponentName(context, klass);
        PackageManager pm = context.getPackageManager();

        if (enable) {
            pm.setComponentEnabledSetting(name,
                    PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
                    PackageManager.DONT_KILL_APP);
        } else {
            pm.setComponentEnabledSetting(name,
                    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
        }
    }
}