forked from jens/Automation
		
	ringtone
This commit is contained in:
		| @@ -12,6 +12,7 @@ import android.location.Location; | ||||
| import android.location.LocationListener; | ||||
| import android.location.LocationManager; | ||||
| import android.net.Uri; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.os.Looper; | ||||
| import android.view.View; | ||||
| @@ -83,17 +84,17 @@ public class ActivityManagePoi extends Activity | ||||
| 		bSavePoi = (Button)findViewById(R.id.bSavePoi); | ||||
| 		bSavePoi.setOnClickListener(new OnClickListener() | ||||
| 		{ | ||||
|         @Override | ||||
|         public void onClick(View v) | ||||
|         { | ||||
| 			hideKeyboard(); | ||||
| 			@Override | ||||
| 			public void onClick(View v) | ||||
| 			{ | ||||
| 				hideKeyboard(); | ||||
|  | ||||
|             if(ActivityMainPoi.poiToEdit == null) | ||||
| 				createPoi(); | ||||
|             else | ||||
| 				changePoi(); | ||||
|         } | ||||
|     }); | ||||
| 				if(ActivityMainPoi.poiToEdit == null) | ||||
| 					createPoi(); | ||||
| 				else | ||||
| 					changePoi(); | ||||
| 			} | ||||
| 		}); | ||||
| 		 | ||||
| 		ibShowOnMap.setOnClickListener(new OnClickListener() | ||||
| 		{			 | ||||
| @@ -136,42 +137,45 @@ public class ActivityManagePoi extends Activity | ||||
| 	 | ||||
| 	private void getLocation() | ||||
| 	{ | ||||
| 		Criteria critNetwork = new Criteria(); | ||||
| 		critNetwork.setPowerRequirement(Criteria.POWER_LOW); | ||||
| 		critNetwork.setAltitudeRequired(false); | ||||
| 		critNetwork.setSpeedRequired(false); | ||||
| 		critNetwork.setBearingRequired(false); | ||||
| 		critNetwork.setCostAllowed(false); | ||||
| 		critNetwork.setAccuracy(Criteria.ACCURACY_COARSE); | ||||
| 		Criteria criteriaNetwork = new Criteria(); | ||||
| 		criteriaNetwork.setPowerRequirement(Criteria.POWER_LOW); | ||||
| 		criteriaNetwork.setAltitudeRequired(false); | ||||
| 		criteriaNetwork.setSpeedRequired(false); | ||||
| 		criteriaNetwork.setBearingRequired(false); | ||||
| 		criteriaNetwork.setCostAllowed(false); | ||||
| 		criteriaNetwork.setAccuracy(Criteria.ACCURACY_COARSE); | ||||
|  | ||||
| 		Criteria criteriaGps = new Criteria(); | ||||
| 		criteriaGps.setAltitudeRequired(false); | ||||
| 		criteriaGps.setSpeedRequired(false); | ||||
| 		criteriaGps.setBearingRequired(false); | ||||
| 		criteriaGps.setCostAllowed(true); | ||||
| 		criteriaGps.setAccuracy(Criteria.ACCURACY_FINE); | ||||
| 		 | ||||
| 		Criteria critGps = new Criteria(); | ||||
| 		critGps.setAltitudeRequired(false); | ||||
| 		critGps.setSpeedRequired(false); | ||||
| 		critGps.setBearingRequired(false); | ||||
| 		critGps.setCostAllowed(true); | ||||
| 		critGps.setAccuracy(Criteria.ACCURACY_FINE); | ||||
| 		 | ||||
| 		String provider1 = myLocationManager.getBestProvider(critNetwork, true); | ||||
| 		String provider2 = myLocationManager.getBestProvider(critGps, true); | ||||
| 		String provider1 = myLocationManager.getBestProvider(criteriaNetwork, true); | ||||
| 		String provider2 = myLocationManager.getBestProvider(criteriaGps, true); | ||||
| //		String provider3 = myLocationManager.getProvider("wifi"); | ||||
| 		 | ||||
| 		if(provider1 == null | provider2 == null) | ||||
| 		if(provider1 == null || provider2 == null) | ||||
| 		{ | ||||
| 			Toast.makeText(this, getResources().getString(R.string.logNoSuitableProvider), Toast.LENGTH_LONG).show(); | ||||
| 			return; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			if(provider1.equals(provider2)) | ||||
| 				Miscellaneous.logEvent("i", "POI Manager", "Both location providers are equal. Only one will be used.", 4); | ||||
|  | ||||
| 			locationSearchStart = Calendar.getInstance(); | ||||
| 			startTimeout(); | ||||
|  | ||||
| 			if(!Settings.privacyLocationing || !ConnectivityReceiver.isDataConnectionAvailable(AutomationService.getInstance())) | ||||
| 			if(!Settings.privacyLocationing && !ConnectivityReceiver.isDataConnectionAvailable(Miscellaneous.getAnyContext()) && !provider1.equals(provider2)) | ||||
| 			{ | ||||
| 				Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider1, 3); | ||||
| 				myLocationManager.requestLocationUpdates(provider1, 500, Settings.satisfactoryAccuracyNetwork, myLocationListenerNetwork); | ||||
| 			} | ||||
| 			else | ||||
| 				Miscellaneous.logEvent("i", "POI Manager", "Skipping network location query because private locationing is active.", 4); | ||||
| 				Miscellaneous.logEvent("i", "POI Manager", "Skipping network location.", 4); | ||||
|  | ||||
| 			Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider2, 3); | ||||
| 			myLocationManager.requestLocationUpdates(provider2, 500, Settings.satisfactoryAccuracyGps, myLocationListenerGps); | ||||
| @@ -310,7 +314,21 @@ public class ActivityManagePoi extends Activity | ||||
| 			public void onClick(DialogInterface dialog, int which) | ||||
| 			{ | ||||
| 				progressDialog = ProgressDialog.show(ActivityManagePoi.this, "", getResources().getString(R.string.gettingPosition), true, true); | ||||
| 				getLocation(); | ||||
| 				if(Build.VERSION.SDK_INT >= 31) | ||||
| 				{ | ||||
| 					AlertDialog dia = Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.locationNotWorkingOn12), ActivityManagePoi.this); | ||||
| 					dia.setOnDismissListener(new DialogInterface.OnDismissListener() | ||||
| 					{ | ||||
| 						@Override | ||||
| 						public void onDismiss(DialogInterface dialogInterface) | ||||
| 						{ | ||||
| 							getLocation(); | ||||
| 						} | ||||
| 					}); | ||||
| 					dia.show(); | ||||
| 				} | ||||
| 				else | ||||
| 					getLocation(); | ||||
| 			} | ||||
| 		}; | ||||
| 		alertDialogBuilder.setMessage(text).setPositiveButton("Ok", dialogClickListener); | ||||
|   | ||||
| @@ -520,6 +520,9 @@ public class ActivityPermissions extends Activity | ||||
|                         addToArrayListUnique(Manifest.permission.MODIFY_AUDIO_SETTINGS, requiredPermissions); | ||||
|                         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) | ||||
|                             addToArrayListUnique(Manifest.permission.ACCESS_NOTIFICATION_POLICY, requiredPermissions); | ||||
|                         Profile targetProfile = Profile.getByName(action.getParameter2()); | ||||
|                         if(targetProfile.changeIncomingCallsRingtone || targetProfile.changeNotificationRingtone) | ||||
|                             addToArrayListUnique(Manifest.permission.READ_EXTERNAL_STORAGE, requiredPermissions); | ||||
|                         break; | ||||
|                     case disableScreenRotation: | ||||
|                         addToArrayListUnique(Manifest.permission.WRITE_SETTINGS, requiredPermissions); | ||||
| @@ -861,6 +864,8 @@ public class ActivityPermissions extends Activity | ||||
|             case Manifest.permission.READ_EXTERNAL_STORAGE: | ||||
|                 for(String ruleName : getRulesUsing(Action.Action_Enum.playSound)) | ||||
|                     usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); | ||||
|                 for(String ruleName : getRulesUsing(Action.Action_Enum.changeSoundProfile)) | ||||
|                     usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName)); | ||||
|                 break; | ||||
|             case Manifest.permission.BIND_DEVICE_ADMIN: | ||||
|                 for(String ruleName : getRulesUsing(Action.Action_Enum.turnScreenOnOrOff)) | ||||
|   | ||||
| @@ -327,6 +327,12 @@ public class AutomationService extends Service implements OnInitListener | ||||
| 		ReceiverCoordinator.startAllReceivers(); | ||||
|  | ||||
| 		PackageReplacedReceiver.setHasServiceBeenRunning(true, this); | ||||
|  | ||||
| 		for(Rule r : Rule.getRuleCollection()) | ||||
| 		{ | ||||
| 			if(r.getsGreenLight(AutomationService.this)) | ||||
| 				r.activate(AutomationService.this, false); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	protected void startLocationProvider() | ||||
|   | ||||
| @@ -8,6 +8,7 @@ import android.app.NotificationChannel; | ||||
| import android.app.NotificationManager; | ||||
| import android.app.PendingIntent; | ||||
| import android.app.Service; | ||||
| import android.content.ContentUris; | ||||
| import android.content.Context; | ||||
| import android.content.DialogInterface; | ||||
| import android.content.Intent; | ||||
| @@ -24,6 +25,7 @@ import android.os.AsyncTask; | ||||
| import android.os.Build; | ||||
| import android.os.Environment; | ||||
| import android.os.IBinder; | ||||
| import android.provider.DocumentsContract; | ||||
| import android.provider.MediaStore; | ||||
| import android.provider.Settings.Secure; | ||||
| import android.telephony.PhoneNumberUtils; | ||||
| @@ -73,8 +75,10 @@ import java.math.BigDecimal; | ||||
| import java.math.RoundingMode; | ||||
| import java.net.HttpURLConnection; | ||||
| import java.net.URL; | ||||
| import java.security.DigestInputStream; | ||||
| import java.security.KeyManagementException; | ||||
| import java.security.KeyStore; | ||||
| import java.security.MessageDigest; | ||||
| import java.security.NoSuchAlgorithmException; | ||||
| import java.security.cert.CertificateException; | ||||
| import java.security.cert.X509Certificate; | ||||
| @@ -1189,7 +1193,8 @@ public class Miscellaneous extends Service | ||||
|  | ||||
| 	public static double round(double value, int places) | ||||
| 	{ | ||||
| 		if (places < 0) throw new IllegalArgumentException(); | ||||
| 		if (places < 0) | ||||
| 			throw new IllegalArgumentException(); | ||||
|  | ||||
| 		BigDecimal bd = new BigDecimal(Double.toString(value)); | ||||
| 		bd = bd.setScale(places, RoundingMode.HALF_UP); | ||||
| @@ -1201,7 +1206,7 @@ public class Miscellaneous extends Service | ||||
| 		Cursor cursor = null; | ||||
| 		try | ||||
| 		{ | ||||
| 			String[] proj = { MediaStore.Images.Media.DATA }; | ||||
| 			String[] proj = { MediaStore.Images.Media.DATA, MediaStore.Audio.Media.DATA }; | ||||
| 			cursor = context.getContentResolver().query(contentUri,  proj, null, null, null); | ||||
| 			int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); | ||||
| 			cursor.moveToFirst(); | ||||
| @@ -1221,6 +1226,114 @@ public class Miscellaneous extends Service | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public static String getRealPathFromURI2(final Context context, final Uri uri) | ||||
| 	{ | ||||
| 		final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; | ||||
|  | ||||
| 		// DocumentProvider | ||||
| 		if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) | ||||
| 		{ | ||||
| 			// ExternalStorageProvider | ||||
| 			if (isExternalStorageDocument(uri)) | ||||
| 			{ | ||||
| 				final String docId = DocumentsContract.getDocumentId(uri); | ||||
| 				final String[] split = docId.split(":"); | ||||
| 				final String type = split[0]; | ||||
|  | ||||
| 				if ("primary".equalsIgnoreCase(type)) | ||||
| 				{ | ||||
| 					return Environment.getExternalStorageDirectory() + "/" + split[1]; | ||||
| 				} | ||||
| 			} | ||||
| 			// DownloadsProvider | ||||
| 			else if (isDownloadsDocument(uri)) | ||||
| 			{ | ||||
|  | ||||
| 				final String id = DocumentsContract.getDocumentId(uri); | ||||
| 				final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); | ||||
|  | ||||
| 				return getDataColumn(context, contentUri, null, null); | ||||
| 			} | ||||
| 			// MediaProvider | ||||
| 			else if (isMediaDocument(uri)) | ||||
| 			{ | ||||
| 				final String docId = DocumentsContract.getDocumentId(uri); | ||||
| 				final String[] split = docId.split(":"); | ||||
| 				final String type = split[0]; | ||||
|  | ||||
| 				Uri contentUri = null; | ||||
| 				if ("image".equals(type)) | ||||
| 				{ | ||||
| 					contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; | ||||
| 				} | ||||
| 				else if ("video".equals(type)) | ||||
| 				{ | ||||
| 					contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; | ||||
| 				} | ||||
| 				else if ("audio".equals(type)) | ||||
| 				{ | ||||
| 					contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; | ||||
| 				} | ||||
|  | ||||
| 				final String selection = "_id=?"; | ||||
| 				final String[] selectionArgs = new String[] { split[1] }; | ||||
|  | ||||
| 				return getDataColumn(context, contentUri, selection, selectionArgs); | ||||
| 			} | ||||
| 		} | ||||
| 		// MediaStore (and general) | ||||
| 		else if ("content".equalsIgnoreCase(uri.getScheme())) | ||||
| 		{ | ||||
| 			return getDataColumn(context, uri, null, null); | ||||
| 		} | ||||
| 		// File | ||||
| 		else if ("file".equalsIgnoreCase(uri.getScheme())) | ||||
| 		{ | ||||
| 			return uri.getPath(); | ||||
| 		} | ||||
|  | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) | ||||
| 	{ | ||||
| 		Cursor cursor = null; | ||||
| 		final String column = "_data"; | ||||
| 		final String[] projection = { column }; | ||||
|  | ||||
| 		try | ||||
| 		{ | ||||
| 			cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, | ||||
| 					null); | ||||
| 			if (cursor != null && cursor.moveToFirst()) | ||||
| 			{ | ||||
| 				final int column_index = cursor.getColumnIndexOrThrow(column); | ||||
| 				return cursor.getString(column_index); | ||||
| 			} | ||||
| 		} | ||||
| 		finally | ||||
| 		{ | ||||
| 			if (cursor != null) | ||||
| 				cursor.close(); | ||||
| 		} | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	public static boolean isExternalStorageDocument(Uri uri) | ||||
| 	{ | ||||
| 		return "com.android.externalstorage.documents".equals(uri.getAuthority()); | ||||
| 	} | ||||
|  | ||||
| 	public static boolean isDownloadsDocument(Uri uri) | ||||
| 	{ | ||||
| 		return "com.android.providers.downloads.documents".equals(uri.getAuthority()); | ||||
| 	} | ||||
|  | ||||
| 	public static boolean isMediaDocument(Uri uri) | ||||
| 	{ | ||||
| 		return "com.android.providers.media.documents".equals(uri.getAuthority()); | ||||
| 	} | ||||
|  | ||||
| 	public static Method getClassMethodReflective(String className, String methodName) | ||||
| 	{ | ||||
| 		Class foundClass = null; | ||||
| @@ -1754,4 +1867,35 @@ public class Miscellaneous extends Service | ||||
|  | ||||
| 		return null; | ||||
| 	} | ||||
|  | ||||
| 	public static String checksumSha(String filepath) throws IOException | ||||
| 	{ | ||||
| 		try | ||||
| 		{ | ||||
| 			MessageDigest md = null; | ||||
| 			md = MessageDigest.getInstance("SHA-256"); | ||||
|  | ||||
| 			// file hashing with DigestInputStream | ||||
| 			try (DigestInputStream dis = new DigestInputStream(new FileInputStream(filepath), md)) | ||||
| 			{ | ||||
| 				while (dis.read() != -1) | ||||
| 					; //empty loop to clear the data | ||||
| 				md = dis.getMessageDigest(); | ||||
| 			} | ||||
|  | ||||
| 			// bytes to hex | ||||
| 			StringBuilder result = new StringBuilder(); | ||||
| 			for (byte b : md.digest()) | ||||
| 			{ | ||||
| 				result.append(String.format("%02x", b)); | ||||
| 			} | ||||
| 			return result.toString(); | ||||
| 		} | ||||
| 		catch (NoSuchAlgorithmException e) | ||||
| 		{ | ||||
| 			Miscellaneous.logEvent("e", "shaChecksum", Log.getStackTraceString(e), 2); | ||||
| 		} | ||||
|  | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @@ -4,10 +4,12 @@ import android.app.NotificationManager; | ||||
| import android.content.ContentValues; | ||||
| import android.content.Context; | ||||
| import android.media.AudioManager; | ||||
| import android.media.Ringtone; | ||||
| import android.media.RingtoneManager; | ||||
| import android.net.Uri; | ||||
| import android.os.Build; | ||||
| import android.provider.MediaStore; | ||||
| import android.provider.Settings; | ||||
| import android.util.Log; | ||||
| import android.widget.Toast; | ||||
|  | ||||
| @@ -604,65 +606,107 @@ public class Profile implements Comparable<Profile> | ||||
| 		try | ||||
| 		{ | ||||
| 			AudioManager am = (AudioManager) Miscellaneous.getAnyContext().getSystemService(Context.AUDIO_SERVICE); | ||||
| 			NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); | ||||
| 			NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); | ||||
|  | ||||
| 			if(changeSoundMode) | ||||
| 			if (changeSoundMode) | ||||
| 			{ | ||||
| 				if(am.getRingerMode() != soundMode) | ||||
| 				if (am.getRingerMode() != soundMode) | ||||
| 					return false; | ||||
| 			} | ||||
|  | ||||
| 			if(changeDndMode && Build.VERSION.SDK_INT >= 23) | ||||
| 			if (changeDndMode && Build.VERSION.SDK_INT >= 23) | ||||
| 			{ | ||||
| 				if(mNotificationManager.getCurrentInterruptionFilter() != dndMode) | ||||
| 				if (mNotificationManager.getCurrentInterruptionFilter() != dndMode) | ||||
| 					return false; | ||||
| 			} | ||||
|  | ||||
| 			if(changeVolumeMusicVideoGameMedia) | ||||
| 			if (changeVolumeMusicVideoGameMedia) | ||||
| 			{ | ||||
| 				if(am.getStreamVolume(AudioManager.STREAM_MUSIC) != volumeMusic) | ||||
| 				if (am.getStreamVolume(AudioManager.STREAM_MUSIC) != volumeMusic) | ||||
| 					return false; | ||||
| 			} | ||||
|  | ||||
| 			if(changeVolumeNotifications) | ||||
| 			if (changeVolumeNotifications) | ||||
| 			{ | ||||
| 				if(am.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != volumeNotifications) | ||||
| 				if (am.getStreamVolume(AudioManager.STREAM_NOTIFICATION) != volumeNotifications) | ||||
| 					return false; | ||||
| 			} | ||||
|  | ||||
| 			if(changeVolumeAlarms) | ||||
| 			if (changeVolumeAlarms) | ||||
| 			{ | ||||
| 				if(am.getStreamVolume(AudioManager.STREAM_ALARM) != volumeAlarms) | ||||
| 				if (am.getStreamVolume(AudioManager.STREAM_ALARM) != volumeAlarms) | ||||
| 					return false; | ||||
| 			} | ||||
|  | ||||
| //			if(changeIncomingCallsRingtone) | ||||
| //			{ | ||||
| //				if (incomingCallsRingtone != null) | ||||
| //				{ | ||||
| //					applyRingTone(incomingCallsRingtone, RingtoneManager.TYPE_RINGTONE, context); | ||||
| //				} | ||||
| //			} | ||||
|  | ||||
| 			if(changeVibrateWhenRinging) | ||||
| 			/*if (changeIncomingCallsRingtone) | ||||
| 			{ | ||||
| 				if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) | ||||
| 				if (incomingCallsRingtone != null) | ||||
| 				{ | ||||
| 					Uri ringtone_uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE); | ||||
|  | ||||
| 					if (ringtone_uri != null) | ||||
| 					{ | ||||
| 						// if ringtone_uri is null get Default Ringtone | ||||
| 						ringtone_uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); | ||||
|  | ||||
| 						Ringtone currentRingtone = RingtoneManager.getRingtone(context, ringtone_uri); | ||||
| 						String title = currentRingtone.getTitle(context); | ||||
| *//*						Ringtone desiredRingtone = RingtoneManager.getRingtone(context, Uri.fromFile(notificationRingtone)); | ||||
| 						boolean result = currentRingtone.equals(desiredRingtone);*//* | ||||
|  | ||||
| 						Uri desired_ringtone = MediaStore.Audio.Media.getContentUriForPath(incomingCallsRingtone.getAbsolutePath()); | ||||
|  | ||||
| //						File currentRingtoneFile = new File(Miscellaneous.getRealPathFromURI(context, ringtone_uri)); | ||||
| 						String currentChecksum = Miscellaneous.checksumSha(ringtone_uri.getPath()); | ||||
| 						String desiredChecksum = Miscellaneous.checksumSha(incomingCallsRingtone.getAbsolutePath()); | ||||
|  | ||||
| 						if (!currentChecksum.equals(desiredChecksum)) | ||||
| 							return false; | ||||
| 					} | ||||
| 				} | ||||
| 			}*/ | ||||
|  | ||||
| 			if (changeVibrateWhenRinging) | ||||
| 			{ | ||||
| 				if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) | ||||
| 				{ | ||||
| 					int currentSetting = android.provider.Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing"); | ||||
| 					if(currentSetting != Miscellaneous.boolToInt(vibrateWhenRinging)) | ||||
| 					if (currentSetting != Miscellaneous.boolToInt(vibrateWhenRinging)) | ||||
| 						return false; | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					int currentSetting = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER); | ||||
| 					if(currentSetting != Miscellaneous.boolToInt(vibrateWhenRinging)) | ||||
| 					if (currentSetting != Miscellaneous.boolToInt(vibrateWhenRinging)) | ||||
| 						return false; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| //			if(changeNotificationRingtone) | ||||
| //				if(notificationRingtone != null) | ||||
| //					applyRingTone(notificationRingtone, RingtoneManager.TYPE_NOTIFICATION, context); | ||||
| 			/*if (changeNotificationRingtone) | ||||
| 			{ | ||||
| 				if (notificationRingtone != null) | ||||
| 				{ | ||||
| 					Uri ringtone_uri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION); | ||||
|  | ||||
| 					if (ringtone_uri == null) | ||||
| 					{ | ||||
| 						// if ringtone_uri is null get Default Ringtone | ||||
| 						ringtone_uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); | ||||
|  | ||||
| 						File currentRingtone = new File(Settings.System.DEFAULT_NOTIFICATION_URI.getPath()); | ||||
|  | ||||
| //						File currentRingtone = new File(Miscellaneous.getRealPathFromURI(context, ringtone_uri)); | ||||
|  | ||||
| 						String currentChecksum = Miscellaneous.checksumSha(currentRingtone.getAbsolutePath()); | ||||
| 						String desiredChecksum = Miscellaneous.checksumSha(notificationRingtone.getAbsolutePath()); | ||||
|  | ||||
| 						if(!currentChecksum.equals(desiredChecksum)) | ||||
| 							return false; | ||||
| 					} | ||||
| 					else | ||||
| 						return false; | ||||
| 				} | ||||
| 			}*/ | ||||
|  | ||||
| 			if(changeScreenLockUnlockSound) | ||||
| 			{ | ||||
|   | ||||
| @@ -81,54 +81,54 @@ public class Settings implements SharedPreferences | ||||
| 	 */ | ||||
| 	public static final String dateFormat = "E dd.MM.yyyy HH:mm:ss:ssss"; | ||||
|  | ||||
| 	protected static final int default_positioningEngine = 0; | ||||
| 	protected static final long default_minimumDistanceChangeForGpsUpdate = 100; | ||||
| 	protected static final long default_minimumDistanceChangeForNetworkUpdate = 500; // in Meters | ||||
| 	protected static final long default_satisfactoryAccuracyGps = 50;	 | ||||
| 	protected static final long default_satisfactoryAccuracyNetwork = 1000; | ||||
| 	protected static final int default_gpsTimeout = 300;	// seconds | ||||
| 	protected static final long default_minimumTimeBetweenUpdate = 30000; // in Milliseconds | ||||
| 	protected static final boolean default_startServiceAtSystemBoot = false; | ||||
| 	protected static final boolean default_writeLogFile = false; | ||||
| 	protected static final long default_logLevel = 2; | ||||
| 	protected static final int default_logFileMaxSize = 10; | ||||
| 	protected static final boolean default_useTextToSpeechOnNormal = false; | ||||
| 	protected static final boolean default_useTextToSpeechOnVibrate = false; | ||||
| 	protected static final boolean default_useTextToSpeechOnSilent = false; | ||||
| 	protected static final boolean default_muteTextToSpeechDuringCalls = true; | ||||
| 	protected static final boolean default_useWifiForPositioning = true; | ||||
| 	protected static final boolean default_useAccelerometerForPositioning = true; | ||||
| 	protected static final long default_useAccelerometerAfterIdleTime = 5; | ||||
| 	protected static final long default_accelerometerMovementThreshold = 2; | ||||
| 	protected static final long default_speedMaximumTimeBetweenLocations = 4; | ||||
| 	protected static final long default_timeBetweenNoiseLevelMeasurements = 60; | ||||
| 	protected static final long default_lengthOfNoiseLevelMeasurements = 5; | ||||
| 	protected static final long default_referenceValueForNoiseLevelMeasurements = 20; | ||||
| 	protected static final boolean default_hasServiceBeenRunning = false; | ||||
| 	protected static final boolean default_startServiceAfterAppUpdate = true; | ||||
| 	protected static final boolean default_startNewThreadForRuleActivation = true; | ||||
| 	protected static final boolean default_showIconWhenServiceIsRunning = true; | ||||
| 	protected static final boolean default_httpAcceptAllCertificates = false; | ||||
| 	protected static final int default_httpAttempts = 3; | ||||
| 	protected static final int default_httpAttemptsTimeout = 60; | ||||
| 	protected static final int default_httpAttemptGap = 2; | ||||
| 	protected static final PointOfInterest default_lastActivePoi = null; | ||||
| 	protected static final boolean default_rememberLastActivePoi = true; | ||||
| 	protected static final int default_locationRingBufferSize=3; | ||||
| 	protected static final long default_timeBetweenProcessMonitorings = 60; | ||||
| 	protected static final long default_acceptDevicePositionSignalEveryX_MilliSeconds = 1000; | ||||
| 	protected static final int default_activityDetectionFrequency = 60; | ||||
| 	protected static final int default_activityDetectionRequiredProbability = 75; | ||||
| 	protected static final boolean default_privacyLocationing = false; | ||||
| 	protected static final int default_startScreen = 0; | ||||
| 	protected static final int default_tabsPlacement = 0; | ||||
| 	protected static final boolean default_executeRulesAndProfilesWithSingleClick = false; | ||||
| 	protected static final boolean default_displayNewsOnMainScreen = false; | ||||
| 	protected static final boolean default_automaticUpdateCheck = false; | ||||
| 	protected static final boolean default_lockSoundChanges = false; | ||||
| 	protected static final long default_lastNewsPolltime = -1; | ||||
| 	protected static final long default_lastUpdateCheck = -1; | ||||
| 	protected static final long default_musicCheckFrequency = 2500; | ||||
| 	public static final int default_positioningEngine = 0; | ||||
| 	public static final long default_minimumDistanceChangeForGpsUpdate = 100; | ||||
| 	public static final long default_minimumDistanceChangeForNetworkUpdate = 500; // in Meters | ||||
| 	public static final long default_satisfactoryAccuracyGps = 50;	 | ||||
| 	public static final long default_satisfactoryAccuracyNetwork = 1000; | ||||
| 	public static final int default_gpsTimeout = 300;	// seconds | ||||
| 	public static final long default_minimumTimeBetweenUpdate = 30000; // in Milliseconds | ||||
| 	public static final boolean default_startServiceAtSystemBoot = false; | ||||
| 	public static final boolean default_writeLogFile = false; | ||||
| 	public static final long default_logLevel = 2; | ||||
| 	public static final int default_logFileMaxSize = 10; | ||||
| 	public static final boolean default_useTextToSpeechOnNormal = false; | ||||
| 	public static final boolean default_useTextToSpeechOnVibrate = false; | ||||
| 	public static final boolean default_useTextToSpeechOnSilent = false; | ||||
| 	public static final boolean default_muteTextToSpeechDuringCalls = true; | ||||
| 	public static final boolean default_useWifiForPositioning = true; | ||||
| 	public static final boolean default_useAccelerometerForPositioning = true; | ||||
| 	public static final long default_useAccelerometerAfterIdleTime = 5; | ||||
| 	public static final long default_accelerometerMovementThreshold = 2; | ||||
| 	public static final long default_speedMaximumTimeBetweenLocations = 4; | ||||
| 	public static final long default_timeBetweenNoiseLevelMeasurements = 60; | ||||
| 	public static final long default_lengthOfNoiseLevelMeasurements = 5; | ||||
| 	public static final long default_referenceValueForNoiseLevelMeasurements = 20; | ||||
| 	public static final boolean default_hasServiceBeenRunning = false; | ||||
| 	public static final boolean default_startServiceAfterAppUpdate = true; | ||||
| 	public static final boolean default_startNewThreadForRuleActivation = true; | ||||
| 	public static final boolean default_showIconWhenServiceIsRunning = true; | ||||
| 	public static final boolean default_httpAcceptAllCertificates = false; | ||||
| 	public static final int default_httpAttempts = 3; | ||||
| 	public static final int default_httpAttemptsTimeout = 60; | ||||
| 	public static final int default_httpAttemptGap = 2; | ||||
| 	public static final PointOfInterest default_lastActivePoi = null; | ||||
| 	public static final boolean default_rememberLastActivePoi = true; | ||||
| 	public static final int default_locationRingBufferSize=3; | ||||
| 	public static final long default_timeBetweenProcessMonitorings = 60; | ||||
| 	public static final long default_acceptDevicePositionSignalEveryX_MilliSeconds = 1000; | ||||
| 	public static final int default_activityDetectionFrequency = 60; | ||||
| 	public static final int default_activityDetectionRequiredProbability = 75; | ||||
| 	public static final boolean default_privacyLocationing = false; | ||||
| 	public static final int default_startScreen = 0; | ||||
| 	public static final int default_tabsPlacement = 0; | ||||
| 	public static final boolean default_executeRulesAndProfilesWithSingleClick = false; | ||||
| 	public static final boolean default_displayNewsOnMainScreen = false; | ||||
| 	public static final boolean default_automaticUpdateCheck = false; | ||||
| 	public static final boolean default_lockSoundChanges = false; | ||||
| 	public static final long default_lastNewsPolltime = -1; | ||||
| 	public static final long default_lastUpdateCheck = -1; | ||||
| 	public static final long default_musicCheckFrequency = 2500; | ||||
|  | ||||
|     @Override | ||||
| 	public boolean contains(String arg0) | ||||
| @@ -265,6 +265,9 @@ public class Settings implements SharedPreferences | ||||
|  | ||||
| 			musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency))); | ||||
|  | ||||
| 			if(Settings.musicCheckFrequency == 0) | ||||
| 				Settings.musicCheckFrequency = Settings.default_musicCheckFrequency; | ||||
|  | ||||
| 			executeRulesAndProfilesWithSingleClick = prefs.getBoolean("executeRulesAndProfilesWithSingleClick", default_executeRulesAndProfilesWithSingleClick); | ||||
| 			automaticUpdateCheck = prefs.getBoolean("automaticUpdateCheck", default_automaticUpdateCheck); | ||||
| 			displayNewsOnMainScreen = prefs.getBoolean("displayNewsOnMainScreen", default_displayNewsOnMainScreen); | ||||
| @@ -546,6 +549,9 @@ public class Settings implements SharedPreferences | ||||
| 				editor.putBoolean("executeRulesAndProfilesWithSingleClick", executeRulesAndProfilesWithSingleClick); | ||||
| 				editor.putBoolean("automaticUpdateCheck", automaticUpdateCheck); | ||||
| 				editor.putBoolean("displayNewsOnMainScreen", displayNewsOnMainScreen); | ||||
|  | ||||
| 				if(Settings.musicCheckFrequency == 0) | ||||
| 					Settings.musicCheckFrequency = Settings.default_musicCheckFrequency; | ||||
| 				editor.putString("musicCheckFrequency", String.valueOf(musicCheckFrequency)); | ||||
|  | ||||
| 				editor.putBoolean("lockSoundChanges", lockSoundChanges); | ||||
|   | ||||
| @@ -162,7 +162,7 @@ public class LocationProvider | ||||
| 								( | ||||
| 										(locationList.get(i).getProvider().equals(LocationManager.GPS_PROVIDER) && locationList.get(i).getAccuracy() > Settings.satisfactoryAccuracyGps) | ||||
| 												|| | ||||
| 												(locationList.get(i).getProvider().equals(LocationManager.NETWORK_PROVIDER) && locationList.get(i).getAccuracy() > Settings.satisfactoryAccuracyNetwork) | ||||
| 										(locationList.get(i).getProvider().equals(LocationManager.NETWORK_PROVIDER) && locationList.get(i).getAccuracy() > Settings.satisfactoryAccuracyNetwork) | ||||
| 								) | ||||
| 								{ | ||||
| 									Miscellaneous.logEvent("i", "Speed", "Not using 2 most recent locations for speed calculation because at least one does not have a satisfactory accuracy: " + locationList.get(i).toString(), 4); | ||||
| @@ -232,12 +232,6 @@ public class LocationProvider | ||||
|  | ||||
| 	public void startLocationService() | ||||
| 	{ | ||||
| //		if(Settings.useAccelerometerForPositioning && !Miscellaneous.isAndroidEmulator()) | ||||
| //		{ | ||||
| //			accelerometerHandler = new AccelerometerHandler(); | ||||
| //			mySensorActivity = new SensorActivity(this); | ||||
| //		} | ||||
|  | ||||
| 		// startPhoneStateListener | ||||
| 			PhoneStatusListener.startPhoneStatusListener(parentService);			// also used to mute anouncements during calls | ||||
|  | ||||
| @@ -248,8 +242,6 @@ public class LocationProvider | ||||
| 		{ | ||||
| 			if(Rule.isAnyRuleUsing(Trigger_Enum.pointOfInterest) | Rule.isAnyRuleUsing(Trigger_Enum.speed)) | ||||
| 			{ | ||||
| //				TelephonyManager telephonyManager = (TelephonyManager) AutomationService.getInstance().getSystemService(Context.TELEPHONY_SERVICE); | ||||
|  | ||||
| 				// startCellLocationChangedReceiver | ||||
| 				if (CellLocationChangedReceiver.isCellLocationChangedReceiverPossible()) | ||||
| 				{ | ||||
| @@ -514,7 +506,6 @@ public class LocationProvider | ||||
| 			Message msg = new Message(); | ||||
| 			msg.what = 1; | ||||
| 			speedHandler.sendMessageAtTime(msg, timeOfForcedLocationCheck.getTimeInMillis()); | ||||
| //			speedHandler.sendMessageDelayed(msg, delayTime); | ||||
| 			speedTimerActive = true; | ||||
| 		} | ||||
| 		else | ||||
| @@ -531,7 +522,7 @@ public class LocationProvider | ||||
| 			if(msg.what == 1) | ||||
| 			{ | ||||
| 				// time is up, no cell location updates since x minutes, start accelerometer | ||||
| 				String text = "Timer triggered. Based on the last location and speed we may be at a POI. Forcing location update in case CellLocationChangedReceiver didn\'t fire."; | ||||
| 				Miscellaneous.logEvent("i", "LocationProvider", "Timer triggered. Based on the last location and speed we may be at a POI. Forcing location update in case CellLocationChangedReceiver didn\'t fire.", 5); | ||||
|  | ||||
| 				Location currentLocation = CellLocationChangedReceiver.getInstance().getLocation("coarse"); | ||||
| 				AutomationService.getInstance().getLocationProvider().setCurrentLocation(currentLocation, false); | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import com.jens.automation2.Settings; | ||||
| import com.jens.automation2.Trigger; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Set; | ||||
| import java.util.Timer; | ||||
| import java.util.TimerTask; | ||||
|  | ||||
|   | ||||
| @@ -793,4 +793,5 @@ | ||||
|     <string name="musicPlayingDetection">Music playing detection</string> | ||||
|     <string name="musicCheckFrequencyTitle">Check frequency [ms]</string> | ||||
|     <string name="musicCheckFrequencySummary">Milliseconds between checks</string> | ||||
|     <string name="locationNotWorkingOn12">Getting the location does not seem to be working on Android 12 devices currently. If it isn\'t working for you, I\'m sorry. I\'ll try to fix this as soon as I know the cause. So if the donut doesn\'t stop spinning, you know why.</string> | ||||
| </resources> | ||||
		Reference in New Issue
	
	Block a user