// Path: app/src/main/java/com/kaliturin/blacklist/utils/DefaultSMSAppHelper.java
// public class DefaultSMSAppHelper {
// 
//     public static boolean isAvailable() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
//     }
// 
//     public static void updateState(Context context) {
//         boolean ready = isDefault(context);
//         enableSMSReceiving(context, ready);
//     }
// 
//     public static void enableSMSReceiving(Context context, boolean enable) {
//         int state = (enable ?
//                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
//                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
//         PackageManager packageManager = context.getPackageManager();
//         ComponentName componentName = new ComponentName(context, SMSBroadcastReceiver.class);
//         packageManager.setComponentEnabledSetting(
//                 componentName,
//                 state,
//                 PackageManager.DONT_KILL_APP);
//     }
// 
//     @TargetApi(19)
//     public static boolean isDefault(Context context) {
//         if (!isAvailable()) return true;
//         String myPackage = context.getPackageName();
//         String smsPackage = Telephony.Sms.getDefaultSmsPackage(context);
//         return (smsPackage != null && smsPackage.equals(myPackage));
//     }
// 
//     @TargetApi(19)
//     public static void askForDefaultAppChange(Fragment fragment, int requestCode) {
//         if (!isAvailable()) return;
//         Context context = fragment.getContext().getApplicationContext();
//         String packageName;
//         // current app package is already set as default
//         if (isDefault(context)) {
//             // get previously saved app package as default
//             packageName = Settings.getStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE);
//         } else {
//             // get blacklist app package as default
//             packageName = context.getPackageName();
//             // save current default sms app package to the settings
//             String nativePackage = Telephony.Sms.getDefaultSmsPackage(context);
//             if (nativePackage != null) {
//                 Settings.setStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE, nativePackage);
//             }
//         }
//         // start sms app change dialog
//         askForDefaultAppChange(fragment, packageName, requestCode);
//     }
// 
//     @TargetApi(19)
//     private static void askForDefaultAppChange(Fragment fragment, @Nullable String packageName, int requestCode) {
//         if (!isAvailable()) return;
//         Intent intent;
//         if (packageName == null) {
//             String action;
//             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//                 action = android.provider.Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
//             } else {
//                 action = android.provider.Settings.ACTION_WIRELESS_SETTINGS;
//             }
//             intent = new Intent(action);
//         } else {
//             intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
//             intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
//         }
//         fragment.startActivityForResult(intent, requestCode);
//     }
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.kaliturin.blacklist.utils.DefaultSMSAppHelper;
/*
 * Copyright (C) 2017 Anton Kaliturin <kaliturin@gmail.com>
 *
 * 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.kaliturin.blacklist.receivers;



/**
 * MMSBroadcastReceiver stub
 */

public class MMSBroadcastReceiver extends BroadcastReceiver {
    private static final String MMS_RECEIVED = "android.provider.Telephony.WAP_PUSH_RECEIVED";
    private static final String MMS_DELIVER = "android.provider.Telephony.WAP_PUSH_DELIVER";
    private static final String MMS_TYPE = "application/vnd.wap.mms-message";

    @Override
    public void onReceive(Context context, Intent intent) {
        // check action
        String action = intent.getAction();
        String type = intent.getType();
        if (action == null || type == null ||
                !action.equals(getAction()) ||
                !type.equals(MMS_TYPE)) {
            return;
        }

        // if not default sms app
// Path: app/src/main/java/com/kaliturin/blacklist/utils/DefaultSMSAppHelper.java
// public class DefaultSMSAppHelper {
// 
//     public static boolean isAvailable() {
//         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
//     }
// 
//     public static void updateState(Context context) {
//         boolean ready = isDefault(context);
//         enableSMSReceiving(context, ready);
//     }
// 
//     public static void enableSMSReceiving(Context context, boolean enable) {
//         int state = (enable ?
//                 PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
//                 PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
//         PackageManager packageManager = context.getPackageManager();
//         ComponentName componentName = new ComponentName(context, SMSBroadcastReceiver.class);
//         packageManager.setComponentEnabledSetting(
//                 componentName,
//                 state,
//                 PackageManager.DONT_KILL_APP);
//     }
// 
//     @TargetApi(19)
//     public static boolean isDefault(Context context) {
//         if (!isAvailable()) return true;
//         String myPackage = context.getPackageName();
//         String smsPackage = Telephony.Sms.getDefaultSmsPackage(context);
//         return (smsPackage != null && smsPackage.equals(myPackage));
//     }
// 
//     @TargetApi(19)
//     public static void askForDefaultAppChange(Fragment fragment, int requestCode) {
//         if (!isAvailable()) return;
//         Context context = fragment.getContext().getApplicationContext();
//         String packageName;
//         // current app package is already set as default
//         if (isDefault(context)) {
//             // get previously saved app package as default
//             packageName = Settings.getStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE);
//         } else {
//             // get blacklist app package as default
//             packageName = context.getPackageName();
//             // save current default sms app package to the settings
//             String nativePackage = Telephony.Sms.getDefaultSmsPackage(context);
//             if (nativePackage != null) {
//                 Settings.setStringValue(context, Settings.DEFAULT_SMS_APP_NATIVE_PACKAGE, nativePackage);
//             }
//         }
//         // start sms app change dialog
//         askForDefaultAppChange(fragment, packageName, requestCode);
//     }
// 
//     @TargetApi(19)
//     private static void askForDefaultAppChange(Fragment fragment, @Nullable String packageName, int requestCode) {
//         if (!isAvailable()) return;
//         Intent intent;
//         if (packageName == null) {
//             String action;
//             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//                 action = android.provider.Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS;
//             } else {
//                 action = android.provider.Settings.ACTION_WIRELESS_SETTINGS;
//             }
//             intent = new Intent(action);
//         } else {
//             intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
//             intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
//         }
//         fragment.startActivityForResult(intent, requestCode);
//     }
// }


// Path: app/src/main/java/com/kaliturin/blacklist/receivers/MMSBroadcastReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.kaliturin.blacklist.utils.DefaultSMSAppHelper;

/*
 * Copyright (C) 2017 Anton Kaliturin <kaliturin@gmail.com>
 *
 * 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.kaliturin.blacklist.receivers;



/**
 * MMSBroadcastReceiver stub
 */

public class MMSBroadcastReceiver extends BroadcastReceiver {
    private static final String MMS_RECEIVED = "android.provider.Telephony.WAP_PUSH_RECEIVED";
    private static final String MMS_DELIVER = "android.provider.Telephony.WAP_PUSH_DELIVER";
    private static final String MMS_TYPE = "application/vnd.wap.mms-message";

    @Override
    public void onReceive(Context context, Intent intent) {
        // check action
        String action = intent.getAction();
        String type = intent.getType();
        if (action == null || type == null ||
                !action.equals(getAction()) ||
                !type.equals(MMS_TYPE)) {
            return;
        }

        // if not default sms app
        if (!DefaultSMSAppHelper.isDefault(context)) {