Skip to content

Commit

Permalink
see 11/12 log
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankj committed Nov 13, 2016
1 parent 2861dcf commit 6d99bd5
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
```
isActivityExists : 判断是否存在Activity
launchActivity : 打开Activity
getLauncherActivity: 获取launcher activity
```

> - **App相关→[AppUtils.java][app.java]**
Expand Down Expand Up @@ -117,6 +118,8 @@ getManufacturer : 获取设备厂商
getModel : 获取设备型号
shutdown : 关机
reboot : 重启
reboot2Recovery : 重启到recovery
reboot2Bootloader : 重启到bootloader
```

> - **判空相关→[EmptyUtils.java][empty.java][Test][empty.test]**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import com.blankj.androidutilcode.R;
import com.blankj.utilcode.utils.ActivityUtils;
import com.blankj.utilcode.utils.DeviceUtils;
import com.blankj.utilcode.utils.IntentUtils;
import com.blankj.utilcode.utils.ShellUtils;

/**
* <pre>
Expand Down Expand Up @@ -38,8 +35,9 @@ protected void onCreate(Bundle savedInstanceState) {

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

boolean isExists = ActivityUtils.isActivityExists(this, packageName, className);
tvAboutActivity.setText(String.format("Is ImageActivity Exists: %b", isExists));
tvAboutActivity.setText("Is ImageActivity Exists: " + ActivityUtils.isActivityExists(this, packageName, className) +
"\ngetLauncherActivity: " + ActivityUtils.getLauncherActivity(this, packageName)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ protected void onCreate(Bundle savedInstanceState) {

findViewById(R.id.btn_shutdown).setOnClickListener(this);
findViewById(R.id.btn_reboot).setOnClickListener(this);
findViewById(R.id.btn_reboot_to_recovery).setOnClickListener(this);
findViewById(R.id.btn_reboot_to_bootloader).setOnClickListener(this);

tvAboutDevice.setText("isRoot: " + DeviceUtils.isDeviceRoot() +
"\ngetSDKVersion: " + DeviceUtils.getSDKVersion() +
Expand All @@ -47,6 +49,10 @@ public void onClick(View view) {
break;
case R.id.btn_reboot:
DeviceUtils.reboot();
case R.id.btn_reboot_to_recovery:
DeviceUtils.reboot2Recovery();
case R.id.btn_reboot_to_bootloader:
DeviceUtils.reboot2Bootloader();
break;
}
}
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_device.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
android:text="@string/device.reboot"
/>

<Button
android:id="@+id/btn_reboot_to_recovery"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device.reboot_to_recovery"
/>

<Button
android:id="@+id/btn_reboot_to_bootloader"
style="@style/BtnFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/device.reboot_to_bootloader"
/>

<TextView
android:id="@+id/tv_about_device"
style="@style/Font"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/string.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<!--Device相关-->
<string name="device.shutdown">Shutdown</string>
<string name="device.reboot">Reboot</string>
<string name="device.reboot_to_recovery">Reboot To Recovery</string>
<string name="device.reboot_to_bootloader">Reboot To Bootloader</string>

<!--Handler相关-->
<string name="handler.send_msg_after_3s">Send Msg After 3s</string>
Expand Down
1 change: 1 addition & 0 deletions update_log.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
###
#### 16/11/12 最近一直在博客搬家,所以更得有点少,新增重启到recovery和bootloader,新增获取launcher activity
#### 16/11/04 修复README的缺少process的bug
#### 16/11/03 SnackbarUtils中Snackbar持有弱引用来消除内存泄漏
#### 16/11/02 内存泄漏检测中
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;

import java.util.List;

Expand Down Expand Up @@ -59,4 +62,24 @@ public static void launchActivity(Context context, String packageName, String cl
public static void launchActivity(Context context, String packageName, String className, Bundle bundle) {
context.startActivity(IntentUtils.getComponentIntent(packageName, className, bundle));
}

/**
* 获取launcher activity
*
* @param context 上下文
* @param packageName 包名
* @return launcher activity
*/
public static String getLauncherActivity(Context context, String packageName) {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = context.getPackageManager();
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
for (ResolveInfo info : infos) {
if (info.activityInfo.packageName.equals(packageName)) {
return info.activityInfo.name;
}
}
return "no " + packageName;
}
}
16 changes: 16 additions & 0 deletions utilcode/src/main/java/com/blankj/utilcode/utils/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,20 @@ public static void reboot(Context context, String reason) {
e.printStackTrace();
}
}

/**
* 重启到recovery
* <p>需要root权限</p>
*/
public static void reboot2Recovery() {
ShellUtils.execCmd("reboot recovery", true);
}

/**
* 重启到bootloader
* <p>需要root权限</p>
*/
public static void reboot2Bootloader() {
ShellUtils.execCmd("reboot bootloader", true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static byte[] encryptMD5(byte[] data) {
* @return 文件的16进制密文
*/
public static String encryptMD5File2String(String filePath) {
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
File file = StringUtils.isSpace(filePath) ? null : new File(filePath);
return encryptMD5File2String(file);
}

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

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

0 comments on commit 6d99bd5

Please sign in to comment.