version:2.1.0

update:
fix:更换应用之后删除原来的应用,加入获取哦log的服务,修复禁止升级的应用也会被卸载
add:
This commit is contained in:
2021-06-03 17:41:52 +08:00
parent 6cd1442f46
commit ee11b63068
20 changed files with 732 additions and 366 deletions

View File

@@ -41,9 +41,9 @@ android {
//新平台正式 //新平台正式
newly { newly {
flavorDimensions "default" flavorDimensions "default"
versionCode 509 versionCode 510
//versionCode 1037 //versionCode 1037
versionName "2.0.9" versionName "2.1.0"
/*********************************极光推送************************************/ /*********************************极光推送************************************/
manifestPlaceholders = [ manifestPlaceholders = [
JPUSH_PKGNAME: "com.jiaoguanyi.appstore", JPUSH_PKGNAME: "com.jiaoguanyi.appstore",
@@ -168,22 +168,22 @@ android {
buildTypes { buildTypes {
zhanRuiRelease.initWith(release) zhanRuiRelease.initWith(release)
zhanRuiRelease { zhanRuiRelease {
buildConfigField "String", "platform", '"ZhanRui"'
signingConfig signingConfigs.zhanRui
manifestPlaceholders = [ manifestPlaceholders = [
AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05" AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
] ]
buildConfigField "String", "platform", '"ZhanRui"'
signingConfig signingConfigs.zhanRui
} }
zhanRuiDebug.initWith(debug) zhanRuiDebug.initWith(debug)
zhanRuiDebug { zhanRuiDebug {
manifestPlaceholders = [
AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
]
versionNameSuffix "-debug" versionNameSuffix "-debug"
buildConfigField "String", "platform", '"ZhanRui"' buildConfigField "String", "platform", '"ZhanRui"'
debuggable true debuggable true
signingConfig signingConfigs.zhanRui signingConfig signingConfigs.zhanRui
manifestPlaceholders = [
AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
]
} }
debug { debug {
@@ -229,7 +229,7 @@ android {
variant.outputs.each { output -> variant.outputs.each { output ->
def outputFile = "" def outputFile = ""
if (outputFile != null) { if (outputFile != null) {
def fileName = "${appName()}-${variant.versionCode}-V${variant.versionName}-${releaseTime()}-${productFlavors[0].name}-${buildType.name}.apk" def fileName = "${appName()}-${variant.versionCode}-V${variant.versionName}-${releaseTime()}-${buildType.name}.apk"
output.outputFileName = fileName output.outputFileName = fileName
} }
} }

View File

@@ -25,20 +25,17 @@
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.SHUTDOWN" /> <uses-permission android:name="android.permission.SHUTDOWN" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/> <uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.DELETE_CACHE_FILES"/> <uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <!-- 静默安装权限 -->
<!-- 静默安装权限 -->
<uses-permission <uses-permission
android:name="android.permission.INSTALL_PACKAGES" android:name="android.permission.INSTALL_PACKAGES"
tools:ignore="ProtectedPermissions" /> <!-- 应用卸载权限 --> tools:ignore="ProtectedPermissions" /> <!-- 应用卸载权限 -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission <uses-permission
android:name="android.permission.DELETE_PACKAGES" android:name="android.permission.DELETE_PACKAGES"
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" /> <!-- ##############################极光推送############################## -->
<!-- ##############################极光推送############################## -->
<!-- Required --> <!-- Required -->
<permission <permission
android:name="${JPUSH_PKGNAME}.permission.JPUSH_MESSAGE" android:name="${JPUSH_PKGNAME}.permission.JPUSH_MESSAGE"
@@ -59,13 +56,10 @@
android:maxSdkVersion="22" /> android:maxSdkVersion="22" />
<uses-permission <uses-permission
android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"
android:maxSdkVersion="23" /> android:maxSdkVersion="23" /> <!-- 高德地图 -->
<!-- 高德地图 -->
<!-- 用于进行网络定位 --> <!-- 用于进行网络定位 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 用于访问GPS定位 -->
<!-- 用于访问GPS定位 --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 用于获取运营商信息,用于支持提供运营商信息相关的接口 -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- 用于获取运营商信息,用于支持提供运营商信息相关的接口 -->
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> --> <!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
<!-- 用于访问wifi网络信息wifi信息会用于进行网络定位 --> <!-- 用于访问wifi网络信息wifi信息会用于进行网络定位 -->
<!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> --> <!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> -->
@@ -78,14 +72,12 @@
<!-- 用于写入缓存数据到扩展存储卡 --> <!-- 用于写入缓存数据到扩展存储卡 -->
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> --> <!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> -->
<!-- 用于申请调用A-GPS模块 --> <!-- 用于申请调用A-GPS模块 -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <!-- 如果设置了target >= 28 如果需要启动后台定位则必须声明这个权限 -->
<!-- 如果设置了target >= 28 如果需要启动后台定位则必须声明这个权限 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> <!-- 如果您的应用需要后台定位权限且有可能运行在Android Q设备上,并且设置了target>28必须增加这个权限声明 -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- 如果您的应用需要后台定位权限且有可能运行在Android Q设备上,并且设置了target>28必须增加这个权限声明 -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application <application
android:name="com.mjsheng.myappstore.base.BaseApplication" android:name=".base.BaseApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
@@ -93,10 +85,13 @@
android:requestLegacyExternalStorage="true" android:requestLegacyExternalStorage="true"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<service
android:name=".server.LogcatService"
android:enabled="true"
android:exported="true"></service>
<activity android:name="com.mjsheng.myappstore.activity.TopActivity" /> <activity android:name=".activity.TopActivity" />
<activity android:name="com.mjsheng.myappstore.activity.HomeActivity"> <activity android:name=".activity.HomeActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@@ -104,26 +99,27 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name="com.mjsheng.myappstore.activity.MainActivity" android:name=".activity.MainActivity"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:launchMode="singleTop"> android:launchMode="singleTop">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />--> <!-- <intent-filter> -->
<!-- </intent-filter>--> <!-- <action android:name="android.intent.action.MAIN" /> -->
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
<!-- </intent-filter> -->
</activity> </activity>
<activity <activity
android:name="com.mjsheng.myappstore.activity.DiscardActivity" android:name=".activity.DiscardActivity"
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:launchMode="singleTop" /> android:launchMode="singleTop" /> <!-- <service android:name=".server.MyDownloadService" /> -->
<!-- <service android:name=".server.MyDownloadService" />--> <service android:name=".server.GuardService" />
<service android:name="com.mjsheng.myappstore.server.GuardService" />
<service <service
android:name="com.mjsheng.myappstore.server.StepService" android:name=".server.StepService"
android:exported="true" /> android:exported="true" />
<service <service
android:name="com.mjsheng.myappstore.server.MainService" android:name=".server.MainService"
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter android:priority="1000"> <intent-filter android:priority="1000">
@@ -133,16 +129,13 @@
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</service> </service> <!-- <service -->
<!-- <service--> <!-- android:name=".server.InitJpushServer" -->
<!-- android:name=".server.InitJpushServer"--> <!-- android:enabled="true" -->
<!-- android:enabled="true"--> <!-- android:exported="true"> -->
<!-- android:exported="true">--> <!-- </service> -->
<!-- </service>-->
<receiver <receiver
android:name="com.mjsheng.myappstore.receiver.NewAppReceiver" android:name=".receiver.NewAppReceiver"
android:enabled="true" android:enabled="true"
android:exported="true" android:exported="true"
android:permission="com.example.broadcast.permission"> android:permission="com.example.broadcast.permission">
@@ -155,11 +148,11 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver <receiver
android:name="com.mjsheng.myappstore.utils.InstallResultReceiver" android:name=".utils.InstallResultReceiver"
android:enabled="true" android:enabled="true"
android:exported="true" /> android:exported="true" />
<receiver <receiver
android:name="com.mjsheng.myappstore.receiver.BootReceiver" android:name=".receiver.BootReceiver"
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter android:priority="1000"> <intent-filter android:priority="1000">
@@ -188,8 +181,7 @@
<!-- 自定义广播 --> <!-- 自定义广播 -->
<action android:name="com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED" /> <action android:name="com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED" />
</intent-filter> </intent-filter>
</receiver> </receiver> <!-- <receiver android:name=".log.LogReceiver" -->
<!-- <receiver android:name=".log.LogReceiver" -->
<!-- android:permission="android.permission.DUMP" > --> <!-- android:permission="android.permission.DUMP" > -->
<!-- <intent-filter> --> <!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.BOOT_COMPLETED" /> --> <!-- <action android:name="android.intent.action.BOOT_COMPLETED" /> -->
@@ -201,7 +193,7 @@
<!-- </intent-filter> --> <!-- </intent-filter> -->
<!-- </receiver> --> <!-- </receiver> -->
<receiver <receiver
android:name="com.mjsheng.myappstore.receiver.MyJPushReceiver" android:name=".receiver.MyJPushReceiver"
android:enabled="true"> android:enabled="true">
<intent-filter> <intent-filter>
@@ -218,8 +210,7 @@
<category android:name="${JPUSH_PKGNAME}" /> <category android:name="${JPUSH_PKGNAME}" />
</intent-filter> </intent-filter>
</receiver> </receiver> <!-- Required. For publish channel feature -->
<!-- Required. For publish channel feature -->
<!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。 --> <!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。 -->
<!-- 例如: --> <!-- 例如: -->
<!-- 发到 Google Play 的APK可以设置为 google-play; --> <!-- 发到 Google Play 的APK可以设置为 google-play; -->
@@ -241,15 +232,13 @@
<meta-data <meta-data
android:name="android.support.FILE_PROVIDER_PATHS" android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" /> android:resource="@xml/file_paths" />
</provider> </provider> <!-- ##############################极光推送############################## -->
<!-- ##############################极光推送############################## -->
<!-- Rich push 核心功能 since 2.0.6 --> <!-- Rich push 核心功能 since 2.0.6 -->
<activity <activity
android:name="cn.jpush.android.ui.PopWinActivity" android:name="cn.jpush.android.ui.PopWinActivity"
android:exported="false" android:exported="false"
android:theme="@style/MyDialogStyle" android:theme="@style/MyDialogStyle"
tools:replace="android:exported" /> tools:replace="android:exported" /> <!-- Required SDK核心功能 -->
<!-- Required SDK核心功能 -->
<activity <activity
android:name="cn.jpush.android.ui.PushActivity" android:name="cn.jpush.android.ui.PushActivity"
android:configChanges="orientation|keyboardHidden" android:configChanges="orientation|keyboardHidden"
@@ -262,8 +251,7 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="com.jiaoguanyi.appstore" /> <category android:name="com.jiaoguanyi.appstore" />
</intent-filter> </intent-filter>
</activity> </activity> <!-- Required SDK 核心功能 -->
<!-- Required SDK 核心功能 -->
<!-- 可配置android:process参数将PushService放在其他进程中 --> <!-- 可配置android:process参数将PushService放在其他进程中 -->
<service <service
android:name="cn.jpush.android.service.PushService" android:name="cn.jpush.android.service.PushService"
@@ -275,15 +263,13 @@
<action android:name="cn.jpush.android.intent.PushService" /> <action android:name="cn.jpush.android.intent.PushService" />
<action android:name="cn.jpush.android.intent.PUSH_TIME" /> <action android:name="cn.jpush.android.intent.PUSH_TIME" />
</intent-filter> </intent-filter>
</service> </service> <!-- since 3.0.9 Required SDK 核心功能 -->
<!-- since 3.0.9 Required SDK 核心功能 -->
<provider <provider
android:name="cn.jpush.android.service.DataProvider" android:name="cn.jpush.android.service.DataProvider"
android:authorities="com.jiaoguanyi.appstore.DataProvider" android:authorities="com.jiaoguanyi.appstore.DataProvider"
android:exported="false" android:exported="false"
android:process=":pushcore" android:process=":pushcore"
tools:replace="android:authorities" /> tools:replace="android:authorities" /> <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
<!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 --> <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
<service <service
android:name="cn.jpush.android.service.DaemonService" android:name="cn.jpush.android.service.DaemonService"
@@ -294,14 +280,12 @@
<category android:name="com.jiaoguanyi.appstore" /> <category android:name="com.jiaoguanyi.appstore" />
</intent-filter> </intent-filter>
</service> </service> <!-- since 3.1.0 Required SDK 核心功能 -->
<!-- since 3.1.0 Required SDK 核心功能 -->
<provider <provider
android:name="cn.jpush.android.service.DownloadProvider" android:name="cn.jpush.android.service.DownloadProvider"
android:authorities="com.jiaoguanyi.appstore.DownloadProvider" android:authorities="com.jiaoguanyi.appstore.DownloadProvider"
android:exported="true" android:exported="true"
tools:replace="android:authorities" /> tools:replace="android:authorities" /> <!-- Required SDK核心功能 -->
<!-- Required SDK核心功能 -->
<receiver <receiver
android:name="cn.jpush.android.service.PushReceiver" android:name="cn.jpush.android.service.PushReceiver"
android:enabled="true" android:enabled="true"
@@ -322,12 +306,10 @@
<data android:scheme="package" /> <data android:scheme="package" />
</intent-filter> </intent-filter>
</receiver> </receiver> <!-- Required SDK核心功能 -->
<!-- Required SDK核心功能 -->
<receiver <receiver
android:name="cn.jpush.android.service.AlarmReceiver" android:name="cn.jpush.android.service.AlarmReceiver"
android:exported="false" /> android:exported="false" /> <!-- since 3.3.0 Required SDK核心功能 -->
<!-- since 3.3.0 Required SDK核心功能 -->
<activity <activity
android:name="cn.jpush.android.service.JNotifyActivity" android:name="cn.jpush.android.service.JNotifyActivity"
android:exported="true" android:exported="true"
@@ -338,19 +320,17 @@
<category android:name="com.jiaoguanyi.appstore" /> <category android:name="com.jiaoguanyi.appstore" />
</intent-filter> </intent-filter>
</activity> </activity> <!-- Since JCore2.0.0 Required SDK核心功能 -->
<!-- Since JCore2.0.0 Required SDK核心功能 -->
<!-- 这个Service要继承JCommonService --> <!-- 这个Service要继承JCommonService -->
<service <service
android:name="com.mjsheng.myappstore.jpush.PushService" android:name=".jpush.PushService"
android:process=":pushcore"> android:process=":pushcore">
<intent-filter> <intent-filter>
<action android:name="cn.jiguang.user.service.action" /> <action android:name="cn.jiguang.user.service.action" />
</intent-filter> </intent-filter>
</service> </service> <!-- User defined. For test only 用户自定义的广播接收器 -->
<!-- User defined. For test only 用户自定义的广播接收器 -->
<receiver <receiver
android:name="com.mjsheng.myappstore.jpush.MyReceiver" android:name=".jpush.MyReceiver"
android:enabled="true" android:enabled="true"
android:exported="false"> android:exported="false">
<intent-filter> <intent-filter>
@@ -366,9 +346,8 @@
<!-- 接收网络变化 连接/断开 since 1.6.3 --> <!-- 接收网络变化 连接/断开 since 1.6.3 -->
<category android:name="com.jiaoguanyi.appstore" /> <category android:name="com.jiaoguanyi.appstore" />
</intent-filter> </intent-filter>
</receiver> </receiver> <!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 -->
<!-- User defined. For test only 用户自定义接收消息器,3.0.7开始支持,目前新tag/alias接口设置结果会在该广播接收器对应的方法中回调 --> <receiver android:name=".jpush.MyJPushMessageReceiver">
<receiver android:name="com.mjsheng.myappstore.jpush.MyJPushMessageReceiver">
<intent-filter> <intent-filter>
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" /> <action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
@@ -378,20 +357,18 @@
<meta-data <meta-data
android:name="JPUSH_CHANNEL" android:name="JPUSH_CHANNEL"
android:value="developer-default" /> android:value="developer-default" /> <!-- Required. AppKey copied from Portal -->
<!-- Required. AppKey copied from Portal -->
<meta-data <meta-data
android:name="JPUSH_APPKEY" android:name="JPUSH_APPKEY"
android:value="${JPUSH_APPKEY}" /> android:value="${JPUSH_APPKEY}" /> <!-- 高德地图 -->
<!-- 高德地图 -->
<!-- 设置key --> <!-- 设置key -->
<meta-data <meta-data
android:name="com.amap.api.v2.apikey" android:name="com.amap.api.v2.apikey"
android:value="${AMAP_KEY}" /> android:value="${AMAP_KEY}" /> <!-- 定位需要的服务 适配Android Q需要加上android:foregroundServiceType="location" -->
<!-- 定位需要的服务 适配Android Q需要加上android:foregroundServiceType="location" -->
<service <service
android:name="com.amap.api.location.APSService" android:name="com.amap.api.location.APSService"
android:foregroundServiceType="location" /> android:foregroundServiceType="location" />
<meta-data <meta-data
android:name="CHANNEL_VALUE" android:name="CHANNEL_VALUE"
android:value="${channel_value}" /> android:value="${channel_value}" />

View File

@@ -2,10 +2,10 @@ package com.mjsheng.myappstore.activity;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.StatusBarManager; import android.app.StatusBarManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.provider.Settings; import android.provider.Settings;
@@ -13,26 +13,55 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R; import com.mjsheng.myappstore.R;
import com.lzy.okgo.model.HttpHeaders; import com.lzy.okgo.model.HttpHeaders;
import com.mjsheng.myappstore.utils.CacheUtils; import com.mjsheng.myappstore.server.LogcatService;
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class HomeActivity extends AppCompatActivity { public class HomeActivity extends AppCompatActivity {
private static String TAG = HomeActivity.class.getSimpleName(); private static String TAG = HomeActivity.class.getSimpleName();
private Button bt_log;
private Button bt_stop;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home); setContentView(R.layout.activity_home);
if (BuildConfig.DEBUG) {
bt_log = findViewById(R.id.bt_log);
bt_log.setVisibility(View.VISIBLE);
bt_log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!ServiceAliveUtils.isServiceAlive(HomeActivity.this, LogcatService.class.getName())) {
startService(new Intent(HomeActivity.this, LogcatService.class));
}
Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION);
sendBroadcast(intent);
}
});
bt_stop = findViewById(R.id.bt_stop);
bt_stop.setVisibility(View.VISIBLE);
bt_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!ServiceAliveUtils.isServiceAlive(HomeActivity.this, LogcatService.class.getName())) {
startService(new Intent(HomeActivity.this, LogcatService.class));
}
Intent intent = new Intent(LogcatService.LOGCAT_STOP_ACTION);
sendBroadcast(intent);
}
});
debugTest();
// return;
}
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -40,27 +69,31 @@ public class HomeActivity extends AppCompatActivity {
finish(); finish();
} }
}, 2000); }, 2000);
if (BuildConfig.DEBUG) {
DebugTest();
}
} }
private void DebugTest() { private void debugTest() {
// Utils.getHardware(this); // Utils.getHardware(this);
// setWebView(); // setWebView();
// hideStatusBar(); // hideStatusBar();
Log.e(TAG, "DebugTest: " + HttpHeaders.getUserAgent()); Log.e(TAG, "DebugTest: " + HttpHeaders.getUserAgent());
// boolean qch_force_app = Settings.System.putString(getContentResolver(), "qch_launcher_icon_app", ""); // boolean qch_force_app = Settings.System.putString(getContentResolver(), "qch_launcher_icon_app", "");
Log.e(TAG, "DebugTest: " + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app")); Log.e(TAG, "DebugTest: qch_launcher_icon_app:" + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app"));
Log.e(TAG, "DebugTest: qch_hide_NavigationBar: " + Settings.System.getString(getContentResolver(), "qch_hide_NavigationBar")); Log.e(TAG, "DebugTest: qch_hide_NavigationBar: " + Settings.System.getString(getContentResolver(), "qch_hide_NavigationBar"));
String only_jgy_shortcut_list = Settings.System.getString(getContentResolver(), "only_jgy_shortcut_list");
Log.e(TAG, "debugTest: only_jgy_shortcut_list:" + only_jgy_shortcut_list);
String qch_app_forbid = Settings.System.getString(getContentResolver(), "qch_app_forbid");
Log.e(TAG, "debugTest: qch_app_forbid:" + qch_app_forbid);
// try { // try {
// new CacheUtils().cleanApplicationUserData(HomeActivity.this, "com.android.launcher3"); // new CacheUtils().cleanApplicationUserData(HomeActivity.this, "com.android.launcher3");
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// Log.e(TAG, "DebugTest: " + e.getMessage()); // Log.e(TAG, "DebugTest: " + e.getMessage());
// } // }
} // ActivityManager mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// mAm.killBackgroundProcesses("com.android.documentsui");
}
@SuppressLint("NewApi") @SuppressLint("NewApi")
private void hideStatusBar() { private void hideStatusBar() {

View File

@@ -740,8 +740,7 @@ public class MainPresenter implements MainContact.Presenter {
// if (null != batchList && batchList.size() > 1) { // if (null != batchList && batchList.size() > 1) {
// Log.e("getDeviceBatch", "onNext: " + "deleteOtherApp"); // Log.e("getDeviceBatch", "onNext: " + "deleteOtherApp");
// if (!BuildConfig.DEBUG) { // if (!BuildConfig.DEBUG) {
//暂时屏蔽 JGYUtils.getInstance().deleteOtherApp();
// JGYUtils.getInstance().deleteOtherApp(packageList);
// } // }
// } else { // } else {
// Log.e("getDeviceBatch", "批次为空"); // Log.e("getDeviceBatch", "批次为空");

View File

@@ -27,6 +27,7 @@ import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.URLAddress; import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.statistics.AppInformation; import com.mjsheng.myappstore.statistics.AppInformation;
import com.mjsheng.myappstore.statistics.StatisticsInfo; import com.mjsheng.myappstore.statistics.StatisticsInfo;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.JGYUtils; import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.SystemUtils; import com.mjsheng.myappstore.utils.SystemUtils;
import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.ToastUtil;
@@ -421,7 +422,7 @@ public class BaseApplication extends MultiDexApplication {
list = statisticsInfo.getShowList(); list = statisticsInfo.getShowList();
if (list != null && list.size() > 0) { if (list != null && list.size() > 0) {
for (AppInformation appInformation : list) { for (AppInformation appInformation : list) {
if (!Utils.isSystemApp(getAppContext(), appInformation.getPackageName())) { if (!ApkUtils.isSystemApp(getAppContext(), appInformation.getPackageName())) {
localAppList.add(appInformation); localAppList.add(appInformation);
} }
} }

View File

@@ -13,7 +13,7 @@ public class UploadAppInfo {
private String install_time; private String install_time;
private String versionCode; private String versionCode;
private int state; private int state;
private int id; // private int id;
String versionName; String versionName;
public String getPackage_name() { public String getPackage_name() {
@@ -32,13 +32,13 @@ public class UploadAppInfo {
this.app_name = app_name; this.app_name = app_name;
} }
public int getId() { // public int getId() {
return id; // return id;
} // }
//
public void setId(int id) { // public void setId(int id) {
this.id = id; // this.id = id;
} // }
public String getInstall_time() { public String getInstall_time() {
return install_time; return install_time;
@@ -78,7 +78,7 @@ public class UploadAppInfo {
"package_name='" + package_name + '\'' + "package_name='" + package_name + '\'' +
", app_name='" + app_name + '\'' + ", app_name='" + app_name + '\'' +
", install_time=" + install_time + ", install_time=" + install_time +
", id=" + id + // ", id=" + id +
'}'; '}';
} }
} }

View File

@@ -1106,14 +1106,15 @@ public class HTTPInterface {
int code = jsonObject.get("code").getAsInt(); int code = jsonObject.get("code").getAsInt();
if (code == 200) { if (code == 200) {
String data = jsonObject.get("data").getAsJsonObject().get("result").getAsString(); String data = jsonObject.get("data").getAsJsonObject().get("result").getAsString();
//开机图标 //开机图标 只记录后台传的包名
boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", data); boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", data);
Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write); Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
JGYUtils.getInstance().writeAppPackageList(context, data); JGYUtils.getInstance().writeAppPackageList(context, data);
} else { } else {
boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", ""); //为错误的时候不删除
Settings.System.putString(context.getContentResolver(), "qch_app_forbid", " "); // boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", "");
Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write); // Settings.System.putString(context.getContentResolver(), "qch_app_forbid", " ");
// Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
Log.e("getAppLimit", "onNext: " + bodyString); Log.e("getAppLimit", "onNext: " + bodyString);
} }
} catch (IOException e) { } catch (IOException e) {
@@ -1134,6 +1135,4 @@ public class HTTPInterface {
} }
}); });
} }
} }

