Skip to content

Commit 160b2c3

Browse files
Check permissions and display message on AAuto
Signed-off-by: Keith Conger <keith.conger@blackboxembedded.com>
1 parent 2509229 commit 160b2c3

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

app/src/main/java/com/blackboxembedded/WunderLINQ/AAuto/AAutoScreen.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import android.content.Intent;
3838
import android.content.IntentFilter;
3939
import android.content.SharedPreferences;
40+
import android.content.pm.PackageManager;
4041
import android.graphics.drawable.Drawable;
4142
import android.preference.PreferenceManager;
4243
import android.util.Log;
@@ -85,6 +86,34 @@ public AAutoScreen(CarContext carContext) {
8586
@NonNull
8687
@Override
8788
public Template onGetTemplate() {
89+
Context context = getCarContext();
90+
91+
// Check for critical permissions used by this screen
92+
boolean hasLocation = ContextCompat.checkSelfPermission(
93+
context, android.Manifest.permission.ACCESS_FINE_LOCATION)
94+
== PackageManager.PERMISSION_GRANTED;
95+
96+
boolean hasBluetooth = ContextCompat.checkSelfPermission(
97+
context, android.Manifest.permission.BLUETOOTH_CONNECT)
98+
== PackageManager.PERMISSION_GRANTED;
99+
100+
// If either permission missing, show a friendly placeholder template
101+
if (!hasLocation || !hasBluetooth) {
102+
StringBuilder message = new StringBuilder(MyApplication.getContext().getString(R.string.permission_required_message));
103+
104+
return new androidx.car.app.model.MessageTemplate.Builder(message.toString())
105+
.setTitle(MyApplication.getContext().getString(R.string.permission_required))
106+
.setHeaderAction(Action.APP_ICON)
107+
.addAction(
108+
new Action.Builder()
109+
.setTitle("Retry")
110+
.setOnClickListener(this::invalidate)
111+
.build()
112+
)
113+
.build();
114+
}
115+
116+
// Safe to show real UI now
88117
return tabTemplate;
89118
}
90119

app/src/main/java/com/blackboxembedded/WunderLINQ/Utils/Utils.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.graphics.Canvas;
2222
import android.graphics.drawable.Drawable;
2323
import android.os.Build;
24+
import android.util.Log;
2425

2526
import com.blackboxembedded.WunderLINQ.MemCache;
2627
import com.blackboxembedded.WunderLINQ.MyApplication;
@@ -38,6 +39,8 @@
3839

3940
public class Utils {
4041

42+
private static final String TAG = "Utils";
43+
4144
public static final String LATITUDE_PATTERN="^(\\+|-)?(?:90(?:(?:\\.0{1,8})?)|(?:[0-9]|[1-8][0-9])(?:(?:\\.[0-9]{1,8})?))$";
4245
public static final String LONGITUDE_PATTERN="^(\\+|-)?(?:180(?:(?:\\.0{1,8})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\\.[0-9]{1,8})?))$";
4346

@@ -263,6 +266,12 @@ public static String bearingToCardinal(Integer bearingValue) {
263266
}
264267

265268
public static Bitmap drawableToBitmap(Drawable drawable) {
269+
270+
if (drawable == null) {
271+
Log.e(TAG, "drawableToBitmap: drawable is null!");
272+
return null;
273+
}
274+
266275
// Determine the size of the Drawable
267276
int width = drawable.getIntrinsicWidth();
268277
int height = drawable.getIntrinsicHeight();

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@
494494
<string name="systemvolume_title">System Volume</string>
495495
<!-- SettingsActivity -->
496496
<string name="title_activity_settings">Settings</string>
497+
<!-- AAutoScreen -->
498+
<string name="permission_required">Permissions Required</string>
499+
<string name="permission_required_message">Please ensure all permissions are granted to the mobile device.</string>
497500
<!-- Preference strings -->
498501
<string name="info_title">Personal Information</string>
499502
<string name="pref_homeAddress_name">Home Address</string>

0 commit comments

Comments
 (0)