添加单元测试模块,增加电话号码是否是数字的检测。
This commit is contained in:
		@@ -226,6 +226,8 @@
 | 
			
		||||
 | 
			
		||||
        <activity android:name="cc.winboll.studio.mymessagemanager.activitys.SMSRecycleActivity"/>
 | 
			
		||||
 | 
			
		||||
        <activity android:name="cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity"/>
 | 
			
		||||
 | 
			
		||||
    </application>
 | 
			
		||||
 | 
			
		||||
</manifest>
 | 
			
		||||
</manifest>
 | 
			
		||||
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 | 
			
		||||
import cc.winboll.studio.libaes.utils.AESThemeUtil;
 | 
			
		||||
import cc.winboll.studio.libaes.views.ASupportToolbar;
 | 
			
		||||
import androidx.appcompat.widget.Toolbar;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.unittest.UnitTestActivity;
 | 
			
		||||
 | 
			
		||||
public class MainActivity extends BaseActivity {
 | 
			
		||||
 | 
			
		||||
@@ -313,7 +314,11 @@ public class MainActivity extends BaseActivity {
 | 
			
		||||
            Intent i = new Intent(MainActivity.this, AppSettingsActivity.class);
 | 
			
		||||
            i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
 | 
			
		||||
            startActivity(i);
 | 
			
		||||
		} else if (nItemId ==  R.id.app_crashtest) {
 | 
			
		||||
		} else if (nItemId ==  R.id.app_unittest) {
 | 
			
		||||
            Intent i = new Intent(MainActivity.this, UnitTestActivity.class);
 | 
			
		||||
            i.setFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT | Intent.FLAG_ACTIVITY_NEW_TASK);
 | 
			
		||||
			startActivity(i);
 | 
			
