Skip to content

Commit 19c4052

Browse files
committed
see 11/24 log
1 parent 8a4b812 commit 19c4052

File tree

11 files changed

+107
-56
lines changed

11 files changed

+107
-56
lines changed

app/src/main/AndroidManifest.xml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>-->
3333
<uses-permission android:name="android.permission.READ_SMS"/>
3434

35+
<!--process-->
36+
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
3537
<application
3638
android:name=".App"
3739
android:allowBackup="true"

app/src/main/java/com/blankj/androidutilcode/activities/ActivityActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ protected void onCreate(Bundle savedInstanceState) {
3535

3636
findViewById(R.id.btn_launch_image_activity).setOnClickListener(this);
3737

38-
tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(this, packageName, className) +
39-
"\ngetLauncherActivity: " + ActivityUtils.getLauncherActivity(this, packageName)
38+
tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(this, packageName, className)
39+
+ "\ngetLauncherActivity: " + ActivityUtils.getLauncherActivity(this, packageName)
4040
);
4141
}
4242

app/src/main/java/com/blankj/androidutilcode/activities/AppActivity.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ protected void onCreate(Bundle savedInstanceState) {
3939
findViewById(R.id.btn_launch_app).setOnClickListener(this);
4040
findViewById(R.id.btn_get_app_details_settings).setOnClickListener(this);
4141

42-
tvAboutApp.setText(AppUtils.getAppInfo(this).toString() +
43-
"\nisInstallWeiXin: " + AppUtils.isInstallApp(this, "com.tencent.mm") +
44-
"\nisAppRoot: " + AppUtils.isAppRoot() +
45-
"\nisAppDebug: " + AppUtils.isAppDebug(this) +
46-
"\nisWeiXinAppDebug: " + AppUtils.isAppDebug(this, "com.tencent.mm") +
47-
"\nAppSignatureSHA1: " + AppUtils.getAppSignatureSHA1(this) +
48-
"\nisAppForeground: " + AppUtils.isAppForeground(this) +
49-
"\nisWeiXinForeground: " + AppUtils.isAppForeground(this, "com.tencent.mm")
42+
tvAboutApp.setText(AppUtils.getAppInfo(this).toString()
43+
+ "\nisInstallWeiXin: " + AppUtils.isInstallApp(this, "com.tencent.mm")
44+
+ "\nisAppRoot: " + AppUtils.isAppRoot()
45+
+ "\nisAppDebug: " + AppUtils.isAppDebug(this)
46+
+ "\nisWeiXinAppDebug: " + AppUtils.isAppDebug(this, "com.tencent.mm")
47+
+ "\nAppSignatureSHA1: " + AppUtils.getAppSignatureSHA1(this)
48+
+ "\nisAppForeground: " + AppUtils.isAppForeground(this)
49+
+ "\nisWeiXinForeground: " + AppUtils.isAppForeground(this, "com.tencent.mm")
5050
);
5151
}
5252

app/src/main/java/com/blankj/androidutilcode/activities/DeviceActivity.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ protected void onCreate(Bundle savedInstanceState) {
3232
findViewById(R.id.btn_reboot_to_recovery).setOnClickListener(this);
3333
findViewById(R.id.btn_reboot_to_bootloader).setOnClickListener(this);
3434

35-
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot() +
36-
"\ngetSDKVersion: " + DeviceUtils.getSDKVersion() +
37-
"\ngetAndroidID: " + DeviceUtils.getAndroidID(App.getInstance()) +
38-
"\ngetMacAddress: " + DeviceUtils.getMacAddress(App.getInstance()) +
39-
"\ngetManufacturer: " + DeviceUtils.getManufacturer() +
40-
"\ngetModel: " + DeviceUtils.getModel()
35+
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot()
36+
+ "\ngetSDKVersion: " + DeviceUtils.getSDKVersion()
37+
+ "\ngetAndroidID: " + DeviceUtils.getAndroidID(App.getInstance())
38+
+ "\ngetMacAddress: " + DeviceUtils.getMacAddress(App.getInstance())
39+
+ "\ngetManufacturer: " + DeviceUtils.getManufacturer()
40+
+ "\ngetModel: " + DeviceUtils.getModel()
4141
);
4242
}
4343

