Skip to content

Commit 6d99bd5

Browse files
committed
see 11/12 log
1 parent 2861dcf commit 6d99bd5

File tree

9 files changed

+73
-8
lines changed

9 files changed

+73
-8
lines changed

README-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
```
77
isActivityExists : 判断是否存在Activity
88
launchActivity : 打开Activity
9+
getLauncherActivity: 获取launcher activity
910
```
1011

1112
> - **App相关→[AppUtils.java][app.java]**
@@ -117,6 +118,8 @@ getManufacturer : 获取设备厂商
117118
getModel : 获取设备型号
118119
shutdown : 关机
119120
reboot : 重启
121+
reboot2Recovery : 重启到recovery
122+
reboot2Bootloader : 重启到bootloader
120123
```
121124

122125
> - **判空相关→[EmptyUtils.java][empty.java][Test][empty.test]**

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
import com.blankj.androidutilcode.R;
99
import com.blankj.utilcode.utils.ActivityUtils;
10-
import com.blankj.utilcode.utils.DeviceUtils;
11-
import com.blankj.utilcode.utils.IntentUtils;
12-
import com.blankj.utilcode.utils.ShellUtils;
1310

1411
/**
1512
* <pre>
@@ -38,8 +35,9 @@ protected void onCreate(Bundle savedInstanceState) {
3835

3936
findViewById(R.id.btn_launch_image_activity).setOnClickListener(this);
4037

41-
boolean isExists = ActivityUtils.isActivityExists(this, packageName, className);
42-
tvAboutActivity.setText(String.format("Is ImageActivity Exists: %b", isExists));
38+
tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(this, packageName, className) +
39+
"\ngetLauncherActivity: " + ActivityUtils.getLauncherActivity(this, packageName)
40+
);
4341
}
4442

4543
@Override

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protected void onCreate(Bundle savedInstanceState) {
2929

3030
findViewById(R.id.btn_shutdown).setOnClickListener(this);
3131
findViewById(R.id.btn_reboot).setOnClickListener(this);
32+
findViewById(R.id.btn_reboot_to_recovery).setOnClickListener(this);
33+
findViewById(R.id.btn_reboot_to_bootloader).setOnClickListener(this);
3234

3335
tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot() +
3436
"\ngetSDKVersion: " + DeviceUtils.getSDKVersion() +
@@ -47,6 +49,10 @@ public void onClick(View view) {
4749
break;
4850
case R.id.btn_reboot:
4951
DeviceUtils.reboot();
52+
case R.id.btn_reboot_to_recovery:
53+
DeviceUtils.reboot2Recovery();
54+
case R.id.btn_reboot_to_bootloader:
55+
DeviceUtils.reboot2Bootloader();
5056
break;
5157
}
5258
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@
2828
android:text="@string/device.reboot"
2929
/>
3030

31+
<Button
32+
android:id="@+id/btn_reboot_to_recovery"
33+
style="@style/BtnFont"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:text="@string/device.reboot_to_recovery"
37+
/>
38+
39+
<Button
40+
android:id="@+id/btn_reboot_to_bootloader"
41+
style="@style/BtnFont"
42+
android:layout_width="match_parent"
43+
android:layout_height="wrap_content"
44+
android:text="@string/device.reboot_to_bootloader"
45+
/>
46+
3147
<TextView
3248
android:id="@+id/tv_about_device"
3349
style="@style/Font"

app/src/main/res/values/string.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<!--Device相关-->
3434
<string name="device.shutdown">Shutdown</string>
3535
<string name="device.reboot">Reboot</string>
36+
<string name="device.reboot_to_recovery">Reboot To Recovery</string>
37+
<string name="device.reboot_to_bootloader">Reboot To Bootloader</string>
3638

3739
<!--Handler相关-->
3840
<string name="handler.send_msg_after_3s">Send Msg After 3s</string>

update_log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
###
2+
#### 16/11/12 最近一直在博客搬家,所以更得有点少,新增重启到recovery和bootloader,新增获取launcher activity
23
#### 16/11/04 修复README的缺少process的bug
34
#### 16/11/03 SnackbarUtils中Snackbar持有弱引用来消除内存泄漏
45
#### 16/11/02 内存泄漏检测中

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import android.app.ActivityManager;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.content.pm.PackageManager;
7+
import android.content.pm.ResolveInfo;
68
import android.os.Bundle;
9+
import android.util.Log;
710

811
import java.util.List;
912

@@ -59,4 +62,24 @@ public static void launchActivity(Context context, String packageName, String cl
5962
public static void launchActivity(Context context, String packageName, String className, Bundle bundle) {
6063
context.startActivity(IntentUtils.getComponentIntent(packageName, className, bundle));
6164
}
65+
66+
/**
67+
* 获取launcher activity
68+
*
69+
* @param context 上下文
70+
* @param packageName 包名
71+
* @return launcher activity
72+
*/
73+
public static String getLauncherActivity(Context context, String packageName) {
74+
Intent intent = new Intent(Intent.ACTION_MAIN, null);
75+
intent.addCategory(Intent.CATEGORY_LAUNCHER);
76+
PackageManager pm = context.getPackageManager();
77+
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
78+
for (ResolveInfo info : infos) {
79+
if (info.activityInfo.packageName.equals(packageName)) {
80+
return info.activityInfo.name;
81+
}
82+
}
83+
return "no " + packageName;
84+
}
6285
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,20 @@ public static void reboot(Context context, String reason) {
243243
e.printStackTrace();
244244
}
245245
}
246+
247+
/**
248+
* 重启到recovery
249+
* <p>需要root权限</p>
250+
*/
251+
public static void reboot2Recovery() {
252+
ShellUtils.execCmd("reboot recovery", true);
253+
}
254+
255+
/**
256+
* 重启到bootloader
257+
* <p>需要root权限</p>
258+
*/
259+
public static void reboot2Bootloader() {
260+
ShellUtils.execCmd("reboot bootloader", true);
261+
}
246262
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static byte[] encryptMD5(byte[] data) {
124124
* @return 文件的16进制密文
125125
*/
126126
public static String encryptMD5File2String(String filePath) {
127-
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
127+
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
128128
return encryptMD5File2String(file);
129129
}
130130

@@ -135,7 +135,7 @@ public static String encryptMD5File2String(String filePath) {
135135
* @return 文件的MD5校验码
136136
*/
137137
public static byte[] encryptMD5File(String filePath) {
138-
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
138+
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
139139
return encryptMD5File(file);
140140
}
141141

@@ -164,7 +164,7 @@ public static byte[] encryptMD5File(File file) {
164164
MessageDigest md = MessageDigest.getInstance("MD5");
165165
digestInputStream = new DigestInputStream(fis, md);
166166
byte[] buffer = new byte[256 * 1024];
167-
while (digestInputStream.read(buffer) > 0);
167+
while (digestInputStream.read(buffer) > 0) ;
168168
md = digestInputStream.getMessageDigest();
169169
return md.digest();
170170
} catch (NoSuchAlgorithmException | IOException e) {

0 commit comments

Comments
 (0)