View File

@@ -7,8 +7,8 @@ import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.server.GuardService; import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.LogcatService;
import com.mjsheng.myappstore.server.MainService; import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.server.StepService; import com.mjsheng.myappstore.server.StepService;
@@ -62,5 +62,6 @@ public class BootReceiver extends BroadcastReceiver {
context.startService(new Intent(context, MainService.class)); context.startService(new Intent(context, MainService.class));
context.startService(new Intent(context, StepService.class)); context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class)); context.startService(new Intent(context, GuardService.class));
context.startService(new Intent(context, LogcatService.class));
} }
} }

View File

@@ -1,7 +1,6 @@
package com.mjsheng.myappstore.receiver; package com.mjsheng.myappstore.receiver;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -44,12 +43,10 @@ import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.SPUtils; import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SaveListUtils; import com.mjsheng.myappstore.utils.SaveListUtils;
import com.mjsheng.myappstore.utils.ServiceAliveUtils; import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.SysSettingUtils;
import com.mjsheng.myappstore.utils.Utils; import com.mjsheng.myappstore.utils.Utils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable; import io.reactivex.Observable;
@@ -197,7 +194,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
SaveListUtils.sendForceAPP(mContext); SaveListUtils.sendForceAPP(mContext);
ApkUtils.UninstallAPP(mContext, title); ApkUtils.UninstallAPP(mContext, title);
} }
getAppLimitApi(); HTTPInterface.getAppLimit(context);
HTTPInterface.getNetAndLaunchSetting(mContext); HTTPInterface.getNetAndLaunchSetting(mContext);
break; break;
case MSG_SETTING: case MSG_SETTING:
@@ -224,7 +221,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break; break;
case MSG_INSTALL: case MSG_INSTALL:
// mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); // mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
getAppLimitApi(); HTTPInterface.getAppLimit(context);
doDownloadAndInstall(extras); doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext); HTTPInterface.setHideDesktopIcon(mContext);
break; break;
@@ -288,7 +285,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
setDisableSlideList(extras); setDisableSlideList(extras);
break; break;
case UPDATE_INFO: case UPDATE_INFO:
getAppLimitApi(); HTTPInterface.getAppLimit(context);
break; break;
case SN_SCREENSHOT: case SN_SCREENSHOT:
screenshot(extras); screenshot(extras);
@@ -335,7 +332,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
case KILL_SERVER: case KILL_SERVER:
JSONObject killJSONObject = JSON.parseObject(extras); JSONObject killJSONObject = JSON.parseObject(extras);
String packages = killJSONObject.getString("package_name"); String packages = killJSONObject.getString("package_name");
killBackgroundProcesses(context, packages); JGYUtils.getInstance().killBackgroundProcesses(context, packages);
break; break;
case TIME_CONTROL: case TIME_CONTROL:
getTimeControl(context, extras); getTimeControl(context, extras);
@@ -366,7 +363,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
} }
private void setLock_screen(int state, Context context, String name) { private void setLock_screen(int state, Context context, String name) {
if (ServiceAliveUtils.isServiceAlice(context)) { if (ServiceAliveUtils.isServiceAlive(context)) {
context.startService(new Intent(context, MainService.class)); context.startService(new Intent(context, MainService.class));
} }
Intent intent = new Intent(); Intent intent = new Intent();
@@ -379,31 +376,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
public void killBackgroundProcesses(Context context, String processName) {
// mIsScanning = true;
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = null;
try {
if (processName.indexOf(":") == -1) {
packageName = processName;
} else {
packageName = processName.split(":")[0];
}
activityManager.killBackgroundProcesses(packageName);
//
Method forceStopPackage = activityManager.getClass()
.getDeclaredMethod("forceStopPackage", String.class);
forceStopPackage.setAccessible(true);
forceStopPackage.invoke(activityManager, packageName);
} catch (Exception e) {
e.printStackTrace();
}
}
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private void SettingSysData(String extras) { private void SettingSysData(String extras) {
@@ -675,13 +647,14 @@ public class MyJPushReceiver extends BroadcastReceiver {
e.printStackTrace(); e.printStackTrace();
} }
if (packageInfo == null) { if (packageInfo == null) {
Log.e(TAG, "doDownloadAndInstall: "+ app_package + "未安装"); Log.e(TAG, "doDownloadAndInstall: " + app_package + "未安装");
if (!SaveListUtils.isDownLoading(app_url)) { if (!SaveListUtils.isDownLoading(app_url)) {
// Aria.download(this) // Aria.download(this)
// .load(app_url) // .load(app_url)
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(s) + ".apk", true) // .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(s) + ".apk", true)
// .setExtendField(packageObj.toJSONString()) // .setExtendField(packageObj.toJSONString())
// .create(); // .create();
Log.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载");
Utils.ariaDownload(mContext, app_url, packageObj); Utils.ariaDownload(mContext, app_url, packageObj);
} }
} else { } else {
@@ -701,50 +674,50 @@ public class MyJPushReceiver extends BroadcastReceiver {
Utils.ariaDownload(mContext, app_url, packageObj); Utils.ariaDownload(mContext, app_url, packageObj);
} }
}else { } else {
Log.e(TAG, "doDownloadAndInstall: "+ app_package + "已安装最新版"); Log.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版");
} }
} }
} }
private void getAppLimitApi() { // private void getAppLimitApi() {
NetInterfaceManager.getAppLimitApi() // NetInterfaceManager.getAppLimitApi()
.getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial()) // .getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io()) // .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) // .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() { // .subscribe(new Observer<ResponseBody>() {
@Override // @Override
public void onComplete() { // public void onComplete() {
} // }
//
@Override // @Override
public void onError(Throwable param1Throwable) { // public void onError(Throwable param1Throwable) {
Log.e(TAG, "getAppLimitApi=onError:"); // Log.e(TAG, "getAppLimitApi=onError:");
} // }
//
@Override // @Override
public void onNext(ResponseBody param1ResponseBody) { // public void onNext(ResponseBody param1ResponseBody) {
try { // try {
String str2 = param1ResponseBody.string(); // String str2 = param1ResponseBody.string();
Log.e(TAG, str2); // Log.e(TAG, str2);
JSONObject jSONObject = JSON.parseObject(str2); // JSONObject jSONObject = JSON.parseObject(str2);
JSONObject data = jSONObject.getJSONObject("data"); // JSONObject data = jSONObject.getJSONObject("data");
String result = ""; // String result = "";
if (data != null) { // if (data != null) {
result = data.getString("result"); // result = data.getString("result");
} // }
JGYUtils.getInstance().writeAppPackageList(mContext, result); // JGYUtils.getInstance().writeAppPackageList(mContext, result);
} catch (IOException e) { // } catch (IOException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
//
} // }
//
@Override // @Override
public void onSubscribe(Disposable param1Disposable) { // public void onSubscribe(Disposable param1Disposable) {
} // }
}); // });
} // }
// private void getForceDownload() { // private void getForceDownload() {
// ForceDownloadApi forceDownloadApi = Network.getForceDownloadApi(); // ForceDownloadApi forceDownloadApi = Network.getForceDownloadApi();

