Skip to content

Commit

Permalink
ready for release (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
yerseg authored Mar 7, 2021
1 parent 77298d7 commit 46eee02
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 39 deletions.
Binary file modified profiling_app/release/profiling_app-release.apk
Binary file not shown.
24 changes: 4 additions & 20 deletions profiling_app/src/main/java/com/yerseg/profiler/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.yerseg.profiler;

import android.Manifest;
import android.app.AppOpsManager;
import android.annotation.SuppressLint;
import android.app.NotificationManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
Expand All @@ -16,15 +16,14 @@
import android.os.Process;
import android.provider.Settings;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toolbar;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.fragment.app.FragmentActivity;
Expand All @@ -43,7 +42,6 @@ public class MainActivity extends FragmentActivity {
public static final String ACTION_LOCATION_SCANNING_SETTINGS = "android.settings.LOCATION_SCANNING_SETTINGS";

private final static String LOCATION_SOURCE_SETTINGS_SHOWN = "com.yerseg.profiler.LOCATION_SOURCE_SETTINGS_SHOWN";
private final static String IGNORE_BATTERY_OPTIMIZATION_SETTINGS_SHOWN = "com.yerseg.profiler.IGNORE_BATTERY_OPTIMIZATION_SETTINGS_SHOWN";
private final static String APPLICATION_DETAILS_SETTINGS_SHOWN = "com.yerseg.profiler.APPLICATION_DETAILS_SETTINGS_SHOWN";
private final static String LOCATION_SCANNING_SETTINGS_SHOWN = "com.yerseg.profiler.LOCATION_SCANNING_SETTINGS_SHOWN";
private final static String REQUEST_IGNORE_BATTERY_OPTIMIZATIONS_SHOWN = "com.yerseg.profiler.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS_SHOWN";
Expand Down Expand Up @@ -79,6 +77,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

if (shouldShowSettingsActivity(REQUEST_IGNORE_BATTERY_OPTIMIZATIONS_SHOWN)) {
@SuppressLint("BatteryLife")
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
showLongToast("Allow the app to ignore battery optimizations please!");
Expand Down Expand Up @@ -191,20 +190,6 @@ private boolean isProfilingServiceRunning() {
return isRunning;
}

private boolean isUsageStatsPermissionsGranted() {
boolean granted = false;
AppOpsManager appOps = (AppOpsManager) getSystemService(APP_OPS_SERVICE);
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), getPackageName());

if (mode == AppOpsManager.MODE_DEFAULT) {
granted = (checkCallingOrSelfPermission(android.Manifest.permission.PACKAGE_USAGE_STATS) == PackageManager.PERMISSION_GRANTED);
} else {
granted = (mode == AppOpsManager.MODE_ALLOWED);
}

return granted;
}

void requestPermissions() {
requestPermissions(new String[]{
Manifest.permission.ACCESS_COARSE_LOCATION,
Expand All @@ -214,13 +199,12 @@ void requestPermissions() {
Manifest.permission.BLUETOOTH_ADMIN,
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.FOREGROUND_SERVICE,
Manifest.permission.PACKAGE_USAGE_STATS,
Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
}, PERMISSIONS_REQUEST_ID);
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
mIsPermissionsGranted = requestCode == PERMISSIONS_REQUEST_ID && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.os.Process;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -192,7 +193,7 @@ private void startLocationTracking() {
if (permission == PackageManager.PERMISSION_GRANTED) {
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult result) {
public void onLocationResult(@NonNull LocationResult result) {
Log.d("Profiler [LocationStat]", String.format(Locale.getDefault(), "\t%d\tonLocationResult()", Process.myTid()));

try {
Expand Down Expand Up @@ -288,9 +289,9 @@ public void run() {
Utils.FileWriter.writeFile(Utils.getProfilingFilesDir(getApplicationContext()), ProfilingService.WIFI_STATS_FILE_NAME, connectionInfo);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
mWifiProfilingThreadHandler.postDelayed(this, WIFI_STATS_UPDATE_FREQ);
}

mWifiProfilingThreadHandler.postDelayed(this, WIFI_STATS_UPDATE_FREQ);
}
});
}
Expand All @@ -301,7 +302,6 @@ public void onReceive(Context context, Intent intent) {
new Thread(() -> {
try {
BluetoothDevice device = null;

try {
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
} catch (Exception ex) {
Expand Down Expand Up @@ -361,6 +361,8 @@ public void onScanResult(int callbackType, android.bluetooth.le.ScanResult resul
if (isKilled)
return;

super.onScanResult(callbackType, result);

String resultStr = String.format(Locale.getDefault(), "%s;LE;%d;%d;%d;%d;%b;%b\n",
Utils.GetTimeStamp(System.currentTimeMillis()),
result.getAdvertisingSid(),
Expand Down Expand Up @@ -390,10 +392,10 @@ public void run() {
btScanner.startScan(mBtLeScanCallback);
}

mBluetoothProfilingThreadHandler.postDelayed(this, BLUETOOTH_STATS_UPDATE_FREQ);

} catch (Exception ex) {
ex.printStackTrace();
} finally {
mBluetoothProfilingThreadHandler.postDelayed(this, BLUETOOTH_STATS_UPDATE_FREQ);
}
}
});
Expand Down
1 change: 0 additions & 1 deletion profiling_app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
Expand Down
9 changes: 0 additions & 9 deletions profiling_app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,4 @@
<item name="colorAccent">@color/safe_green</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
3 changes: 0 additions & 3 deletions profiling_app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@
<item name="windowNoTitle">true</item>
</style>

<style name="Theme.Profiler.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="Theme.Profiler.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>

0 comments on commit 46eee02

Please sign in to comment.