添加磁贴工具...

This commit is contained in:
ZhanGSKen 2025-04-15 10:57:19 +08:00
parent c302179960
commit 63b1d2dece
12 changed files with 284 additions and 30 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Wed Apr 02 21:25:51 HKT 2025 #Tue Apr 15 02:52:13 GMT 2025
stageCount=1 stageCount=1
libraryProject= libraryProject=
baseVersion=15.2 baseVersion=15.2
publishVersion=15.2.0 publishVersion=15.2.0
buildCount=0 buildCount=12
baseBetaVersion=15.2.1 baseBetaVersion=15.2.1

View File

@ -54,6 +54,21 @@
<service android:name=".services.AssistantService"/> <service android:name=".services.AssistantService"/>
<service
android:name=".AppBaseTileService"
android:exported="true"
android:label="@string/tileservice_name"
android:icon="@drawable/ic_launcher"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
</intent-filter>
</service>
<receiver <receiver
android:name=".receivers.MainReceiver" android:name=".receivers.MainReceiver"
android:enabled="true" android:enabled="true"

View File

@ -0,0 +1,83 @@
package cc.winboll.studio.autoinstaller;
import android.content.Context;
import android.service.quicksettings.Tile;
import android.service.quicksettings.TileService;
import cc.winboll.studio.autoinstaller.models.MainServiceBean;
import cc.winboll.studio.autoinstaller.services.MainService;
import cc.winboll.studio.autoinstaller.models.AppConfigs;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/04/15 09:24:46
* @Describe 磁贴工具服务类
*/
public class AppBaseTileService extends TileService {
public static final String TAG = "AppBaseTileService";
volatile static AppBaseTileService _AppBaseTileService;
@Override
public void onStartListening() {
super.onStartListening();
_AppBaseTileService = this;
Tile tile = getQsTile();
//MainServiceBean bean = MainServiceBean.loadBean(this, MainServiceBean.class);
if (AppConfigs.getInstance(AppBaseTileService.this).isEnableService()) {
//MainService.startMainService(context);
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud));
} else {
//MainService.stopMainService(context);
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud_outline));
}
tile.updateTile();
// Tile tile = getQsTile();
// tile.setState(Tile.STATE_INACTIVE);
// tile.setLabel(getString(R.string.tileservice_name));
// tile.setIcon(android.graphics.drawable.Icon.createWithResource(this, R.drawable.ic_cloud_outline));
// tile.updateTile();
}
@Override
public void onClick() {
super.onClick();
Tile tile = getQsTile();
// MainServiceBean bean = MainServiceBean.loadBean(this, MainServiceBean.class);
// if (bean == null) {
// bean = new MainServiceBean();
// }
if (tile.getState() == Tile.STATE_ACTIVE) {
// bean.setIsEnable(false);
// MainServiceBean.saveBean(this, bean);
AppConfigs.getInstance(AppBaseTileService.this).setIsEnableService(false);
AppConfigs.getInstance(AppBaseTileService.this).saveAppConfigs();
MainActivity.stopMainService();
} else if (tile.getState() == Tile.STATE_INACTIVE) {
AppConfigs.getInstance(AppBaseTileService.this).setIsEnableService(true);
AppConfigs.getInstance(AppBaseTileService.this).saveAppConfigs();
MainActivity.startMainService();
}
updateServiceIconStatus(this);
}
public static void updateServiceIconStatus(Context context) {
if (_AppBaseTileService == null) {
return;
}
Tile tile = _AppBaseTileService.getQsTile();
MainServiceBean bean = MainServiceBean.loadBean(context, MainServiceBean.class);
if (bean != null && bean.isEnable()) {
tile.setState(Tile.STATE_ACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(context, R.drawable.ic_cloud));
} else {
tile.setState(Tile.STATE_INACTIVE);
tile.setIcon(android.graphics.drawable.Icon.createWithResource(context, R.drawable.ic_cloud_outline));
}
tile.updateTile();
}
}

View File