View File

@@ -11,7 +11,9 @@ import android.util.Log;
import com.mjsheng.myappstore.BuildConfig; import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.network.HTTPInterface; import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.CacheUtils;
import com.mjsheng.myappstore.utils.JGYUtils; import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SaveListUtils; import com.mjsheng.myappstore.utils.SaveListUtils;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -37,7 +39,7 @@ public class NewAppReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
mContext = context; mContext = context;
String action = intent.getAction(); String action = intent.getAction();
JGYUtils.getInstance().cleanLauncherCache(); cleanLauncherCache();
Log.e(TAG, "onReceive: " + "action = " + action); Log.e(TAG, "onReceive: " + "action = " + action);
String state; String state;
if (TextUtils.isEmpty(action)) { if (TextUtils.isEmpty(action)) {
@@ -84,6 +86,20 @@ public class NewAppReceiver extends BroadcastReceiver {
// } // }
} }
public void cleanLauncherCache() {
Log.e(TAG, "cleanLauncherCache: Start");
int cleaned = (int) SPUtils.get(mContext, "fristcleanLauncherCache", 0);
if (cleaned == 0) {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
SPUtils.put(mContext, "fristcleanLauncherCache", 1);
Log.e(TAG, "cleanLauncherCache: end");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "cleanLauncherCache: " + e.getMessage());
}
}
}
public interface NewAppListener { public interface NewAppListener {
void setNewAppListener(String packageName); void setNewAppListener(String packageName);

View File

@@ -749,7 +749,7 @@ public class DiscardServer extends Service {
List<Batch> batchList = JSON.parseArray(data, Batch.class); List<Batch> batchList = JSON.parseArray(data, Batch.class);
if (null != batchList && batchList.size() > 1) { if (null != batchList && batchList.size() > 1) {
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
JGYUtils.getInstance().deleteOtherApp(result); // JGYUtils.getInstance().deleteOtherApp(result);
} }
} else { } else {
Log.e("getDeviceBatch", "批次为空"); Log.e("getDeviceBatch", "批次为空");

View File

@@ -56,10 +56,7 @@ import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.ToastUtil; import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.Utils; import com.mjsheng.myappstore.utils.Utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
import io.reactivex.Observer; import io.reactivex.Observer;
@@ -84,9 +81,9 @@ public class GuardService extends Service {
@Override @Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) { public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.e(TAG, "GuardService:建立链接"); Log.e(TAG, "GuardService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(GuardService.this); boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName());
if (!isServiceRunning) { if (!isServiceRunning) {
Intent i = new Intent(GuardService.this, GuardService.class); Intent i = new Intent(GuardService.this, StepService.class);
startService(i); startService(i);
} }
} }
@@ -109,22 +106,13 @@ public class GuardService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
// try {
// exec = Runtime.getRuntime().exec(running);
// final InputStream is = exec.getInputStream();
// logThread = new LogThread(is);
// is.close();
// exec.destroy();
// } catch (IOException e) {
//// e.printStackTrace();
// Log.e("第一个是Logcat", e.getMessage());
// }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 8.0之后需要在 // 8.0之后需要在
registmNewAppReceiver(); registmNewAppReceiver();
startService(new Intent(this, MainService.class)); startService(new Intent(this, MainService.class));
startService(new Intent(this, StepService.class)); startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class)); startService(new Intent(this, GuardService.class));
startService(new Intent(this, LogcatService.class));
} }
registerPresentReceiver(); registerPresentReceiver();
registerBatteryReceiver(); registerBatteryReceiver();
@@ -133,57 +121,6 @@ public class GuardService extends Service {
super.onCreate(); super.onCreate();
} }
private Process exec;
private LogThread logThread;
//第一个是Logcat 也就是我们想要获取的log日志
//第二个是 -s 也就是表示过滤的意思
//第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D debug IinfoEerror等等
// String[] running = new String[]{"logcat", "-s", "adb logcat *: W"};
String[] running = new String[]{"logcat"};
String logFilePath = "/sdcard/Log/Log.txt";
class LogThread extends Thread {
InputStream is;
LogThread(InputStream inputStream) {
super();
this.is = inputStream;
}
@Override
public void run() {
FileOutputStream os = null;
try {
//新建一个路径信息
File file = new File(logFilePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
os = new FileOutputStream(logFilePath);
int len = 0;
byte[] buf = new byte[1024];
while (-1 != (len = is.read(buf))) {
os.write(buf, 0, len);
os.flush();
}
} catch (Exception e) {
Log.e("writelog", "read logcat process failed. message: "
+ e.getMessage());
} finally {
if (null != os) {
try {
os.close();
os = null;
} catch (IOException e) {
// Do nothing
}
}
}
}
}
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand: "); Log.e(TAG, "onStartCommand: ");
@@ -349,20 +286,21 @@ public class GuardService extends Service {
startService(new Intent(context, MainService.class)); startService(new Intent(context, MainService.class));
startService(new Intent(context, StepService.class)); startService(new Intent(context, StepService.class));
startService(new Intent(context, GuardService.class)); startService(new Intent(context, GuardService.class));
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { startService(new Intent(context, LogcatService.class));
int setting_statusbar = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0); // if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
String statusbarStatus = ""; // int setting_statusbar = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0);
switch (setting_statusbar) { // String statusbarStatus = "";
case 0: // switch (setting_statusbar) {
statusbarStatus = "qch_show_statusBar"; // case 0:
break; // statusbarStatus = "qch_show_statusBar";
case 1: // break;
statusbarStatus = "qch_hide_statusBar"; // case 1:
break; // statusbarStatus = "qch_hide_statusBar";
} // break;
Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); // }
context.sendBroadcast(navIntent); // Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
} // context.sendBroadcast(navIntent);
// }
} }
break; break;
case Intent.ACTION_SCREEN_ON: { case Intent.ACTION_SCREEN_ON: {
@@ -371,11 +309,11 @@ public class GuardService extends Service {
aMapLocationClient.stopLocation(); aMapLocationClient.stopLocation();
aMapLocationClient.startLocation(); aMapLocationClient.startLocation();
getLockState("2", String.valueOf(time)); getLockState("2", String.valueOf(time));
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { // if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
String statusbarStatus = "qch_hide_statusBar"; // String statusbarStatus = "qch_hide_statusBar";
Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); // Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
context.sendBroadcast(navIntent); // context.sendBroadcast(navIntent);
} // }
break; break;
} }
case Intent.ACTION_SCREEN_OFF: { case Intent.ACTION_SCREEN_OFF: {
@@ -388,11 +326,11 @@ public class GuardService extends Service {
sendBroadcast(intent1); sendBroadcast(intent1);
JGYUtils.getInstance().deleteScreenshots(); JGYUtils.getInstance().deleteScreenshots();
} }
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) { // if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
String statusbarStatus = "qch_show_statusBar"; // String statusbarStatus = "qch_show_statusBar";
Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); // Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
context.sendBroadcast(navIntent); // context.sendBroadcast(navIntent);
} // }
break; break;
} }
case "android.intent.action.FACTORY_RESET": case "android.intent.action.FACTORY_RESET":

