| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | package eu.siacs.conversations.utils;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-07 00:33:50 +01:00
										 |  |  | import android.Manifest;
 | 
					
						
							| 
									
										
										
										
											2018-05-12 17:23:37 +02:00
										 |  |  | import android.annotation.SuppressLint;
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | import android.content.Context;
 | 
					
						
							|  |  |  | import android.content.CursorLoader;
 | 
					
						
							| 
									
										
										
										
											2015-02-16 10:06:09 +01:00
										 |  |  | import android.content.pm.PackageManager;
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | import android.database.Cursor;
 | 
					
						
							|  |  |  | import android.net.Uri;
 | 
					
						
							| 
									
										
										
										
											2015-12-07 00:33:50 +01:00
										 |  |  | import android.os.Build;
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | import android.os.Bundle;
 | 
					
						
							|  |  |  | import android.provider.ContactsContract;
 | 
					
						
							|  |  |  | import android.provider.ContactsContract.Profile;
 | 
					
						
							| 
									
										
										
										
											2018-05-12 17:23:37 +02:00
										 |  |  | import android.provider.Settings;
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-31 17:20:21 +02:00
										 |  |  | import java.util.ArrayList;
 | 
					
						
							| 
									
										
										
										
											2015-07-20 14:26:29 +02:00
										 |  |  | import java.util.List;
 | 
					
						
							|  |  |  | import java.util.concurrent.RejectedExecutionException;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | public class PhoneHelper {
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-12 17:23:37 +02:00
										 |  |  | 	@SuppressLint("HardwareIds")
 | 
					
						
							|  |  |  | 	public static String getAndroidId(Context context) {
 | 
					
						
							|  |  |  | 		return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 10:28:51 +01:00
										 |  |  | 	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;
 | 
					
						
							| 
									
										
										
										
											2016-01-20 16:18:15 +01:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-11-17 10:28:51 +01:00
										 |  |  | 		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);
 | 
					
						
							| 
									
										
										
										
											2018-03-12 15:59:35 +01:00
										 |  |  | 		} catch (Throwable e) {
 | 
					
						
							| 
									
										
										
										
											2015-12-07 00:33:50 +01:00
										 |  |  | 			return null;
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-11-17 10:28:51 +01:00
										 |  |  | 		if (cursor == null) {
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | 			return null;
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-11-17 10:28:51 +01:00
										 |  |  | 		final String uri = cursor.moveToFirst() ? cursor.getString(1) : null;
 | 
					
						
							|  |  |  | 		cursor.close();
 | 
					
						
							|  |  |  | 		return uri == null ? null : Uri.parse(uri);
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2015-02-16 10:06:09 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public static String getVersionName(Context context) {
 | 
					
						
							|  |  |  | 		final String packageName = context == null ? null : context.getPackageName();
 | 
					
						
							|  |  |  | 		if (packageName != null) {
 | 
					
						
							|  |  |  | 			try {
 | 
					
						
							|  |  |  | 				return context.getPackageManager().getPackageInfo(packageName, 0).versionName;
 | 
					
						
							| 
									
										
										
										
											2015-08-19 12:24:42 +02:00
										 |  |  | 			} catch (final PackageManager.NameNotFoundException | RuntimeException e) {
 | 
					
						
							| 
									
										
										
										
											2015-02-16 10:06:09 +01:00
										 |  |  | 				return "unknown";
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		} else {
 | 
					
						
							|  |  |  | 			return "unknown";
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2014-10-22 18:38:44 +02:00
										 |  |  | }
 |