Skip to content

Commit

Permalink
v6.10: Fixed a problem opening multiple settings sheets from the desk…
Browse files Browse the repository at this point in the history
…top. Fixed an error of auto determining the device phone number
  • Loading branch information
vmayorow committed Nov 2, 2024
1 parent 51641c5 commit 976292f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
7 changes: 2 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ android {
defaultConfig {
applicationId "com.hmdm.launcher"
minSdkVersion 16
// To change to 30, file access should be updated: https://developer.android.com/training/data-storage/manage-all-files
// To avoid extra step during initial setup, let's keep the target SDK version as 29 as long as possible
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 34
versionCode 15090
versionName "6.09"
versionCode 15100
versionName "6.10"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
dataBinding {
enabled = true
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
Expand Down Expand Up @@ -102,6 +104,8 @@
<uses-permission android:name="android.permission.MANAGE_DEVICE_POLICY_WIPE_DATA" />

<uses-sdk tools:overrideLibrary="com.google.zxing.client.android" />
<uses-feature
android:name="android.hardware.telephony" android:required="false" />

<application
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ protected void chooseApp(AppInfo appInfo) {
if (appInfo.intent != null) {
try {
Intent i = new Intent(appInfo.intent);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
parentActivity.startActivity(i);
} catch (Exception e) {
Toast.makeText(parentActivity, parentActivity.getString(R.string.activity_not_found, appInfo.intent), Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ public static String getPhoneNumber(Context context) {
}
return tMgr.getLine1Number();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Expand Down Expand Up @@ -309,6 +310,7 @@ public static String getImsi(Context context, int slot) {
@SuppressLint( { "MissingPermission" } )
public static String getPhoneNumber(Context context, int slot) {
try {
Utils.autoGrantPhonePermission(context);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
if (slot == 0) {
return getPhoneNumber(context);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hmdm/launcher/util/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static void autoSetAccessibilityPermission(Context context, String packag

static final int OP_WRITE_SETTINGS = 23;
static final int OP_SYSTEM_ALERT_WINDOW = 24;
static final int APP_OP_GET_USAGE_STATS = 43;
static final int OP_GET_USAGE_STATS = 43;
static final int OP_MANAGE_EXTERNAL_STORAGE = 92;

@TargetApi(Build.VERSION_CODES.KITKAT)
Expand All @@ -163,7 +163,7 @@ public static boolean autoSetOverlayPermission(Context context, String packageNa

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean autoSetUsageStatsPermission(Context context, String packageName) {
return autoSetPermission(context, packageName, APP_OP_GET_USAGE_STATS, "Usage history");
return autoSetPermission(context, packageName, OP_GET_USAGE_STATS, "Usage history");
}

@TargetApi(Build.VERSION_CODES.KITKAT)
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/hmdm/launcher/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ public static boolean autoGrantPhonePermission(Context context) {
return false;
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (devicePolicyManager.getPermissionGrantState(adminComponentName,
context.getPackageName(), Manifest.permission.READ_PHONE_NUMBERS) != DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED) {
boolean success = devicePolicyManager.setPermissionGrantState(adminComponentName,
context.getPackageName(), Manifest.permission.READ_PHONE_NUMBERS, DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
if (!success) {
return false;
}
}
if (devicePolicyManager.getPermissionGrantState(adminComponentName,
context.getPackageName(), Manifest.permission.READ_SMS) != DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED) {
boolean success = devicePolicyManager.setPermissionGrantState(adminComponentName,
context.getPackageName(), Manifest.permission.READ_SMS, DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED);
if (!success) {
return false;
}
}
}
} catch (NoSuchMethodError e) {
// This exception is raised on Android 5.1
e.printStackTrace();
Expand Down

0 comments on commit 976292f

Please sign in to comment.