app/src/main/java/com/blankj/androidutilcode/activities/LocationActivity.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ protected void onCreate(Bundle savedInstanceState) {
3232

3333
tvAboutLocation = (TextView) findViewById(R.id.tv_about_location);
3434

35-
tvAboutLocation.setText("lastLatitude: unknown" +
36-
"\nlastLongitude: unknown" +
37-
"\nlatitude: unknown" +
38-
"\nlongitude: unknown" +
39-
"\ngetCountryName: unknown" +
40-
"\ngetLocality: unknown" +
41-
"\ngetStreet: unknown"
35+
tvAboutLocation.setText("lastLatitude: unknown"
36+
+ "\nlastLongitude: unknown"
37+
+ "\nlatitude: unknown"
38+
+ "\nlongitude: unknown"
39+
+ "\ngetCountryName: unknown"
40+
+ "\ngetLocality: unknown"
41+
+ "\ngetStreet: unknown"
4242
);
4343

4444
bindService(new Intent(this, LocationService.class), conn, Context.BIND_AUTO_CREATE);

app/src/main/java/com/blankj/androidutilcode/activities/NetworkActivity.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ public void onClick(View view) {
5555
}
5656

5757
private void setAboutNetwork() {
58-
tvAboutNetwork.setText("isConnected: " + NetworkUtils.isConnected(mContext) +
59-
"\nisAvailableByPing: " + NetworkUtils.isAvailableByPing(mContext) +
60-
"\ngetDataEnabled: " + NetworkUtils.getDataEnabled(mContext) +
61-
"\nis4G: " + NetworkUtils.is4G(mContext) +
62-
"\ngetWifiEnabled: " + NetworkUtils.getWifiEnabled(mContext) +
63-
"\nisWifiConnected: " + NetworkUtils.isWifiConnected(mContext) +
64-
"\nisWifiAvailable: " + NetworkUtils.isWifiAvailable(mContext) +
65-
"\ngetNetworkOperatorName: " + NetworkUtils.getNetworkOperatorName(mContext) +
66-
"\ngetNetworkTypeName: " + NetworkUtils.getNetworkType(mContext) +
67-
"\ngetIPAddress: " + NetworkUtils.getIPAddress(true) +
68-
"\ngetDomainAddress: " + NetworkUtils.getDomainAddress("baidu.com")
58+
tvAboutNetwork.setText("isConnected: " + NetworkUtils.isConnected(mContext)
59+
+ "\nisAvailableByPing: " + NetworkUtils.isAvailableByPing(mContext)
60+
+ "\ngetDataEnabled: " + NetworkUtils.getDataEnabled(mContext)
61+
+ "\nis4G: " + NetworkUtils.is4G(mContext)
62+
+ "\ngetWifiEnabled: " + NetworkUtils.getWifiEnabled(mContext)
63+
+ "\nisWifiConnected: " + NetworkUtils.isWifiConnected(mContext)
64+
+ "\nisWifiAvailable: " + NetworkUtils.isWifiAvailable(mContext)
65+
+ "\ngetNetworkOperatorName: " + NetworkUtils.getNetworkOperatorName(mContext)
66+
+ "\ngetNetworkTypeName: " + NetworkUtils.getNetworkType(mContext)
67+
+ "\ngetIPAddress: " + NetworkUtils.getIPAddress(true)
68+
+ "\ngetDomainAddress: " + NetworkUtils.getDomainAddress("baidu.com")
6969
);
7070
}
7171
}

app/src/main/java/com/blankj/androidutilcode/activities/PhoneActivity.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ protected void onCreate(Bundle savedInstanceState) {
3131
findViewById(R.id.btn_send_sms).setOnClickListener(this);
3232
findViewById(R.id.btn_send_sms_silent).setOnClickListener(this);
3333

34-
tvAboutPhone.setText("isPhone: " + PhoneUtils.isPhone(this) +
35-
"\ngetIMEI: " + PhoneUtils.getIMEI(this) +
36-
"\ngetIMSI: " + PhoneUtils.getIMSI(this) +
37-
"\ngetPhoneType: " + PhoneUtils.getPhoneType(this) +
38-
"\nisSimCardReady: " + PhoneUtils.isSimCardReady(this) +
39-
"\ngetSimOperatorName: " + PhoneUtils.getSimOperatorName(this) +
40-
"\ngetSimOperatorByMnc: " + PhoneUtils.getSimOperatorByMnc(this) +
41-
"\n获取手机状态信息: " + PhoneUtils.getPhoneStatus(this)
34+
tvAboutPhone.setText("isPhone: " + PhoneUtils.isPhone(this)
35+
+ "\ngetIMEI: " + PhoneUtils.getIMEI(this)
36+
+ "\ngetIMSI: " + PhoneUtils.getIMSI(this)
37+
+ "\ngetPhoneType: " + PhoneUtils.getPhoneType(this)
38+
+ "\nisSimCardReady: " + PhoneUtils.isSimCardReady(this)
39+
+ "\ngetSimOperatorName: " + PhoneUtils.getSimOperatorName(this)
40+
+ "\ngetSimOperatorByMnc: " + PhoneUtils.getSimOperatorByMnc(this)
41+
+ "\n获取手机状态信息: " + PhoneUtils.getPhoneStatus(this)
4242
);
4343
}
4444

app/src/main/java/com/blankj/androidutilcode/activities/ProcessActivity.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
import android.app.Activity;
44
import android.os.Bundle;
55
import android.view.View;
6+
import android.widget.TextView;
67

78
import com.blankj.androidutilcode.R;
89
import com.blankj.utilcode.utils.ProcessUtils;
910
import com.blankj.utilcode.utils.ToastUtils;
1011

12+
import java.util.Iterator;
13+
import java.util.Set;
14+
1115
/**
1216
* <pre>
1317
* author: Blankj
@@ -19,20 +23,43 @@
1923
public class ProcessActivity extends Activity
2024
implements View.OnClickListener {
2125

26+
private TextView tvAboutProcess;
27+
2228
@Override
2329
protected void onCreate(Bundle savedInstanceState) {
2430
super.onCreate(savedInstanceState);
2531
setContentView(R.layout.activity_process);
2632

2733
findViewById(R.id.btn_kill_all_background_processes).setOnClickListener(this);
34+
tvAboutProcess = (TextView) findViewById(R.id.tv_about_process);
35+
36+
Set<String> set = ProcessUtils.getAllBackgroundProcesses(this);
37+
tvAboutProcess.setText("getForegroundProcessName: " + ProcessUtils.getForegroundProcessName(this)
38+
+ "\n\ngetAllBackgroundProcesses: " + getSetItems(set)
39+
+ "\nsize: " + set.size());
2840
}
2941

3042
@Override
3143
public void onClick(View view) {
3244
switch (view.getId()) {
3345
case R.id.btn_kill_all_background_processes:
34-
ToastUtils.showShortToast(this, ProcessUtils.killAllBackgroundProcesses(this));
46+
Set<String> set = ProcessUtils.getAllBackgroundProcesses(this);
47+
Set<String> set1 = ProcessUtils.killAllBackgroundProcesses(this);
48+
tvAboutProcess.setText("getForegroundProcessName: " + ProcessUtils.getForegroundProcessName(this)
49+
+ "\n\ngetAllBackgroundProcesses: " + getSetItems(set)
50+
+ "\nsize: " + set.size()
51+
+ "\n\nkillAllBackgroundProcesses: " + getSetItems(set1)
52+
+ "\nsize: " + set1.size());
3553
break;
3654
}
3755
}
56+
57+
private String getSetItems(Set<String> set) {
58+
Iterator<String> iterator = set.iterator();
59+
StringBuilder sb = new StringBuilder();
60+
while (iterator.hasNext()) {
61+
sb.append(iterator.next()).append("\n");
62+
}
63+
return sb.toString();
64+
}
3865
}

app/src/main/java/com/blankj/androidutilcode/activities/SDCardActivity.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ protected void onCreate(Bundle savedInstanceState) {
2323
setContentView(R.layout.activity_sdcard);
2424

2525
TextView tvAboutSdcard = (TextView) findViewById(R.id.tv_about_sdcard);
26-
tvAboutSdcard.setText("isSDCardEnable: " + SDCardUtils.isSDCardEnable() +
27-
"\ngetDataPath: " + SDCardUtils.getDataPath() +
28-
"\ngetSDCardPath: " + SDCardUtils.getSDCardPath() +
29-
"\ngetFreeSpace: " + SDCardUtils.getFreeSpace() +
30-
"\ngetSDCardInfo: " + SDCardUtils.getSDCardInfo()
26+
tvAboutSdcard.setText("isSDCardEnable: " + SDCardUtils.isSDCardEnable()
27+
+ "\ngetDataPath: " + SDCardUtils.getDataPath()
28+
+ "\ngetSDCardPath: " + SDCardUtils.getSDCardPath()
29+
+ "\ngetFreeSpace: " + SDCardUtils.getFreeSpace()
30+
+ "\ngetSDCardInfo: " + SDCardUtils.getSDCardInfo()
3131
);
3232
}
3333
}

app/src/main/res/layout/activity_process.xml

+8
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,13 @@
1818
android:text="@string/process.kill_all_background"
1919
/>
2020

21+
<TextView
22+
android:id="@+id/tv_about_process"
23+
style="@style/Font"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:gravity="center"
27+
/>
28+
2129
</LinearLayout>
2230
</ScrollView>

utilcode/src/main/java/com/blankj/utilcode/utils/ProcessUtils.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import android.content.pm.ResolveInfo;
1212
import android.provider.Settings;
1313

14+
import java.util.ArrayList;
1415
import java.util.Arrays;
16+
import java.util.Collections;
1517
import java.util.HashSet;
1618
import java.util.List;
1719
import java.util.Set;
@@ -86,35 +88,47 @@ public static String getForegroundProcessName(Context context) {
8688
return null;
8789
}
8890

91+
/**
92+
* 获取后台服务进程
93+
* <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
94+
*
95+
* @param context 上下文
96+
* @return 后台服务进程
97+
*/
98+
public static Set<String> getAllBackgroundProcesses(Context context) {
99+
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
100+
List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses();
101+
Set<String> set = new HashSet<>();
102+
for (ActivityManager.RunningAppProcessInfo info : infos) {
103+
Collections.addAll(set, info.pkgList);
104+
}
105+
return set;
106+
}
107+
89108
/**
90109
* 杀死后台服务进程
91110
* <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
92111
*
93112
* @param context 上下文
94-
* @return 杀死后台进程数
113+
* @return 被暂时杀死的服务集合
95114
*/
96-
public static int killAllBackgroundProcesses(Context context) {
97-
int count = 0;
115+
public static Set<String> killAllBackgroundProcesses(Context context) {
98116
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
99117
List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses();
100-
if (infos == null || infos.size() == 0) return 0;
101118
Set<String> set = new HashSet<>();
102119
for (ActivityManager.RunningAppProcessInfo info : infos) {
103120
for (String pkg : info.pkgList) {
104121
am.killBackgroundProcesses(pkg);
105122
set.add(pkg);
106-
++count;
107123
}
108124
}
109125
infos = am.getRunningAppProcesses();
110-
if (infos == null || infos.size() == 0) return count;
111126
for (ActivityManager.RunningAppProcessInfo info : infos) {
112127
for (String pkg : info.pkgList) {
113128
set.remove(pkg);
114-
--count;
115129
}
116130
}
117-
return count;
131+
return set;
118132
}
119133

120134
/**

0 commit comments

Comments
 (0)