		||||
        } else if (nItemId ==  R.id.app_crashtest) {
 | 
			
		||||
            for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
 | 
			
		||||
                getString(i);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@ import cc.winboll.studio.mymessagemanager.utils.SMSRecycleUtil;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.utils.SMSUtil;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.utils.TTSPlayRuleUtil;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.utils.RegexPPiUtils;
 | 
			
		||||
import cc.winboll.studio.shared.log.LogUtils;
 | 
			
		||||
 | 
			
		||||
public class SMSRecevier extends BroadcastReceiver {
 | 
			
		||||
 | 
			
		||||
@@ -39,25 +40,11 @@ public class SMSRecevier extends BroadcastReceiver {
 | 
			
		||||
            //LogUtils.d(TAG, "ACTION_SMS_RECEIVED");
 | 
			
		||||
            String szSmsBody = SMSUtil.getSmsBody(intent);
 | 
			
		||||
            String szSmsAddress = SMSUtil.getSmsAddress(intent);
 | 
			
		||||
            PhoneUtil phoneUtil = new PhoneUtil(context);
 | 
			
		||||
            boolean isPhoneInContacts = phoneUtil.isPhoneInContacts(szSmsAddress);
 | 
			
		||||
            AppConfigUtil configUtil = AppConfigUtil.getInstance(context);
 | 
			
		||||
            boolean isOnlyReceiveContacts = configUtil.mAppConfigBean.isEnableOnlyReceiveContacts();
 | 
			
		||||
            boolean isEnableTTS = configUtil.mAppConfigBean.isEnableTTS();
 | 
			
		||||
            boolean isEnableTTSAnalyzeMode = configUtil.mAppConfigBean.isEnableTTSRuleMode();
 | 
			
		||||
            boolean isInSMSAcceptRule = SMSReceiveRuleUtil.getInstance(context, false).checkIsSMSAcceptInRule(context, szSmsBody);
 | 
			
		||||
            //LogUtils.d(TAG, "isInSMSAcceptRule is : " + Boolean.toString(isInSMSAcceptRule));
 | 
			
		||||
 | 
			
		||||
            if (!isPhoneInContacts) {
 | 
			
		||||
                GlobalApplication.showApplicationMessage(" The phone number " + szSmsAddress + " is not in contacts.");
 | 
			
		||||
                if (isOnlyReceiveContacts) {
 | 
			
		||||
                    GlobalApplication.showApplicationMessage("Close the \"Only Receive Contacts\" switch will be receive The " + szSmsAddress + "'s message in future.");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ((!isOnlyReceiveContacts)
 | 
			
		||||
                || isPhoneInContacts
 | 
			
		||||
                || isInSMSAcceptRule) {
 | 
			
		||||
            if (checkIsSMSOK(context, szSmsBody, szSmsAddress)) {
 | 
			
		||||
                int nResultId = SMSUtil.saveReceiveSms(context, szSmsAddress, szSmsBody, "0", System.currentTimeMillis(), "inbox");
 | 
			
		||||
                if (nResultId >= 0) {
 | 
			
		||||
                    NotificationUtil nu = new NotificationUtil();
 | 
			
		||||
@@ -81,12 +68,32 @@ public class SMSRecevier extends BroadcastReceiver {
 | 
			
		||||
                SMSRecycleUtil.addSMSRecycleItem(context, bean);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    // 检查短信是否在接收设定规则内
 | 
			
		||||
    //
 | 
			
		||||
    public static boolean checkIsSMSOK(Context context, String szSmsBody, String szSmsAddress) {
 | 
			
		||||
        PhoneUtil phoneUtil = new PhoneUtil(context);
 | 
			
		||||
        boolean isPhoneInContacts = phoneUtil.isPhoneInContacts(szSmsAddress);
 | 
			
		||||
        LogUtils.d(TAG, String.format("isPhoneInContacts %s", isPhoneInContacts));
 | 
			
		||||
        
 | 
			
		||||
        boolean isPhoneByDigit = phoneUtil.isPhoneByDigit(szSmsAddress);
 | 
			
		||||
        LogUtils.d(TAG, String.format("isPhoneByDigit %s", isPhoneByDigit));
 | 
			
		||||
        
 | 
			
		||||
        AppConfigUtil configUtil = AppConfigUtil.getInstance(context);
 | 
			
		||||
        boolean isOnlyReceiveContacts = configUtil.mAppConfigBean.isEnableOnlyReceiveContacts();
 | 
			
		||||
        LogUtils.d(TAG, String.format("isOnlyReceiveContacts %s", isOnlyReceiveContacts));
 | 
			
		||||
        
 | 
			
		||||
        boolean isInSMSAcceptRule = SMSReceiveRuleUtil.getInstance(context, false).checkIsSMSAcceptInRule(context, szSmsBody);
 | 
			
		||||
        LogUtils.d(TAG, String.format("isInSMSAcceptRule %s", isInSMSAcceptRule));
 | 
			
		||||
        
 | 
			
		||||
        if (isPhoneByDigit 
 | 
			
		||||
            && (!isOnlyReceiveContacts || isPhoneInContacts || isInSMSAcceptRule)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
package cc.winboll.studio.mymessagemanager.unittest;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author ZhanGSKen@AliYun.Com
 | 
			
		||||
 * @Date 2025/02/25 19:02:15
 | 
			
		||||
 * @Describe SMSRecevier 测试类
 | 
			
		||||
 */
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.utils.SMSReceiveRuleUtil;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import cc.winboll.studio.shared.log.LogUtils;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.receivers.SMSRecevier;
 | 
			
		||||
 | 
			
		||||
public class SMSRecevier_Test {
 | 
			
		||||
 | 
			
		||||
    public static final String TAG = "SMSRecevier_Test";
 | 
			
		||||
 | 
			
		||||
    public static void main(Context context) {
 | 
			
		||||
        String szSmsBody = "无影无迹";
 | 
			
		||||
        String szSmsAddress = "无名小辈";
 | 
			
		||||
        test1(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        
 | 
			
		||||
        szSmsBody = "无影无迹";
 | 
			
		||||
        szSmsAddress = "1?0";
 | 
			
		||||
        test1(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        
 | 
			
		||||
        szSmsBody = "无影无迹";
 | 
			
		||||
        szSmsAddress = "10000";
 | 
			
		||||
        test1(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        
 | 
			
		||||
        szSmsBody = "【UC】无影无迹";
 | 
			
		||||
        szSmsAddress = "无名小辈";
 | 
			
		||||
        test1(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        
 | 
			
		||||
        szSmsBody = "【UC】无影无迹";
 | 
			
		||||
        szSmsAddress = "10000";
 | 
			
		||||
        test1(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public static void test1(Context context, String szSmsBody, String szSmsAddress) {
 | 
			
		||||
        
 | 
			
		||||
        boolean isSMSOK = SMSRecevier.checkIsSMSOK(context, szSmsBody, szSmsAddress);
 | 
			
		||||
        LogUtils.d(TAG, String.format("szSmsBody : %s\nszSmsAddress : %s\nisSMSOK : %s", szSmsBody, szSmsAddress, isSMSOK));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
package cc.winboll.studio.mymessagemanager.unittest;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author ZhanGSKen@AliYun.Com
 | 
			
		||||
 * @Date 2025/02/25 19:00:10
 | 
			
		||||
 * @Describe 应用单元测试窗口
 | 
			
		||||
 */
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.unittest.*;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import cc.winboll.studio.mymessagemanager.R;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import cc.winboll.studio.shared.log.LogView;
 | 
			
		||||
 | 
			
		||||
public class UnitTestActivity extends Activity {
 | 
			
		||||
 | 
			
		||||
    public static final String TAG = "UnitTestActivity";
 | 
			
		||||
 | 
			
		||||
    LogView mLogView;
 | 
			
		||||
    
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(R.layout.activity_unittest);
 | 
			
		||||
        
 | 
			
		||||
        mLogView = findViewById(R.id.logview);
 | 
			
		||||
        mLogView.start();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onMain(View view) {
 | 
			
		||||
        SMSRecevier_Test.main(this);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -15,6 +15,9 @@ import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import cc.winboll.studio.shared.log.LogUtils;
 | 
			
		||||
 | 
			
		||||
public class PhoneUtil {
 | 
			
		||||
 | 
			
		||||
@@ -67,4 +70,23 @@ public class PhoneUtil {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //
 | 
			
		||||
    // 检验电话号码是否是数字
 | 
			
		||||
    //
 | 
			
		||||
    public static boolean isPhoneByDigit(String szPhone) {
 | 
			
		||||
        if(!RegexPPiUtils.isPPiOK(szPhone)) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        //String text = "这里是一些任意的文本内容";
 | 
			
		||||
        String regex = "\\d+";
 | 
			
		||||
        Pattern pattern = Pattern.compile(regex);
 | 
			
		||||
        Matcher matcher = pattern.matcher(szPhone);
 | 
			
		||||
        LogUtils.d(TAG, String.format("matcher.matches() : %s", matcher.matches()));
 | 
			
		||||
        /*if (matcher.matches()) {
 | 
			
		||||
         System.out.println("文本满足该正则表达式模式");
 | 
			
		||||
         } else {
 | 
			
		||||
         System.out.println("文本不满足该正则表达式模式");
 | 
			
		||||
         }*/
 | 
			
		||||
        return matcher.matches();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -194,9 +194,9 @@ public class SMSReceiveRuleUtil {
 | 
			
		||||
    public ArrayList<SMSAcceptRuleBean> loadConfigData() {
 | 
			
		||||
        ArrayList<SMSAcceptRuleBean> list = new ArrayList<SMSAcceptRuleBean>();
 | 
			
		||||
        SMSAcceptRuleBean.loadBeanList(mContext, list, SMSAcceptRuleBean.class);
 | 
			
		||||
        for (int i = 0; i < list.size(); i++) {
 | 
			
		||||
            LogUtils.d(TAG, "loadConfigData isEnable : " + Boolean.toString(list.get(i).isEnable()));
 | 
			
		||||
        }
 | 
			
		||||
//        for (int i = 0; i < list.size(); i++) {
 | 
			
		||||
//            LogUtils.d(TAG, "loadConfigData isEnable : " + Boolean.toString(list.get(i).isEnable()));
 | 
			
		||||
//        }
 | 
			
		||||
        mDataList.clear();
 | 
			
		||||
        mDataList.addAll(list);
 | 
			
		||||
        return mDataList;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										44
									
								
								mymessagemanager/src/main/res/layout/activity_unittest.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								mymessagemanager/src/main/res/layout/activity_unittest.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<LinearLayout
 | 
			
		||||
	xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
	xmlns:app="http://schemas.android.com/apk/res-auto"
 | 
			
		||||
	android:orientation="vertical"
 | 
			
		||||
	android:layout_width="match_parent"
 | 
			
		||||
	android:layout_height="match_parent">
 | 
			
		||||
 | 
			
		||||
	<ScrollView
 | 
			
		||||
		android:layout_width="match_parent"
 | 
			
		||||
		android:layout_height="500dp">
 | 
			
		||||
 | 
			
		||||
		<LinearLayout
 | 
			
		||||
			android:orientation="vertical"
 | 
			
		||||
			android:layout_width="match_parent"
 | 
			
		||||
			android:layout_height="wrap_content">
 | 
			
		||||
 | 
			
		||||
			<LinearLayout
 | 
			
		||||
				android:orientation="horizontal"
 | 
			
		||||
				android:layout_width="match_parent"
 | 
			
		||||
				android:layout_height="wrap_content"
 | 
			
		||||
				android:gravity="right">
 | 
			
		||||
 | 
			
		||||
				<Button
 | 
			
		||||
					android:layout_width="wrap_content"
 | 
			
		||||
					android:layout_height="wrap_content"
 | 
			
		||||
					android:text="Test Main"
 | 
			
		||||
					android:onClick="onMain"
 | 
			
		||||
					android:textAllCaps="false"/>
 | 
			
		||||
 | 
			
		||||
			</LinearLayout>
 | 
			
		||||
 | 
			
		||||
		</LinearLayout>
 | 
			
		||||
 | 
			
		||||
	</ScrollView>
 | 
			
		||||
 | 
			
		||||
	<cc.winboll.studio.shared.log.LogView
 | 
			
		||||
		android:layout_width="match_parent"
 | 
			
		||||
		android:layout_height="0dp"
 | 
			
		||||
		android:layout_weight="1.0"
 | 
			
		||||
		android:id="@+id/logview"/>
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
 | 
			
		||||
@@ -19,6 +19,9 @@
 | 
			
		||||
        android:title="@string/text_smsrule"/>
 | 
			
		||||
    <item android:title="@string/app_developoptions">
 | 
			
		||||
        <menu>
 | 
			
		||||
            <item
 | 
			
		||||
                android:id="@+id/app_unittest"
 | 
			
		||||
                android:title="@string/app_unittest"/>
 | 
			
		||||
            <item
 | 
			
		||||
                android:id="@+id/app_crashtest"
 | 
			
		||||
                android:title="@string/app_crashtest"/>
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
    <string name="app_goldentheme">辉煌历程主题</string>
 | 
			
		||||
    <string name="app_developoptions">开发选项</string>
 | 
			
		||||
    <string name="app_default_app_settings">默认应用设置</string>
 | 
			
		||||
    <string name="app_unittest">单元测试</string>
 | 
			
		||||
    <string name="app_crashtest">应用异常崩溃处理测试</string>
 | 
			
		||||
    <string name="app_about">关于应用</string>
 | 
			
		||||
    <string name="app_smsrecycle">短信回收站</string>
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
    <string name="app_goldentheme">Golden Theme</string>
 | 
			
		||||
    <string name="app_developoptions">Develop Options</string>
 | 
			
		||||
    <string name="app_default_app_settings">Default App Settings</string>
 | 
			
		||||
    <string name="app_unittest">Unit Test</string>
 | 
			
		||||
    <string name="app_crashtest">Crash Test</string>
 | 
			
		||||
    <string name="app_about">About APP</string>
 | 
			
		||||
    <string name="app_smsrecycle">SMS Recycle</string>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user