View File

@@ -0,0 +1,251 @@
package com.mjsheng.myappstore.server;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Environment;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import com.android.server.am.ServiceRecordProto;
import com.mjsheng.myappstore.utils.Utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LogcatService extends Service {
public final static String LOGCAT_START_ACTION = "START";
public final static String LOGCAT_STOP_ACTION = "STOP";
private String TAG = LogcatService.class.getSimpleName();
public LogcatService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
// throw new UnsupportedOperationException("Not yet implemented");
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
logFilePath = getExternalCacheDir() + File.separator + "LOG" + File.separator;
File file = new File(logFilePath);
if (!file.exists()) {
file.mkdirs();
}
// try {
// exec = Runtime.getRuntime().exec(running);
// final InputStream is = exec.getInputStream();
// logThread = new LogThread(is);
// logThread.start();
// // is.close();
//// exec.destroy();
// } catch (IOException e) {
//// e.printStackTrace();
// Log.e("第一个是Logcat", e.getMessage());
// }
registerLogcatReceiver();
}
LogcatReceiver receiver;
private void registerLogcatReceiver() {
receiver = new LogcatReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(LOGCAT_START_ACTION);
filter.addAction(LOGCAT_STOP_ACTION);
registerReceiver(receiver, filter);
}
Thread thread = null;
private void creatLogThread() {
if (thread == null) {
thread = new Thread(LogcatRunnale);
}
}
private void startLogThread() {
if (thread == null) {
creatLogThread();
shouldGetLog = true;
thread.start();
} else {
//已经有线程正在运行了
}
}
private void stopLogThread() {
if (thread != null) {
shouldGetLog = false;
thread = null;
//清除adb 缓存
try {
Runtime.getRuntime().exec(clearLogcat);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private Process exec;
private LogThread logThread;
//第一个是Logcat 也就是我们想要获取的log日志
//第二个是 -s 也就是表示过滤的意思
//第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D debug IinfoEerror等等
// String[] running = new String[]{"logcat", "-s", "adb logcat *: W"};
String[] running = new String[]{"logcat"};
String clearLogcat = "logcat -c";
String logFilePath;
//= getExternalCacheDir() + File.separator + "LOG" + File.separator;
String logFileName;
class LogThread extends Thread {
InputStream is;
LogThread(InputStream inputStream) {
super();
this.is = inputStream;
}
@Override
public void run() {
FileOutputStream os = null;
try {
//新建一个路径信息
File file = new File(logFilePath + logFileName);
Log.e(TAG, "run: " + logFilePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
os = new FileOutputStream(logFilePath);
int len = 0;
byte[] buf = new byte[1024];
while (-1 != (len = is.read(buf))) {
os.write(buf, 0, len);
os.flush();
}
} catch (Exception e) {
Log.e("writelog", "read logcat process failed. message: "
+ e.getMessage());
} finally {
if (null != os) {
try {
os.close();
os = null;
} catch (IOException e) {
// Do nothing
}
}
}
}
}
private Runnable LogcatRunnale = new Runnable() {
@Override
public void run() {
getLog();
}
};
public static boolean shouldGetLog = true;
private void getLog() {
Process process = null;
try {
process = Runtime.getRuntime().exec(running);
} catch (IOException e) {
e.printStackTrace();
}
InputStreamReader inputStreamReader;
BufferedReader bufferedReader;
FileOutputStream fileOutputStream;
File file = new File(logFilePath);
Log.e(TAG, "getLog: " + logFilePath);
if (!file.exists()) {
file.mkdirs();
}
logFileName = Utils.getSerial() + "-" + getTime() + ".log";
try {
inputStreamReader = new InputStreamReader(process.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
fileOutputStream = new FileOutputStream(logFilePath + logFileName);
Log.e(TAG, "getLog: " + logFilePath + logFileName);
String logEntry;
while (shouldGetLog) {
logEntry = bufferedReader.readLine() + "\n";
fileOutputStream.write(logEntry.getBytes());
fileOutputStream.flush();
}
inputStreamReader.close();
bufferedReader.close();
fileOutputStream.close();
Log.e(TAG, "getLog: " + "closed");
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
class LogcatReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.e(TAG, "onReceive: " + action);
if (TextUtils.isEmpty(action)) {
return;
}
switch (action) {
case LOGCAT_START_ACTION:
startLogThread();
break;
case LOGCAT_STOP_ACTION:
stopLogThread();
break;
default:
break;
}
}
}
public static String getTime() {
long time = System.currentTimeMillis();//long now = android.os.SystemClock.uptimeMillis();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
Date d1 = new Date(time);
String t1 = format.format(d1);
return t1;
}
@Override
public void onDestroy() {
super.onDestroy();
if (receiver != null) {
unregisterReceiver(receiver);
}
}
}

View File

@@ -51,9 +51,9 @@ public class StepService extends Service {
@Override @Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) { public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.e(TAG, "StepService:建立链接"); Log.e(TAG, "StepService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this); boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName());
if (!isServiceRunning) { if (!isServiceRunning) {
Intent i = new Intent(StepService.this, StepService.class); Intent i = new Intent(StepService.this, GuardService.class);
startService(i); startService(i);
} }
} }

View File

@@ -339,6 +339,7 @@ public class ApkUtils {
} }
public static void installApp(Context context, String filePath) { public static void installApp(Context context, String filePath) {
Log.e(TAG, "installApp: " + filePath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
installAppatPie(context, filePath); installAppatPie(context, filePath);
} else { } else {
@@ -700,7 +701,6 @@ public class ApkUtils {
this.add("com.android.calendar");//日历 this.add("com.android.calendar");//日历
}}; }};
//桌面app //桌面app
@@ -980,24 +980,49 @@ public class ApkUtils {
} }
public static boolean isSystemApp(Context context, String pkg) { // public static boolean isSystemApp(Context context, String pkg) {
// try {
// PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0);
// if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// if (pkg.equals(context.getPackageName())) {
// return true;
// } else {
// //第三方应用
// return false;
// }
// } else {
// //系统应用
// return true;
// }
// } catch (PackageManager.NameNotFoundException e) {
// e.printStackTrace();
// return false;
// }
// }
/**
* 判断是否为系统应用
*
* @param context 上下文
* @param pkgName 包名
* @return
*/
public static boolean isSystemApp(Context context, String pkgName) {
boolean isSystemApp = false;
PackageInfo pi = null;
try { try {
PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0); PackageManager pm = context.getPackageManager();
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) { pi = pm.getPackageInfo(pkgName, 0);
if (pkg.equals(context.getPackageName())) {
return true;
} else {
//第三方应用
return false;
}
} else {
//系统应用
return true;
}
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); Log.e("isSystemApp: NameNotFoundException:", e.getMessage());
return true;
} }
// 是系统中已安装的应用
if (pi != null) {
boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
isSystemApp = isSysApp || isSysUpd;
}
return isSystemApp;
} }
public static void getStartActivityName(Context mContext, String packagename) { public static void getStartActivityName(Context mContext, String packagename) {
@@ -1099,37 +1124,43 @@ public class ApkUtils {
} }
ArrayList<UploadAppInfo> appList = new ArrayList<UploadAppInfo>(); //用来存储获取的应用信息数据 ArrayList<UploadAppInfo> appList = new ArrayList<UploadAppInfo>(); //用来存储获取的应用信息数据
List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0); List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0);
for (PackageInfo packageInfo : packages) {
for (int i = 0; i < packages.size(); i++) { String packageName = packageInfo.packageName;
PackageInfo packageInfo = packages.get(i); //排除桌面app和出厂自带app
if (ApkUtils.systemapp.contains(packageInfo.packageName) if (desktopAPP.contains(packageName)
|| ApkUtils.show_canremove_systemapp.contains(packageInfo.packageName) || factoryapp.contains(packageName)
|| ApkUtils.canremove_systemapp.contains(packageInfo.packageName)
) { ) {
continue; continue;
} }
//排除所有系统应用,不显示
if (((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) && factoryapp.contains(packageInfo.packageName)) { if (isSystemApp(context, packageName)) {
//如果是系统应用且包名属于出厂app 跳过
continue; continue;
} } else {
//排除预装可以卸载的应用
if (desktopAPP.contains(packageInfo.packageName)) { if (canremove_systemapp.contains(packageName)) {
continue;
}
if (JGYUtils.getInstance().checkAppPlatform() == 2) {
if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
continue; continue;
} }
} }
// if (ApkUtils.systemapp.contains(packageInfo.packageName)
// || ApkUtils.show_canremove_systemapp.contains(packageInfo.packageName)
// || ApkUtils.canremove_systemapp.contains(packageInfo.packageName)) {continue;}
// //如果是系统应用且包名属于出厂app 跳过
// if (((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) && factoryapp.contains(packageInfo.packageName)) {continue;}
// if (desktopAPP.contains(packageInfo.packageName)) {continue;}
// if (JGYUtils.getInstance().checkAppPlatform() == 2) {
// if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
// continue;
// }
// }
UploadAppInfo uploadAppInfo = new UploadAppInfo(); UploadAppInfo uploadAppInfo = new UploadAppInfo();
uploadAppInfo.setApp_name(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString()); uploadAppInfo.setApp_name(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
uploadAppInfo.setPackage_name(packageInfo.packageName); uploadAppInfo.setPackage_name(packageInfo.packageName);
Log.e("getAppInfo", "getAppInfo:" + packageInfo.packageName); Log.e("getAppInfo", "getAppInfo:" + packageInfo.packageName);
uploadAppInfo.setId(i); // uploadAppInfo.setId(i);
String firstInstallTime = Utils.transferLongToDate(packageInfo.firstInstallTime); String firstInstallTime = Utils.transferLongToDate(packageInfo.firstInstallTime);
uploadAppInfo.setInstall_time(firstInstallTime); uploadAppInfo.setInstall_time(firstInstallTime);
uploadAppInfo.setVersionCode(String.valueOf(packageInfo.versionCode)); uploadAppInfo.setVersionCode(String.valueOf(packageInfo.versionCode));

View File

@@ -2,6 +2,8 @@ package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.ActivityTaskManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
@@ -10,10 +12,12 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.net.Uri; import android.net.Uri;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Build; import android.os.Build;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.RemoteException;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@@ -44,9 +48,13 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
public class JGYUtils { public class JGYUtils {
private static final String TAG = JGYUtils.class.getSimpleName(); private static final String TAG = JGYUtils.class.getSimpleName();
@@ -585,10 +593,12 @@ public class JGYUtils {
int versionCode = jsonObject.get("version_code").getAsInt(); int versionCode = jsonObject.get("version_code").getAsInt();
String packageName = jsonObject.get("package").getAsString(); String packageName = jsonObject.get("package").getAsString();
String app_name = jsonObject.get("app_name").getAsString(); String app_name = jsonObject.get("app_name").getAsString();
String app_md5 = jsonObject.get("app_md5").getAsString();
// String app_id = jsonObject.get("app_id").getAsString(); // String app_id = jsonObject.get("app_id").getAsString();
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put("app_name", app_name); object.put("app_name", app_name);
object.put("app_package", packageName); object.put("app_package", packageName);
object.put("MD5", app_md5);
// object.put("app_id", app_id); // object.put("app_id", app_id);
PackageManager pm = mContext.getPackageManager(); PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null; PackageInfo packageInfo = null;
@@ -704,22 +714,29 @@ public class JGYUtils {
} }
//删除用户除了在应用市场的其他应用 //删除用户除了在应用市场的其他应用
public void deleteOtherApp(String packageList) { public void deleteOtherApp() {
Log.e("deleteOtherApp", "packageList:" + packageList); Log.e(TAG, "deleteOtherApp: " + "start");
String[] result = packageList.split(","); //获取后台应用白名单
List<String> resultList = new ArrayList<>(Arrays.asList(result)); String only_jgy_shortcut_list = Settings.System.getString(mContext.getContentResolver(), "only_jgy_shortcut_list");
List<String> packageLists = ApkUtils.queryFilterAppInfo(mContext); //获取可以被安装的包名
String qch_app_forbid = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid");
Log.e("deleteOtherApp", "only_jgy_shortcut_list:" + only_jgy_shortcut_list);
Log.e("deleteOtherApp", "qch_app_forbid:" + qch_app_forbid);
String[] result_white = only_jgy_shortcut_list.split(",");
String[] result_forbid = qch_app_forbid.split(",");
List<String> resulWhitetList = new ArrayList<>(Arrays.asList(result_white));
List<String> resulForbidtList = new ArrayList<>(Arrays.asList(result_forbid));
resulWhitetList.addAll(resulForbidtList);
HashSet<String> allWhitePkg = new HashSet<>(resulWhitetList);
List<String> installedPackageList = ApkUtils.queryFilterAppInfo(mContext);
Log.e("deleteOtherApp", "packageLists:" + packageLists.toString()); Log.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString());
if (resultList.size() > 0) { if (allWhitePkg.size() > 0) {
for (final String packageName : packageLists) { for (final String packageName : installedPackageList) {
if (Utils.isSystemApp(mContext, packageName)) { if (ApkUtils.isSystemApp(mContext, packageName)) {
Log.e("deleteOtherApp", "is systemApp:" + packageName); Log.e("deleteOtherApp", "is systemApp:" + packageName);
continue; continue;
} }
if (ApkUtils.systemapp.contains(packageName)) {
continue;
}
if (ApkUtils.desktopAPP.contains(packageName)) { if (ApkUtils.desktopAPP.contains(packageName)) {
continue; continue;
} }
@@ -730,12 +747,13 @@ public class JGYUtils {
) { ) {
continue; continue;
} }
if (!resultList.contains(packageName)) { if (!allWhitePkg.contains(packageName)) {
ApkUtils.UninstallAPP(mContext, packageName); ApkUtils.UninstallAPP(mContext, packageName);
Log.e("deleteOtherApp", "uninstall apkName:" + packageName); Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
} }
} }
} }
Log.e(TAG, "deleteOtherApp: " + "end");
} }
@@ -1009,4 +1027,106 @@ public class JGYUtils {
} }
} }
} }
public void killBackgroundProcesses(Context context, String processName) {
gotoLauncher();
// mIsScanning = true;
removeTask(processName);
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
String packageName = null;
try {
if (processName.indexOf(":") == -1) {
packageName = processName;
} else {
packageName = processName.split(":")[0];
}
activityManager.killBackgroundProcesses(packageName);
//
Method forceStopPackage = activityManager.getClass()
.getDeclaredMethod("forceStopPackage", String.class);
forceStopPackage.setAccessible(true);
forceStopPackage.invoke(activityManager, packageName);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 清除所有最近记录
*/
public void removeAllTask(Context context) {
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
for (ActivityManager.RecentTaskInfo info : list) {
if (info.realActivity != null) {
Log.e(TAG, "removeAllTask: " + info.realActivity.getPackageName());
//排除自身
if (BuildConfig.APPLICATION_ID.equals(info.realActivity.getPackageName())) {
continue;
}
}
try {
ActivityManagerNative.getDefault().removeTask(info.id);
} catch (RemoteException e) {
e.printStackTrace();
Log.e(TAG, "removeAllTask: " + e.getMessage());
}
}
}
public void removeTask(String packageName) {
List<ActivityManager.RecentTaskInfo> list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
HashMap<String, Integer> taskMap = new HashMap<>();
for (ActivityManager.RecentTaskInfo info : list) {
taskMap.put(info.realActivity.getPackageName(), info.id);
}
try {
ActivityManagerNative.getDefault().removeTask(taskMap.get(packageName));
} catch (RemoteException e) {
e.printStackTrace();
Log.e(TAG, "removeTask: " + e.getMessage());
} catch (NullPointerException e) {
Log.e(TAG, "removeTask: " + e.getMessage());
}
}
/**
* 如果界面正在最近任务列表有些app可能不会被清理
*/
private void gotoLauncher() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //android123提示如果是服务里调用必须加入new task标识
i.addCategory(Intent.CATEGORY_HOME);
mContext.startActivity(i);
}
/**
* @return a list of the recents tasks.
* 获取近期任务列表
*/
public List<ActivityManager.RecentTaskInfo> getRecentTasks(int numTasks, int userId) {
try {
return ActivityTaskManager.getService().getRecentTasks(numTasks,
RECENT_IGNORE_UNAVAILABLE, userId).getList();
} catch (RemoteException e) {
Log.e(TAG, "Failed to get recent tasks", e);
return new ArrayList<>();
}
}
/**
* @return the current user's id.
* 获取userId
*/
public int getCurrentUserId() {
UserInfo ui;
try {
ui = ActivityManager.getService().getCurrentUser();
return ui != null ? ui.id : 0;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
} }

View File

@@ -5,7 +5,7 @@ import android.content.Context;
import android.util.Log; import android.util.Log;
public class ServiceAliveUtils { public class ServiceAliveUtils {
public static boolean isServiceAlice(Context mContext) { public static boolean isServiceAlive(Context mContext) {
boolean isServiceRunning = false; boolean isServiceRunning = false;
ActivityManager manager = ActivityManager manager =
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
@@ -20,4 +20,20 @@ public class ServiceAliveUtils {
Log.e("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning); Log.e("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
return isServiceRunning; return isServiceRunning;
} }
public static boolean isServiceAlive(Context mContext, String serviceName) {
boolean isServiceRunning = false;
ActivityManager manager =
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (manager == null) {
return false;
}
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceName.equals(service.service.getClassName())) {
isServiceRunning = true;
}
}
Log.e("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning);
return isServiceRunning;
}
} }

View File

@@ -725,35 +725,6 @@ public class Utils {
return null; return null;
} }
/**
* 判断是否为系统应用
*
* @param context 上下文
* @param pkgName 包名
* @return
*/
public static boolean isSystemApp(Context context, String pkgName) {
boolean isSystemApp = false;
PackageInfo pi = null;
try {
PackageManager pm = context.getPackageManager();
pi = pm.getPackageInfo(pkgName, 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
Log.e("isSystemApp", e.getMessage(), e);
}
// 是系统中已安装的应用
if (pi != null) {
boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
isSystemApp = isSysApp || isSysUpd;
}
return isSystemApp;
}
public static Bitmap getRoundedBitmap(Bitmap mBitmap, Context context) { public static Bitmap getRoundedBitmap(Bitmap mBitmap, Context context) {
Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888); Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
@@ -963,6 +934,7 @@ public class Utils {
String fileName = getFileNamefromURL(url); String fileName = getFileNamefromURL(url);
String urlMD5 = jsonObject.getString("MD5"); String urlMD5 = jsonObject.getString("MD5");
Log.e("ariaDownload", "urlMD5=" + urlMD5); Log.e("ariaDownload", "urlMD5=" + urlMD5);
String p = PathUtils.getExternalDownloadsPath();
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName); File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName);
if (file.exists() && !file.isDirectory()) { if (file.exists() && !file.isDirectory()) {
String filenameMD5 = getMD5fromFileName(url); String filenameMD5 = getMD5fromFileName(url);

View File

@@ -17,6 +17,25 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/bt_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="logtest"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<Button
android:id="@+id/bt_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="logtest"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/bt_log"
app:layout_constraintStart_toStartOf="@+id/bt_log"
app:layout_constraintTop_toBottomOf="@+id/bt_log" />
<TextView <TextView
android:id="@+id/textView3" android:id="@+id/textView3"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -17,13 +17,33 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/bt_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="logtest"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/imageView" />
<Button
android:id="@+id/bt_stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="logtest"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/bt_log"
app:layout_constraintStart_toStartOf="@+id/bt_log"
app:layout_constraintTop_toBottomOf="@+id/bt_log" />
<TextView <TextView
android:id="@+id/textView3" android:id="@+id/textView3"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="40dp" android:layout_marginBottom="40dp"
android:textColor="@color/title_textcolor"
android:text="版权所有@深圳市七彩宏云智能设备有限公司" android:text="版权所有@深圳市七彩宏云智能设备有限公司"
android:textColor="@color/title_textcolor"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />