移除了主动请求READ_PHONE_STATE权限
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package com.stardust.autojs.runtime.api;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.AudioManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
@@ -98,6 +100,7 @@ public class Device {
|
||||
@SuppressLint("HardwareIds")
|
||||
@Nullable
|
||||
public String getIMEI() {
|
||||
checkReadPhoneStatePermission();
|
||||
try {
|
||||
return ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
|
||||
} catch (SecurityException e) {
|
||||
@@ -105,6 +108,7 @@ public class Device {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("HardwareIds")
|
||||
public String getAndroidId() {
|
||||
return Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
@@ -287,6 +291,16 @@ public class Device {
|
||||
}
|
||||
|
||||
|
||||
private void checkReadPhoneStatePermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (mContext.checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
throw new SecurityException(mContext.getString(R.string.no_read_phone_state_permissin));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// just to avoid warning of null pointer to make android studio happy..
|
||||
@NonNull
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<string name="text_requires_app_version_to_run_the_script" formatted="true">本脚本需要Auto.js版本号%d以上才能运行</string>
|
||||
<string name="text_drawer_open">打开侧拉菜单</string>
|
||||
<string name="text_drawer_close">关闭侧拉菜单</string>
|
||||
<string name="no_read_phone_state_permissin">没有读取设备信息权限</string>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user