SOS 服务架构基本完成
This commit is contained in:
		@@ -29,7 +29,7 @@ android {
 | 
				
			|||||||
        // versionName 更新后需要手动设置 
 | 
					        // versionName 更新后需要手动设置 
 | 
				
			||||||
        // .winboll/winbollBuildProps.properties 文件的 stageCount=0
 | 
					        // .winboll/winbollBuildProps.properties 文件的 stageCount=0
 | 
				
			||||||
        // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
 | 
					        // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0"
 | 
				
			||||||
        versionName "1.4" 
 | 
					        versionName "1.5" 
 | 
				
			||||||
        if(true) {
 | 
					        if(true) {
 | 
				
			||||||
            versionName = genVersionName("${versionName}")
 | 
					            versionName = genVersionName("${versionName}")
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
#Created by .winboll/winboll_app_build.gradle
 | 
					#Created by .winboll/winboll_app_build.gradle
 | 
				
			||||||
#Wed Feb 12 19:45:53 GMT 2025
 | 
					#Wed Feb 12 22:48:52 GMT 2025
 | 
				
			||||||
stageCount=2
 | 
					stageCount=0
 | 
				
			||||||
libraryProject=libappbase
 | 
					libraryProject=libappbase
 | 
				
			||||||
baseVersion=1.4
 | 
					baseVersion=1.5
 | 
				
			||||||
publishVersion=1.4.1
 | 
					publishVersion=1.5.0
 | 
				
			||||||
buildCount=22
 | 
					buildCount=0
 | 
				
			||||||
baseBetaVersion=1.4.2
 | 
					baseBetaVersion=1.5.1
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ public class App extends GlobalApplication {
 | 
				
			|||||||
    public void onCreate() {
 | 
					    public void onCreate() {
 | 
				
			||||||
        super.onCreate();
 | 
					        super.onCreate();
 | 
				
			||||||
        GlobalApplication.setIsDebuging(this, BuildConfig.DEBUG);
 | 
					        GlobalApplication.setIsDebuging(this, BuildConfig.DEBUG);
 | 
				
			||||||
        mSOSCSBroadcastReceiver = new SOSCSBroadcastReceiver();
 | 
					        mSOSCSBroadcastReceiver = new SOSCSBroadcastReceiver(this);
 | 
				
			||||||
        IntentFilter intentFilter = new IntentFilter();
 | 
					        IntentFilter intentFilter = new IntentFilter();
 | 
				
			||||||
        intentFilter.addAction(SOSCSBroadcastReceiver.ACTION_SOS);
 | 
					        intentFilter.addAction(SOSCSBroadcastReceiver.ACTION_SOS);
 | 
				
			||||||
        registerReceiver(mSOSCSBroadcastReceiver, intentFilter);
 | 
					        registerReceiver(mSOSCSBroadcastReceiver, intentFilter);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package cc.winboll.studio.appbase;
 | 
					package cc.winboll.studio.appbase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.content.ComponentName;
 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
@@ -10,7 +11,10 @@ import cc.winboll.studio.appbase.R;
 | 
				
			|||||||
import cc.winboll.studio.libappbase.GlobalApplication;
 | 
					import cc.winboll.studio.libappbase.GlobalApplication;
 | 
				
			||||||
import cc.winboll.studio.libappbase.LogUtils;
 | 
					import cc.winboll.studio.libappbase.LogUtils;
 | 
				
			||||||
import cc.winboll.studio.libappbase.LogView;
 | 
					import cc.winboll.studio.libappbase.LogView;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.SOSCSBroadcastReceiver;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.SimpleOperateSignalCenterService;
 | 
				
			||||||
import com.hjq.toast.ToastUtils;
 | 
					import com.hjq.toast.ToastUtils;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.ISOSAPP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class MainActivity extends AppCompatActivity {
 | 
					public class MainActivity extends AppCompatActivity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -45,11 +49,41 @@ public class MainActivity extends AppCompatActivity {
 | 
				
			|||||||
        GlobalApplication.setIsDebuging(this, ((CheckBox)view).isChecked());
 | 
					        GlobalApplication.setIsDebuging(this, ((CheckBox)view).isChecked());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onStartCenter(View view) {
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterService.startISOSService(this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onStopCenter(View view) {
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterService.stopISOSService(this);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onTestStopWithoutSettingEnable(View view) {
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "onTestStopWithoutSettingEnable");
 | 
				
			||||||
 | 
					        stopService(new Intent(this, SimpleOperateSignalCenterService.class));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onTestStartWithString(View view) {
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "onTestStartWithString");
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 目标服务的包名和类名
 | 
				
			||||||
 | 
					        String packageName = this.getPackageName();
 | 
				
			||||||
 | 
					        String serviceClassName = SimpleOperateSignalCenterService.class.getName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 构建Intent
 | 
				
			||||||
 | 
					        Intent intentService = new Intent();
 | 
				
			||||||
 | 
					        intentService.setComponent(new ComponentName(packageName, serviceClassName));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        startService(intentService);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void onSOS(View view) {
 | 
					    public void onSOS(View view) {
 | 
				
			||||||
        // 创建Intent对象,指定广播的action
 | 
					        // 创建Intent对象,指定广播的action
 | 
				
			||||||
        Intent intent = new Intent("cc.winboll.studio.libappbase.SOSCSBroadcastReceiver.ACTION_SOS");
 | 
					        Intent intent = new Intent(SOSCSBroadcastReceiver.ACTION_SOS);
 | 
				
			||||||
        // 可以添加额外的数据
 | 
					        // 目标服务的包名和类名
 | 
				
			||||||
        intent.putExtra("data", "这是广播携带的数据");
 | 
					        String packageName = this.getPackageName();
 | 
				
			||||||
 | 
					        String serviceClassName = SimpleOperateSignalCenterService.class.getName();
 | 
				
			||||||
 | 
					        intent.putExtra(ISOSAPP.EXTRA_PACKAGE, packageName);
 | 
				
			||||||
 | 
					        intent.putExtra(ISOSAPP.EXTRA_SERVICE, serviceClassName);
 | 
				
			||||||
        // 发送广播
 | 
					        // 发送广播
 | 
				
			||||||
        sendBroadcast(intent);
 | 
					        sendBroadcast(intent);
 | 
				
			||||||
        LogUtils.d(TAG, "onSOS");
 | 
					        LogUtils.d(TAG, "onSOS");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,11 +48,39 @@
 | 
				
			|||||||
		</LinearLayout>
 | 
							</LinearLayout>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		<LinearLayout
 | 
							<LinearLayout
 | 
				
			||||||
			android:orientation="horizontal"
 | 
								android:orientation="vertical"
 | 
				
			||||||
			android:layout_width="match_parent"
 | 
								android:layout_width="match_parent"
 | 
				
			||||||
			android:layout_height="wrap_content"
 | 
								android:layout_height="wrap_content"
 | 
				
			||||||
			android:gravity="right">
 | 
								android:gravity="right">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								<Button
 | 
				
			||||||
 | 
									android:layout_width="wrap_content"
 | 
				
			||||||
 | 
									android:layout_height="wrap_content"
 | 
				
			||||||
 | 
									android:text="StartCenter"
 | 
				
			||||||
 | 
									android:textAllCaps="false"
 | 
				
			||||||
 | 
									android:onClick="onStartCenter"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								<Button
 | 
				
			||||||
 | 
									android:layout_width="wrap_content"
 | 
				
			||||||
 | 
									android:layout_height="wrap_content"
 | 
				
			||||||
 | 
									android:text="StopCenter"
 | 
				
			||||||
 | 
									android:textAllCaps="false"
 | 
				
			||||||
 | 
									android:onClick="onStopCenter"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <Button
 | 
				
			||||||
 | 
					                android:layout_width="wrap_content"
 | 
				
			||||||
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                android:text="TestStopWithoutSettingEnable"
 | 
				
			||||||
 | 
									android:textAllCaps="false"
 | 
				
			||||||
 | 
					                android:onClick="onTestStopWithoutSettingEnable"/>
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
								<Button
 | 
				
			||||||
 | 
									android:layout_width="wrap_content"
 | 
				
			||||||
 | 
									android:layout_height="wrap_content"
 | 
				
			||||||
 | 
									android:text="TestStartWithString"
 | 
				
			||||||
 | 
									android:textAllCaps="false"
 | 
				
			||||||
 | 
									android:onClick="onTestStartWithString"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			<Button
 | 
								<Button
 | 
				
			||||||
				android:layout_width="wrap_content"
 | 
									android:layout_width="wrap_content"
 | 
				
			||||||
				android:layout_height="wrap_content"
 | 
									android:layout_height="wrap_content"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
#Created by .winboll/winboll_app_build.gradle
 | 
					#Created by .winboll/winboll_app_build.gradle
 | 
				
			||||||
#Wed Feb 12 19:45:53 GMT 2025
 | 
					#Wed Feb 12 22:48:52 GMT 2025
 | 
				
			||||||
stageCount=2
 | 
					stageCount=2
 | 
				
			||||||
libraryProject=libappbase
 | 
					libraryProject=libappbase
 | 
				
			||||||
baseVersion=1.4
 | 
					baseVersion=1.4
 | 
				
			||||||
publishVersion=1.4.1
 | 
					publishVersion=1.4.1
 | 
				
			||||||
buildCount=22
 | 
					buildCount=51
 | 
				
			||||||
baseBetaVersion=1.4.2
 | 
					baseBetaVersion=1.4.2
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,9 @@ package cc.winboll.studio.libappbase;
 | 
				
			|||||||
 * @Describe 全局应用类
 | 
					 * @Describe 全局应用类
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
import android.app.Application;
 | 
					import android.app.Application;
 | 
				
			||||||
 | 
					import android.content.ComponentName;
 | 
				
			||||||
import android.content.Context;
 | 
					import android.content.Context;
 | 
				
			||||||
 | 
					import android.content.Intent;
 | 
				
			||||||
import android.content.SharedPreferences;
 | 
					import android.content.SharedPreferences;
 | 
				
			||||||
import android.content.pm.ApplicationInfo;
 | 
					import android.content.pm.ApplicationInfo;
 | 
				
			||||||
import android.content.pm.PackageManager;
 | 
					import android.content.pm.PackageManager;
 | 
				
			||||||
@@ -16,7 +18,7 @@ import android.view.Gravity;
 | 
				
			|||||||
import com.hjq.toast.ToastUtils;
 | 
					import com.hjq.toast.ToastUtils;
 | 
				
			||||||
import com.hjq.toast.style.WhiteToastStyle;
 | 
					import com.hjq.toast.style.WhiteToastStyle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class GlobalApplication extends Application {
 | 
					public class GlobalApplication extends Application implements ISOSAPP {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static final String TAG = "GlobalApplication";
 | 
					    public static final String TAG = "GlobalApplication";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -91,4 +93,27 @@ public class GlobalApplication extends Application {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return null;
 | 
					        return null;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void helpISOSService(Intent intent) {
 | 
				
			||||||
 | 
					        String szServiceName = intent.getStringExtra(EXTRA_SERVICE);
 | 
				
			||||||
 | 
					        String szPackageName = intent.getStringExtra(EXTRA_PACKAGE);
 | 
				
			||||||
 | 
					        if (szServiceName != null && !szServiceName.equals("")
 | 
				
			||||||
 | 
					            && szPackageName != null && !szPackageName.equals("")) {
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "szPackageName " + szPackageName);
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "szServiceName " + szServiceName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 目标服务的包名和类名
 | 
				
			||||||
 | 
					            //String packageName = this.getPackageName();
 | 
				
			||||||
 | 
					            //String serviceClassName = SimpleOperateSignalCenterService.class.getName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 构建Intent
 | 
				
			||||||
 | 
					            Intent intentService = new Intent();
 | 
				
			||||||
 | 
					            intentService.setComponent(new ComponentName(szPackageName, szServiceName));
 | 
				
			||||||
 | 
					            intentService.putExtra(ISOSService.EXTRA_ENABLE, true);
 | 
				
			||||||
 | 
					            startService(intentService);
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "startService(intentService)");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "helpISOSService");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					package cc.winboll.studio.libappbase;
 | 
				
			||||||
 | 
					import android.content.Intent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @Author ZhanGSKen@AliYun.Com
 | 
				
			||||||
 | 
					 * @Date 2025/02/13 03:49:35
 | 
				
			||||||
 | 
					 * @Describe 简单 SOS 接口
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public interface ISOSAPP {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static final String TAG = "ISOS";
 | 
				
			||||||
 | 
					    public static final String EXTRA_PACKAGE = "EXTRA_PACKAGE";
 | 
				
			||||||
 | 
					    public static final String EXTRA_SERVICE = "EXTRA_SERVICE";
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public void helpISOSService(Intent intent);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					package cc.winboll.studio.libappbase;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @Author ZhanGSKen@AliYun.Com
 | 
				
			||||||
 | 
					 * @Date 2025/02/13 04:13:51
 | 
				
			||||||
 | 
					 * @Describe 简单链接 SOS 体系的服务
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					import android.content.Intent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public interface ISOSService {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static final String TAG = "ISOSService";
 | 
				
			||||||
 | 
					    public static final String EXTRA_ENABLE = "EXTRA_ENABLE";
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public Intent getISOSServiceIntentWhichAskForHelp();
 | 
				
			||||||
 | 
					    public boolean isEnable();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -14,14 +14,19 @@ public class SOSCSBroadcastReceiver extends BroadcastReceiver {
 | 
				
			|||||||
    public static final String TAG = "SOSCSBroadcastReceiver";
 | 
					    public static final String TAG = "SOSCSBroadcastReceiver";
 | 
				
			||||||
    public static final String ACTION_SOS = SOSCSBroadcastReceiver.class.getName() + ".ACTION_SOS";
 | 
					    public static final String ACTION_SOS = SOSCSBroadcastReceiver.class.getName() + ".ACTION_SOS";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ISOSAPP mISOSAPP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SOSCSBroadcastReceiver(ISOSAPP iSOSAPP) {
 | 
				
			||||||
 | 
					        mISOSAPP = iSOSAPP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onReceive(Context context, Intent intent) {
 | 
					    public void onReceive(Context context, Intent intent) {
 | 
				
			||||||
        String action = intent.getAction();
 | 
					        String action = intent.getAction();
 | 
				
			||||||
        if(action.equals(context.getString(R.string.action_sos))) {
 | 
					        if (action.equals(ACTION_SOS)) {
 | 
				
			||||||
            LogUtils.d(TAG, "action_sos");
 | 
					            LogUtils.d(TAG, "ACTION_SOS");
 | 
				
			||||||
 | 
					            mISOSAPP.helpISOSService(intent);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            LogUtils.d(TAG, String.format("action %s", action));
 | 
					            LogUtils.d(TAG, String.format("%s", action));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,12 +7,25 @@ package cc.winboll.studio.libappbase;
 | 
				
			|||||||
 * @Describe 简单信号服务中心
 | 
					 * @Describe 简单信号服务中心
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
import android.app.Service;
 | 
					import android.app.Service;
 | 
				
			||||||
 | 
					import android.content.Context;
 | 
				
			||||||
import android.content.Intent;
 | 
					import android.content.Intent;
 | 
				
			||||||
import android.os.IBinder;
 | 
					import android.os.IBinder;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.bean.SimpleOperateSignalCenterServiceBean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class SimpleOperateSignalCenterService extends Service {
 | 
					public class SimpleOperateSignalCenterService extends Service implements ISOSService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static final String TAG = "SimpleOperateSignalCenterService";
 | 
					    public static final String TAG = "SimpleOperateSignalCenterService";
 | 
				
			||||||
 | 
					    public static final String ACTION_ENABLE = SimpleOperateSignalCenterService.class.getName() + ".ACTION_ENABLE";
 | 
				
			||||||
 | 
					    public static final String ACTION_DISABLE = SimpleOperateSignalCenterService.class.getName() + ".ACTION_DISABLE";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SimpleOperateSignalCenterServiceBean mSimpleOperateSignalCenterServiceBean;
 | 
				
			||||||
 | 
					    static MainThread _MainThread;
 | 
				
			||||||
 | 
					    public static synchronized MainThread getMainThreadInstance() {
 | 
				
			||||||
 | 
					        if (_MainThread == null) {
 | 
				
			||||||
 | 
					            _MainThread = new MainThread();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return _MainThread;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public IBinder onBind(Intent intent) {
 | 
					    public IBinder onBind(Intent intent) {
 | 
				
			||||||
@@ -22,10 +35,103 @@ public class SimpleOperateSignalCenterService extends Service {
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onCreate() {
 | 
					    public void onCreate() {
 | 
				
			||||||
        super.onCreate();
 | 
					        super.onCreate();
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "onCreate");
 | 
				
			||||||
 | 
					        mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
 | 
				
			||||||
 | 
					        runMainThread();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public int onStartCommand(Intent intent, int flags, int startId) {
 | 
					    public int onStartCommand(Intent intent, int flags, int startId) {
 | 
				
			||||||
        return super.onStartCommand(intent, flags, startId);
 | 
					        LogUtils.d(TAG, "onStartCommand");
 | 
				
			||||||
 | 
					        if (intent.getBooleanExtra(ISOSService.EXTRA_ENABLE, false)) {
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "onStartCommand enable service");
 | 
				
			||||||
 | 
					            mSimpleOperateSignalCenterServiceBean.setIsEnable(true);
 | 
				
			||||||
 | 
					            SimpleOperateSignalCenterServiceBean.saveBean(this, mSimpleOperateSignalCenterServiceBean);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        runMainThread();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //return super.onStartCommand(intent, flags, startId);
 | 
				
			||||||
 | 
					        return mSimpleOperateSignalCenterServiceBean.isEnable() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void runMainThread() {
 | 
				
			||||||
 | 
					        mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
 | 
				
			||||||
 | 
					        if (mSimpleOperateSignalCenterServiceBean.isEnable()
 | 
				
			||||||
 | 
					            && _MainThread == null) {
 | 
				
			||||||
 | 
					            getMainThreadInstance().start();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public Intent getISOSServiceIntentWhichAskForHelp() {
 | 
				
			||||||
 | 
					        Intent intentService = new Intent();
 | 
				
			||||||
 | 
					        intentService.putExtra(ISOSAPP.EXTRA_PACKAGE, this.getPackageName());
 | 
				
			||||||
 | 
					        intentService.putExtra(ISOSAPP.EXTRA_SERVICE, this.getClass().getName());
 | 
				
			||||||
 | 
					        return intentService;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isEnable() {
 | 
				
			||||||
 | 
					        mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
 | 
				
			||||||
 | 
					        return mSimpleOperateSignalCenterServiceBean.isEnable();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void onDestroy() {
 | 
				
			||||||
 | 
					        super.onDestroy();
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "onDestroy");
 | 
				
			||||||
 | 
					        mSimpleOperateSignalCenterServiceBean = SimpleOperateSignalCenterServiceBean.loadBean(this, SimpleOperateSignalCenterServiceBean.class);
 | 
				
			||||||
 | 
					        if (mSimpleOperateSignalCenterServiceBean.isEnable()) {
 | 
				
			||||||
 | 
					            LogUtils.d(TAG, "mSimpleOperateSignalCenterServiceBean.isEnable()");
 | 
				
			||||||
 | 
					            ISOSAPP iSOSAPP = (ISOSAPP)getApplication();
 | 
				
			||||||
 | 
					            iSOSAPP.helpISOSService(getISOSServiceIntentWhichAskForHelp());
 | 
				
			||||||
 | 
					        } 
 | 
				
			||||||
 | 
					        if (_MainThread != null) {
 | 
				
			||||||
 | 
					            _MainThread.isExist = true;
 | 
				
			||||||
 | 
					            _MainThread = null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void stopISOSService(Context context) {
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "stopISOSService");
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterServiceBean bean = new SimpleOperateSignalCenterServiceBean();
 | 
				
			||||||
 | 
					        bean.setIsEnable(false);
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterServiceBean.saveBean(context, bean);
 | 
				
			||||||
 | 
					        context.stopService(new Intent(context, SimpleOperateSignalCenterService.class));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void startISOSService(Context context) {
 | 
				
			||||||
 | 
					        LogUtils.d(TAG, "startISOSService");
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterServiceBean bean = new SimpleOperateSignalCenterServiceBean();
 | 
				
			||||||
 | 
					        bean.setIsEnable(true);
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterServiceBean.saveBean(context, bean);
 | 
				
			||||||
 | 
					        context.startService(new Intent(context, SimpleOperateSignalCenterService.class));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static class MainThread extends Thread {
 | 
				
			||||||
 | 
					        volatile boolean isExist = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void setIsExist(boolean isExist) {
 | 
				
			||||||
 | 
					            this.isExist = isExist;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public boolean isExist() {
 | 
				
			||||||
 | 
					            return isExist;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public void run() {
 | 
				
			||||||
 | 
					            super.run();
 | 
				
			||||||
 | 
					            while (!isExist) {
 | 
				
			||||||
 | 
					                LogUtils.d(TAG, "run");
 | 
				
			||||||
 | 
					                try {
 | 
				
			||||||
 | 
					                    sleep(1000);
 | 
				
			||||||
 | 
					                } catch (InterruptedException e) {
 | 
				
			||||||
 | 
					                    LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,67 @@
 | 
				
			|||||||
 | 
					package cc.winboll.studio.libappbase.bean;
 | 
				
			||||||
 | 
					import android.util.JsonReader;
 | 
				
			||||||
 | 
					import android.util.JsonWriter;
 | 
				
			||||||
 | 
					import cc.winboll.studio.libappbase.BaseBean;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @Author ZhanGSKen@AliYun.Com
 | 
				
			||||||
 | 
					 * @Date 2025/02/13 04:27:42
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class SimpleOperateSignalCenterServiceBean extends BaseBean {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static final String TAG = "SimpleOperateSignalCenterServiceBean";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    boolean isEnable;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public SimpleOperateSignalCenterServiceBean() {
 | 
				
			||||||
 | 
					        this.isEnable = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void setIsEnable(boolean isEnable) {
 | 
				
			||||||
 | 
					        this.isEnable = isEnable;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public boolean isEnable() {
 | 
				
			||||||
 | 
					        return isEnable;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String getName() {
 | 
				
			||||||
 | 
					        return SimpleOperateSignalCenterServiceBean.class.getName();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
 | 
				
			||||||
 | 
					        super.writeThisToJsonWriter(jsonWriter);
 | 
				
			||||||
 | 
					        SimpleOperateSignalCenterServiceBean bean = this;
 | 
				
			||||||
 | 
					        jsonWriter.name("isEnable").value(bean.isEnable());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
 | 
				
			||||||
 | 
					        if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
 | 
				
			||||||
 | 
					            if (name.equals("isEnable")) {
 | 
				
			||||||
 | 
					                setIsEnable(jsonReader.nextBoolean());
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
 | 
				
			||||||
 | 
					        jsonReader.beginObject();
 | 
				
			||||||
 | 
					        while (jsonReader.hasNext()) {
 | 
				
			||||||
 | 
					            String name = jsonReader.nextName();
 | 
				
			||||||
 | 
					            if (!initObjectsFromJsonReader(jsonReader, name)) {
 | 
				
			||||||
 | 
					                jsonReader.skipValue();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // 结束 JSON 对象
 | 
				
			||||||
 | 
					        jsonReader.endObject();
 | 
				
			||||||
 | 
					        return this;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,6 +3,5 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <string name="lib_name">libappbase</string>
 | 
					    <string name="lib_name">libappbase</string>
 | 
				
			||||||
    <string name="hello_world">Hello world!</string>
 | 
					    <string name="hello_world">Hello world!</string>
 | 
				
			||||||
    <string name="action_sos">cc.winboll.studio.libappbase.SOSCSBroadcastReceiver.ACTION_SOS</string>
 | 
					 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
</resources>
 | 
					</resources>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user