aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-11-22 19:08:00 +0100
committerChristian Schneppe <christian@pix-art.de>2017-11-22 19:08:00 +0100
commit53b5dfbe16676a314d5929592a118169a61b4085 (patch)
tree22080325e3da2f483e350a79c64e94d3ac381cd2 /src/main/java/de/pixart/messenger
parentfdff7a4e89ae28ca50c9b17e9dd54b94ba47c207 (diff)
refactore phone helper to ignore security exception
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/utils/PhoneHelper.java63
2 files changed, 31 insertions, 34 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
index ac981f722..7a142a7d3 100644
--- a/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/PublishProfilePictureActivity.java
@@ -141,7 +141,7 @@ public class PublishProfilePictureActivity extends XmppActivity {
}
});
- this.defaultUri = PhoneHelper.getSelfiUri(getApplicationContext());
+ this.defaultUri = PhoneHelper.getProfilePictureUri(getApplicationContext());
}
private void chooseAvatar(boolean crop) {
diff --git a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
index cdc51f729..a8c53f699 100644
--- a/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/PhoneHelper.java
@@ -82,45 +82,24 @@ public class PhoneHelper {
}
}
- private static class NotThrowCursorLoader extends CursorLoader {
-
- public NotThrowCursorLoader(Context c, Uri u, String[] p, String s, String[] sa, String so) {
- super(c, u, p, s, sa, so);
- }
-
- @Override
- public Cursor loadInBackground() {
-
- try {
- return (super.loadInBackground());
- } catch (Throwable e) {
- return (null);
- }
+ public static Uri getProfilePictureUri(Context context) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
+ return null;
}
- }
-
- public static Uri getSelfiUri(Context context) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
- && context.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
+ final String[] projection = new String[]{Profile._ID, Profile.PHOTO_URI};
+ final Cursor cursor;
+ try {
+ cursor = context.getContentResolver().query(Profile.CONTENT_URI, projection, null, null, null);
+ } catch (SecurityException e) {
return null;
}
- String[] mProjection = new String[]{Profile._ID, Profile.PHOTO_URI};
- Cursor mProfileCursor = context.getContentResolver().query(
- Profile.CONTENT_URI, mProjection, null, null, null);
-
- if (mProfileCursor == null || mProfileCursor.getCount() == 0) {
+ if (cursor == null) {
return null;
- } else {
- mProfileCursor.moveToFirst();
- String uri = mProfileCursor.getString(1);
- mProfileCursor.close();
- if (uri == null) {
- return null;
- } else {
- return Uri.parse(uri);
- }
}
+ final String uri = cursor.moveToFirst() ? cursor.getString(1) : null;
+ cursor.close();
+ return uri == null ? null : Uri.parse(uri);
}
public static String getVersionName(Context context) {
@@ -136,6 +115,24 @@ public class PhoneHelper {
}
}
+ private static class NotThrowCursorLoader extends CursorLoader {
+
+ private NotThrowCursorLoader(Context c, Uri u, String[] p, String s, String[] sa, String so) {
+ super(c, u, p, s, sa, so);
+ }
+
+ @Override
+ public Cursor loadInBackground() {
+
+ try {
+ return (super.loadInBackground());
+ } catch (Throwable e) {
+ return (null);
+ }
+ }
+
+ }
+
public static String getOSVersion(Context context) {
return "Android/" + android.os.Build.MODEL + "/" + android.os.Build.VERSION.RELEASE;
}