|
@@ -49,7 +49,6 @@ import androidx.core.content.ContextCompat;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
-import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
@@ -66,6 +65,7 @@ public final class PermissionsUtil {
|
|
public static final int REQUEST_ALL_PERMISSION_REQ_CODE = 1001;
|
|
public static final int REQUEST_ALL_PERMISSION_REQ_CODE = 1001;
|
|
public static final int REQUEST_SINGLE_PERMISSION_REQ_CODE = 1002;
|
|
public static final int REQUEST_SINGLE_PERMISSION_REQ_CODE = 1002;
|
|
public static final int REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE = 2002;
|
|
public static final int REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE = 2002;
|
|
|
|
+ public static final int REQUEST_INSTALL_PACKAGES_REQ_CODE = 3002;
|
|
|
|
|
|
private PermissionsUtil() {
|
|
private PermissionsUtil() {
|
|
}
|
|
}
|
|
@@ -105,6 +105,16 @@ public final class PermissionsUtil {
|
|
activity.startActivityForResult(intent, REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE);
|
|
activity.startActivityForResult(intent, REQUEST_MANAGE_EXTERNAL_STORAGE_REQ_CODE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } else if (permission.equals(Manifest.permission.REQUEST_INSTALL_PACKAGES)) {
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !activity.getPackageManager().canRequestPackageInstalls()) {
|
|
|
|
+ try {
|
|
|
|
+ Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
|
|
|
|
+ intent.setData(Uri.parse(String.format("package:%s", activity.getPackageName())));
|
|
|
|
+ activity.startActivityForResult(intent, REQUEST_INSTALL_PACKAGES_REQ_CODE);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ Log.e(TAG, "Unable to request permission " + Manifest.permission.REQUEST_INSTALL_PACKAGES);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
PermissionInfo permissionInfo = getPermissionInfo(activity, permission);
|
|
PermissionInfo permissionInfo = getPermissionInfo(activity, permission);
|
|
int protectionLevel = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? permissionInfo.getProtection() : permissionInfo.protectionLevel;
|
|
int protectionLevel = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P ? permissionInfo.getProtection() : permissionInfo.protectionLevel;
|
|
@@ -215,7 +225,7 @@ public final class PermissionsUtil {
|
|
try {
|
|
try {
|
|
manifestPermissions = getManifestPermissions(activity);
|
|
manifestPermissions = getManifestPermissions(activity);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ Log.e(TAG, "Unable to retrieve manifest permissions", e);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -242,7 +252,7 @@ public final class PermissionsUtil {
|
|
try {
|
|
try {
|
|
manifestPermissions = getManifestPermissions(context);
|
|
manifestPermissions = getManifestPermissions(context);
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ Log.e(TAG, "Unable to retrieve manifest permissions", e);
|
|
return new String[0];
|
|
return new String[0];
|
|
}
|
|
}
|
|
if (manifestPermissions.isEmpty()) {
|
|
if (manifestPermissions.isEmpty()) {
|