Skip to content

Commit

Permalink
!ring command feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementGre committed May 1, 2022
1 parent bf936f6 commit 15cc882
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 116 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 23 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 30
compileSdkVersion 31

defaultConfig {
applicationId "fr.themsou.monitorinternetless"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0.0"
minSdkVersion 26
targetSdkVersion 31
versionCode 2
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand All @@ -21,30 +21,34 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.navigation:navigation-fragment:2.4.2'
implementation 'androidx.navigation:navigation-ui:2.4.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.preference:preference:1.2.0'
implementation 'com.google.android.material:material:1.5.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation 'com.github.clans:fab:1.6.4'

def room_version = "2.2.5"
def core_version = "1.6.0"
implementation "androidx.core:core:$core_version"


def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor

Expand All @@ -56,7 +60,7 @@ dependencies {
testImplementation "androidx.room:room-testing:$room_version"


def work_version = '2.4.0'
def work_version = '2.7.1'
// (Java only)
implementation "androidx.work:work-runtime:$work_version"
// Kotlin + coroutines
Expand All @@ -75,5 +79,5 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1'

// GAPPS
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation 'com.google.android.gms:play-services-location:19.0.1'
}
Binary file removed app/release/app-release.apk
Binary file not shown.
10 changes: 6 additions & 4 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
Expand All @@ -10,9 +10,11 @@
{
"type": "SINGLE",
"filters": [],
"versionCode": 1,
"versionName": "1.0.0",
"attributes": [],
"versionCode": 2,
"versionName": "1.0.1",
"outputFile": "app-release.apk"
}
]
],
"elementType": "File"
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <!-- !eco -->
<!-- !mobile -->
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- !gps -->
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <!-- !wifi -->
Expand All @@ -38,12 +37,14 @@
<activity
android:name=".ui.about.AboutActivity"
android:label="@string/title_activity_about"
android:exported="false"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<!-- GUI -->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:exported="true"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
73 changes: 33 additions & 40 deletions app/src/main/java/fr/themsou/monitorinternetless/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package fr.themsou.monitorinternetless;

import android.Manifest;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.MenuItem;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.util.Consumer;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.google.android.material.bottomnavigation.BottomNavigationView;

import fr.themsou.monitorinternetless.commander.RingCommandExecutor;
import fr.themsou.monitorinternetless.ui.about.AboutActivity;

public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
Expand Down Expand Up @@ -64,6 +68,15 @@ protected void onCreate(Bundle savedInstanceState) {
}
});

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.cancel(1);
if(RingCommandExecutor.mediaPlayer != null && RingCommandExecutor.mediaPlayer.isPlaying()){
RingCommandExecutor.mediaPlayer.stop();
final AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, RingCommandExecutor.oldVolume, 0);
}

initNotificationsChannels();
checkBasePermissions(this);
//checkAdvancedPermissions(this);

Expand All @@ -84,7 +97,7 @@ public void checkBasePermissions(final MainActivity activity){
.setMessage(getString(R.string.restart_dialog))
.setPositiveButton(getString(R.string.message_ok), new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int which) {
doRestart(activity);
doRestart();
}
}).show();
}else{
Expand Down Expand Up @@ -163,41 +176,21 @@ public void onStop() {
active = false;
}

public static void doRestart(Context c) {
try {
//check if the context is given
if (c != null) {
//fetch the packagemanager so we can get the default launch activity
// (you can replace this intent with any other activity if you want
PackageManager pm = c.getPackageManager();
//check if we got the PackageManager
if (pm != null) {
//create the intent with the default start activity for your application
Intent mStartActivity = pm.getLaunchIntentForPackage(
c.getPackageName()
);
if (mStartActivity != null) {
mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//create a pending intent so the application is restarted after System.exit(0) was called.
// We use an AlarmManager to call this intent in 100ms
int mPendingIntentId = 223344;
PendingIntent mPendingIntent = PendingIntent.getActivity(c, mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager mgr = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 200, mPendingIntent);
//kill the application
System.exit(0);
} else {
Log.e(TAG, "Was not able to restart application, mStartActivity null");
}
} else {
Log.e(TAG, "Was not able to restart application, PM null");
}
} else {
Log.e(TAG, "Was not able to restart application, Context null");
}
} catch (Exception ex) {
Log.e(TAG, "Was not able to restart application");
}
public void doRestart(){
finish();
startActivity(getIntent());
// Animation
overridePendingTransition(0, 0);
}

private void initNotificationsChannels(){
CharSequence name = "Sonnerie";
String description = "Notification pour alerter de la sonnerie du téléphone avec la commande !ring";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("ring", name, importance);
channel.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
import android.telephony.SmsManager;
import android.util.Log;

import androidx.core.util.Predicate;

import java.util.ArrayList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.regex.Pattern;

import fr.themsou.monitorinternetless.R;
Expand Down Expand Up @@ -47,6 +43,8 @@ public String executeAuto() {
new InfoCommandExecutor(context, this).execute(args);
case "!locate":
new LocateCommandExecutor(context, this).execute(args);
case "!ring":
new RingCommandExecutor(context, this).execute(args);
}

}else replyAndTerminate(context.getString(R.string.command_error_no_permission));
Expand All @@ -71,16 +69,4 @@ public void terminate(String message){
terminatedMessage = message;
}


private boolean parse(String arg){
switch(arg.toLowerCase()){
case "on":
case "yes":
case "true":
case "enable":
return true;
default:
return false;
}
}
}
Loading

0 comments on commit 15cc882

Please sign in to comment.