-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Permission Checks #993
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ | |
*/ | ||
package org.envirocar.obd; | ||
|
||
import android.Manifest; | ||
import android.app.Activity; | ||
import android.bluetooth.BluetoothAdapter; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Message; | ||
|
@@ -74,7 +76,7 @@ public class OBDSimulator extends Activity { | |
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
if(D) Log.e(TAG, "+++ ON CREATE +++"); | ||
if (D) Log.e(TAG, "+++ ON CREATE +++"); | ||
|
||
// Set up the window layout | ||
setContentView(R.layout.main); | ||
|
@@ -93,14 +95,18 @@ public void onCreate(Bundle savedInstanceState) { | |
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
if(D) Log.e(TAG, "++ ON START ++"); | ||
if (D) Log.e(TAG, "++ ON START ++"); | ||
|
||
// If BT is not on, request that it be enabled. | ||
// setupChat() will then be called during onActivityResult | ||
if (!mBluetoothAdapter.isEnabled()) { | ||
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); | ||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) { | ||
|
||
return; | ||
} | ||
startActivityForResult(enableIntent, REQUEST_ENABLE_BT); | ||
// Otherwise, setup the chat session | ||
// Otherwise, setup the chat session | ||
} else { | ||
if (mChatService == null) setupChat(); | ||
} | ||
|
@@ -109,16 +115,16 @@ public void onStart() { | |
@Override | ||
public synchronized void onResume() { | ||
super.onResume(); | ||
if(D) Log.e(TAG, "+ ON RESUME +"); | ||
if (D) Log.e(TAG, "+ ON RESUME +"); | ||
|
||
// Performing this check in onResume() covers the case in which BT was | ||
// not enabled during onStart(), so we were paused to enable it... | ||
// onResume() will be called when ACTION_REQUEST_ENABLE activity returns. | ||
if (mChatService != null) { | ||
// Only if the state is STATE_NONE, do we know that we haven't started already | ||
if (mChatService.getState() == SimulatorService.STATE_NONE) { | ||
// Start the Bluetooth chat services | ||
mChatService.start(); | ||
// Start the Bluetooth chat services | ||
mChatService.start(); | ||
} | ||
} | ||
} | ||
|
@@ -137,7 +143,7 @@ private void setupChat() { | |
mSendButton.setOnClickListener(new OnClickListener() { | ||
public void onClick(View v) { | ||
// Send a message using content of the edit text widget | ||
//TODO disable enable | ||
//TODO disable enable | ||
} | ||
}); | ||
|
||
|
@@ -148,29 +154,42 @@ public void onClick(View v) { | |
@Override | ||
public synchronized void onPause() { | ||
super.onPause(); | ||
if(D) Log.e(TAG, "- ON PAUSE -"); | ||
if (D) Log.e(TAG, "- ON PAUSE -"); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
super.onStop(); | ||
if(D) Log.e(TAG, "-- ON STOP --"); | ||
if (D) Log.e(TAG, "-- ON STOP --"); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
// Stop the Bluetooth chat services | ||
if (mChatService != null) mChatService.stop(); | ||
if(D) Log.e(TAG, "--- ON DESTROY ---"); | ||
if (D) Log.e(TAG, "--- ON DESTROY ---"); | ||
} | ||
|
||
private void ensureDiscoverable() { | ||
if(D) Log.d(TAG, "ensure discoverable"); | ||
if (D) Log.d(TAG, "ensure discoverable"); | ||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) { | ||
// TODO: Consider calling | ||
// Activity#requestPermissions | ||
// here to request the missing permissions, and then overriding | ||
// public void onRequestPermissionsResult(int requestCode, String[] permissions, | ||
// int[] grantResults) | ||
// to handle the case where the user grants the permission. See the documentation | ||
// for Activity#requestPermissions for more details. | ||
return; | ||
Comment on lines
+176
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. The recent implementation requests permissions and closes the app, if permissions are declined. But your implementation just do nothing then. Your IDE even suggests you, what to do: call |
||
} | ||
if (mBluetoothAdapter.getScanMode() != | ||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { | ||
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) { | ||
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); | ||
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); | ||
if (checkSelfPermission(Manifest.permission.BLUETOOTH_ADVERTISE) != PackageManager.PERMISSION_GRANTED) { | ||
return; | ||
} | ||
startActivity(discoverableIntent); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, what else then, if permissions are not granted? Shouldn't they be requested? Just doing nothing, will make the simulator unusable.