Add developer options check for launching Traceur MainActivity
Previously, it was possible for apps to launch the System Tracing
app even when developer options was not enabled.
This change introduces a check at activity start that will close
the activity if developer options are not enabled.
Bug: 142936525
Test: Flashed phone with R master and verified that Traceur could
be launched from the Settings app and via the quick settings tile
long press.
Test: Verified that an app calling startActivity on the Traceur
MainActivity would fail if developer options were disabled.
Change-Id: I8b2da8cf732edf5c44b0a7f85f250752ae7d190f
diff --git a/src/com/android/traceur/MainActivity.java b/src/com/android/traceur/MainActivity.java
index a8c8a2b..be14223 100644
--- a/src/com/android/traceur/MainActivity.java
+++ b/src/com/android/traceur/MainActivity.java
@@ -17,6 +17,7 @@
import android.app.Activity;
import android.os.Bundle;
+import android.provider.Settings;
public class MainActivity extends Activity {
@Override
@@ -24,4 +25,16 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
}
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ boolean developerOptionsIsEnabled =
+ Settings.Global.getInt(getApplicationContext().getContentResolver(),
+ Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
+
+ if (!developerOptionsIsEnabled) {
+ finish();
+ }
+ }
}