@ -6,6 +6,8 @@ import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.RadioButton; import android.widget.RadioButton;
@ -30,8 +32,12 @@ import java.util.Map;
public class MainActivity extends Activity { public class MainActivity extends Activity {
public static final String TAG = "MainActivity"; public static final String TAG = "MainActivity";
public static final int MSG_UPDATE_STATUS = 0;
private static final int INSTALL_PERMISSION_CODE = 1; private static final int INSTALL_PERMISSION_CODE = 1;
static MainActivity _MainActivity;
ArrayList<APKModel> _APKModelList = new ArrayList<APKModel>(); ArrayList<APKModel> _APKModelList = new ArrayList<APKModel>();
LogView mLogView; LogView mLogView;
TextClock mTextClock; TextClock mTextClock;
@ -61,6 +67,7 @@ public class MainActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
_MainActivity = this;
initView(); initView();
if (getIntent().getAction().equals(ACTION_NEW_INSTALLTASK)) { if (getIntent().getAction().equals(ACTION_NEW_INSTALLTASK)) {
@ -77,11 +84,7 @@ public class MainActivity extends Activity {
mLogView = findViewById(R.id.logview); mLogView = findViewById(R.id.logview);
mLogView.start(); mLogView.start();
AppConfigs appConfigs = AppConfigs.loadAppConfigs(this); AppConfigs appConfigs = AppConfigs.getInstance(this).loadAppConfigs(this);
if (appConfigs == null) {
appConfigs = new AppConfigs();
AppConfigs.saveAppConfigs(this, appConfigs);
}
if (appConfigs.getSetupMode() == AppConfigs.SetupMode.WATCHOUTPUTINSTALLER) { if (appConfigs.getSetupMode() == AppConfigs.SetupMode.WATCHOUTPUTINSTALLER) {
((RadioButton)findViewById(R.id.activitymainRadioButton1)).setChecked(true); ((RadioButton)findViewById(R.id.activitymainRadioButton1)).setChecked(true);
@ -196,10 +199,15 @@ public class MainActivity extends Activity {
} }
public void onLockPath(View view) { public void onLockPath(View view) {
AppConfigs appConfigs = AppConfigs.loadAppConfigs(this);
Switch sw = (Switch)view; Switch sw = (Switch)view;
if (sw.isChecked()) { setMainServiceStatus(sw.isChecked());
}
public void setMainServiceStatus(boolean isEnable) {
AppConfigs appConfigs = AppConfigs.getInstance(this).loadAppConfigs(this);
Switch sw = (Switch)findViewById(R.id.activitymainSwitch1);
if (isEnable) {
String szFilePath = mEditText.getText().toString(); String szFilePath = mEditText.getText().toString();
// 设置空路径时退出 // 设置空路径时退出
@ -247,7 +255,7 @@ public class MainActivity extends Activity {
stopWatchingFile(); stopWatchingFile();
} }
AppConfigs.saveAppConfigs(this, appConfigs); AppConfigs.getInstance(this).saveAppConfigs(this, appConfigs);
} }
void stopWatchingFile() { void stopWatchingFile() {
@ -307,7 +315,7 @@ public class MainActivity extends Activity {
}*/ }*/
public void onChangeSetupMode(View view) { public void onChangeSetupMode(View view) {
AppConfigs appConfigs = AppConfigs.loadAppConfigs(this); AppConfigs appConfigs = AppConfigs.getInstance(this).loadAppConfigs(this);
if (view.getId() == R.id.activitymainRadioButton1) { if (view.getId() == R.id.activitymainRadioButton1) {
appConfigs.setSetupMode(AppConfigs.SetupMode.WATCHOUTPUTINSTALLER); appConfigs.setSetupMode(AppConfigs.SetupMode.WATCHOUTPUTINSTALLER);
@ -316,6 +324,42 @@ public class MainActivity extends Activity {
appConfigs.setSetupMode(AppConfigs.SetupMode.NEWAPKINFONEWAPKINFO); appConfigs.setSetupMode(AppConfigs.SetupMode.NEWAPKINFONEWAPKINFO);
((RadioButton)findViewById(R.id.activitymainRadioButton1)).setChecked(false); ((RadioButton)findViewById(R.id.activitymainRadioButton1)).setChecked(false);
} }
AppConfigs.saveAppConfigs(this, appConfigs); AppConfigs.getInstance(this).saveAppConfigs(this, appConfigs);
}
// 定义Handler
static Handler _Handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_UPDATE_STATUS) {
if (_MainActivity != null) {
boolean isEnableMainService = (boolean)msg.obj;
// 处理消息这里更新 MainService 的状态
_MainActivity.setMainServiceStatus(isEnableMainService);
}
}
}
};
static void updateMainServiceStatus(boolean isEnable) {
if (_Handler != null) {
Message msg = new Message();
msg.obj = isEnable;
msg.what = MSG_UPDATE_STATUS;
_Handler.sendMessage(msg);
}
}
public static void stopMainService() {
if (_MainActivity != null && _Handler != null) {
updateMainServiceStatus(false);
}
}
public static void startMainService() {
if (_MainActivity != null && _Handler != null) {
updateMainServiceStatus(true);
}
} }
} }

View File

@ -15,6 +15,8 @@ import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import android.drm.DrmConvertedStatus;
import com.hjq.toast.ToastUtils;
public class AppConfigs implements Serializable { public class AppConfigs implements Serializable {
@ -26,6 +28,20 @@ public class AppConfigs implements Serializable {
NEWAPKINFONEWAPKINFO // 调用[应用信息查看器]打开应用包 NEWAPKINFONEWAPKINFO // 调用[应用信息查看器]打开应用包
}; };
static volatile AppConfigs _AppConfigs;
Context mContext;
AppConfigs(Context context) {
mContext = context;
}
public static synchronized AppConfigs getInstance(Context context) {
if (_AppConfigs == null) {
_AppConfigs = new AppConfigs(context);
}
return _AppConfigs;
}
// 监控文件路径 // 监控文件路径
private String watchingFilePath = ""; private String watchingFilePath = "";
@ -85,8 +101,8 @@ public class AppConfigs implements Serializable {
return ""; return "";
} }
public static AppConfigs parseAppConfigs(String szAppConfigs) { public AppConfigs parseAppConfigs(String szAppConfigs) {
AppConfigs appConfigs = new AppConfigs(); AppConfigs appConfigs = new AppConfigs(mContext);
// 创建 JsonWriter 对象 // 创建 JsonWriter 对象
StringReader stringReader = new StringReader(szAppConfigs); StringReader stringReader = new StringReader(szAppConfigs);
JsonReader jsonReader = new JsonReader jsonReader = new
@ -122,19 +138,20 @@ public class AppConfigs implements Serializable {
return context.getExternalFilesDir(TAG) + "/" + TAG + ".json"; return context.getExternalFilesDir(TAG) + "/" + TAG + ".json";
} }
public static AppConfigs loadAppConfigs(Context context) { public AppConfigs loadAppConfigs(Context context) {
AppConfigs appConfigs = null; AppConfigs appConfigs = null;
try { try {
String szJson = FileUtil.readFile(getDataPath(context)); String szJson = FileUtil.readFile(getDataPath(context));
appConfigs = AppConfigs.parseAppConfigs(szJson); appConfigs = AppConfigs.getInstance(mContext).parseAppConfigs(szJson);
} catch (IOException e) { } catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace()); LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
} }
return appConfigs; return appConfigs;
} }
public static void saveAppConfigs(Context context, AppConfigs appConfigs) { public void saveAppConfigs(Context context, AppConfigs appConfigs) {
try { try {
ToastUtils.show(String.format("AppConfigs set enable service to %s", appConfigs.isEnableService()));
//LogUtils.d(TAG, "appConfigs is : " + appConfigs.toString()); //LogUtils.d(TAG, "appConfigs is : " + appConfigs.toString());
String szJson = appConfigs.toString(); String szJson = appConfigs.toString();
FileUtil.writeFile(getDataPath(context), szJson); FileUtil.writeFile(getDataPath(context), szJson);
@ -142,4 +159,8 @@ public class AppConfigs implements Serializable {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace()); LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
} }
} }
public void saveAppConfigs() {
saveAppConfigs(mContext, this);
}
} }

View File

@ -0,0 +1,67 @@
package cc.winboll.studio.autoinstaller.models;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import java.io.IOException;
/**
* @Author ZhanGSKen@AliYun.Com
* @Date 2025/04/15 09:27:39
* @Describe MainServiceBean
*/
public class MainServiceBean extends BaseBean {
public static final String TAG = "MainServiceBean";
boolean isEnable;
public MainServiceBean() {
this.isEnable = false;
}
public void setIsEnable(boolean isEnable) {
this.isEnable = isEnable;
}
public boolean isEnable() {
return isEnable;
}
@Override
public String getName() {
return MainServiceBean.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("isEnable").value(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;
}
}

View File

@ -23,7 +23,7 @@ public class MainReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
String szAction = intent.getAction(); String szAction = intent.getAction();
if (szAction.equals(ACTION_BOOT_COMPLETED)) { if (szAction.equals(ACTION_BOOT_COMPLETED)) {
AppConfigs appConfigs = AppConfigs.loadAppConfigs(context); AppConfigs appConfigs = AppConfigs.getInstance(context).loadAppConfigs(context);
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
Intent intentService = new Intent(context, MainService.class); Intent intentService = new Intent(context, MainService.class);
//intentService.putExtra(MainService.EXTRA_APKFILEPATH, appConfigs.getWatchingFilePath()); //intentService.putExtra(MainService.EXTRA_APKFILEPATH, appConfigs.getWatchingFilePath());

View File

@ -46,7 +46,7 @@ public class AssistantService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
//LogUtils.d(TAG, "call onStartCommand(...)"); //LogUtils.d(TAG, "call onStartCommand(...)");
run(); run();
AppConfigs appConfigs = AppConfigs.loadAppConfigs(AssistantService.this); AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(AssistantService.this);
return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId); return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
} }
@ -68,7 +68,7 @@ public class AssistantService extends Service {
// //
void run() { void run() {
//LogUtils.d(TAG, "call run()"); //LogUtils.d(TAG, "call run()");
AppConfigs appConfigs = AppConfigs.loadAppConfigs(AssistantService.this); AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(AssistantService.this);
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
if (mIsThreadAlive == false) { if (mIsThreadAlive == false) {
// 设置运行状态 // 设置运行状态
@ -101,7 +101,7 @@ public class AssistantService extends Service {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
//LogUtils.d(TAG, "call onServiceDisconnected(...)"); //LogUtils.d(TAG, "call onServiceDisconnected(...)");
AppConfigs appConfigs = AppConfigs.loadAppConfigs(AssistantService.this); AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(AssistantService.this);
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
wakeupAndBindMain(); wakeupAndBindMain();
} }

View File

@ -26,6 +26,7 @@ import com.hjq.toast.ToastUtils;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import cc.winboll.studio.autoinstaller.models.MainServiceBean;
public class MainService extends Service { public class MainService extends Service {
@ -62,7 +63,7 @@ public class MainService extends Service {
private void run() { private void run() {
AppConfigs appConfigs = AppConfigs.loadAppConfigs(MainService.this); AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(MainService.this);
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
if (_mIsServiceAlive == false) { if (_mIsServiceAlive == false) {
// 设置运行状态 // 设置运行状态
@ -77,8 +78,8 @@ public class MainService extends Service {
startWatchingFile(appConfigs.getWatchingFilePath()); startWatchingFile(appConfigs.getWatchingFilePath());
LogUtils.d(TAG, "running..."); //LogUtils.d(TAG, "running...");
ToastUtils.show("running..."); //ToastUtils.show("running...");
} else { } else {
LogUtils.d(TAG, "_mIsServiceAlive is " + Boolean.toString(_mIsServiceAlive)); LogUtils.d(TAG, "_mIsServiceAlive is " + Boolean.toString(_mIsServiceAlive));
@ -105,7 +106,7 @@ public class MainService extends Service {
LogUtils.d(TAG, "onStartCommand"); LogUtils.d(TAG, "onStartCommand");
run(); run();
AppConfigs appConfigs = AppConfigs.loadAppConfigs(MainService.this); AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(MainService.this);
return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId); return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
} }
@ -122,7 +123,7 @@ public class MainService extends Service {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
//LogUtils.d(TAG, "call onServiceConnected(...)"); //LogUtils.d(TAG, "call onServiceConnected(...)");
AppConfigs appConfigs = AppConfigs.loadAppConfigs(MainService.this); AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(MainService.this);
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
// 唤醒守护进程 // 唤醒守护进程
wakeupAndBindAssistant(); wakeupAndBindAssistant();
@ -164,7 +165,7 @@ public class MainService extends Service {
}); });
mFileListener.startWatching(); mFileListener.startWatching();
ToastUtils.show("Start watching."); //ToastUtils.show("Start watching.");
} else { } else {
// 父级文件夹不存在就提示用户 // 父级文件夹不存在就提示用户
Toast.makeText(getApplication(), fParentDir.toString() + " no exist.", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplication(), fParentDir.toString() + " no exist.", Toast.LENGTH_SHORT).show();
@ -247,7 +248,7 @@ public class MainService extends Service {
switch (message.what) { switch (message.what) {
case MSG_INSTALL_APK: case MSG_INSTALL_APK:
{ {
AppConfigs appConfigs = AppConfigs.loadAppConfigs(theActivity); AppConfigs appConfigs = AppConfigs.getInstance(theActivity).loadAppConfigs(theActivity);
if (appConfigs.getSetupMode() == AppConfigs.SetupMode.WATCHOUTPUTINSTALLER) { if (appConfigs.getSetupMode() == AppConfigs.SetupMode.WATCHOUTPUTINSTALLER) {
theActivity.installAPK2((String)message.obj); theActivity.installAPK2((String)message.obj);
} else if (appConfigs.getSetupMode() == AppConfigs.SetupMode.NEWAPKINFONEWAPKINFO) { } else if (appConfigs.getSetupMode() == AppConfigs.SetupMode.NEWAPKINFONEWAPKINFO) {

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ff000000"
android:pathData="M6.5,20Q4.22,20 2.61,18.43 1,16.85 1,14.58 1,12.63 2.17,11.1 3.35,9.57 5.25,9.15 5.88,6.85 7.75,5.43 9.63,4 12,4 14.93,4 16.96,6.04 19,8.07 19,11 20.73,11.2 21.86,12.5 23,13.78 23,15.5 23,17.38 21.69,18.69 20.38,20 18.5,20Z"/>
</vector>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#ff000000"
android:pathData="M6.5,20Q4.22,20 2.61,18.43 1,16.85 1,14.58 1,12.63 2.17,11.1 3.35,9.57 5.25,9.15 5.88,6.85 7.75,5.43 9.63,4 12,4 14.93,4 16.96,6.04 19,8.07 19,11 20.73,11.2 21.86,12.5 23,13.78 23,15.5 23,17.38 21.69,18.69 20.38,20 18.5,20M6.5,18H18.5Q19.55,18 20.27,17.27 21,16.55 21,15.5 21,14.45 20.27,13.73 19.55,13 18.5,13H17V11Q17,8.93 15.54,7.46 14.08,6 12,6 9.93,6 8.46,7.46 7,8.93 7,11H6.5Q5.05,11 4.03,12.03 3,13.05 3,14.5 3,15.95 4.03,17 5.05,18 6.5,18M12,12Z"/>
</vector>

View File

@ -1,3 +1,4 @@
<resources> <resources>
<string name="app_name">AutoInstaller</string> <string name="app_name">AutoInstaller</string>
<string name="tileservice_name">AutoInstaller</string>
</resources> </resources>