Skip to content

Commit 9d8961f

Browse files
authored
Merge pull request #173 from TeamOpenSmartGlasses/fix-errors
Fix errors
2 parents cc1b31b + 018ceea commit 9d8961f

File tree

3 files changed

+116
-91
lines changed

3 files changed

+116
-91
lines changed

augmentos_core/app/src/main/java/com/teamopensmartglasses/convoscope/AugmentosService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,10 +538,15 @@ public void completeInitialization(){
538538
// TODO: Uncomment for auto-connect
539539
String preferredWearable = AugmentosSmartGlassesService.getPreferredWearable(this);
540540
if(!preferredWearable.isEmpty()) {
541-
executeOnceSmartGlassesServiceReady(this, () -> {
542-
SmartGlassesDevice preferredDevice = AugmentosSmartGlassesService.getSmartGlassesDeviceFromModelName(preferredWearable);
543-
smartGlassesService.connectToSmartGlasses(preferredDevice);
544-
});
541+
SmartGlassesDevice preferredDevice = AugmentosSmartGlassesService.getSmartGlassesDeviceFromModelName(preferredWearable);
542+
if (preferredDevice != null) {
543+
executeOnceSmartGlassesServiceReady(this, () -> {
544+
smartGlassesService.connectToSmartGlasses(preferredDevice);
545+
});
546+
} else {
547+
// We have some invalid device saved... delete from preferences
548+
AugmentosSmartGlassesService.savePreferredWearable(this, "");
549+
}
545550
}
546551
}
547552

@@ -2555,7 +2560,7 @@ public JSONObject generateStatusJson() {
25552560
connectedGlasses.put("battery_life", (batteryLevel == null) ? -1: batteryLevel); //-1 if unknown
25562561
String brightnessString;
25572562
if (brightnessLevel == null) {
2558-
brightnessString = "?";
2563+
brightnessString = "-";
25592564
} else if (brightnessLevel == -1){
25602565
brightnessString = "AUTO";
25612566
} else {

augmentos_core/app/src/main/java/com/teamopensmartglasses/convoscope/PermissionsActivity.java

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
6868

6969
// Check if permissions are already granted
7070
if (areAllPermissionsGranted(false)) {
71-
onPermissionsGranted();
71+
promptForBatteryOptimizationPermission();
7272
} else {
7373
// Request permissions
7474
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, PERMISSION_REQUEST_CODE);
@@ -103,7 +103,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
103103
new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
104104
BACKGROUND_LOCATION_PERMISSION_CODE);
105105
} else {
106-
onPermissionsGranted();
106+
promptForBatteryOptimizationPermission();
107107
}
108108
} else {
109109
showPermissionDenialAlert();
@@ -112,7 +112,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
112112
// Check if background location permission is granted
113113
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
114114
== PackageManager.PERMISSION_GRANTED) {
115-
onPermissionsGranted();
115+
promptForBatteryOptimizationPermission();
116116
} else {
117117
// ... handle background location denial ...
118118
showPermissionDenialAlert();
@@ -133,11 +133,11 @@ public void onClick(DialogInterface dialog, int which) {
133133
}
134134
});
135135
AlertDialog alert = builder.create();
136-
alert.setOnDismissListener(dialogInterface -> finish());
136+
alert.setOnDismissListener(dialogInterface -> promptForBatteryOptimizationPermission());
137137
alert.show();
138138
}
139139

140-
private void onPermissionsGranted() {
140+
private void promptForBatteryOptimizationPermission() {
141141
// Call the helper method for battery optimization handling
142142
if (isSystemApp(this)) {
143143
handleBatteryOptimization(this);
@@ -158,25 +158,27 @@ private void onPermissionsGranted() {
158158
}
159159

160160
private void showBatteryOptimizationSettings() {
161-
AlertDialog.Builder builder = new AlertDialog.Builder(this);
162-
builder.setTitle("Disable Battery Optimization")
163-
.setMessage("This application needs to remain active in the background to function properly. " +
164-
"Please disable battery optimization for better performance and reliability.")
165-
.setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
166-
@Override
167-
public void onClick(DialogInterface dialog, int which) {
168-
userWentToSettings = true;
169-
Intent intent = new Intent();
170-
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
171-
startActivity(intent);
172-
}
173-
})
174-
.setNegativeButton("Back", (dialog, which) -> {
175-
redirectAndFinish();
176-
});
177-
;
178-
AlertDialog alert = builder.create();
179-
alert.show();
161+
if (!isFinishing()) {
162+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
163+
builder.setTitle("Disable Battery Optimization")
164+
.setMessage("This application needs to remain active in the background to function properly. " +
165+
"Please disable battery optimization for better performance and reliability.")
166+
.setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
167+
@Override
168+
public void onClick(DialogInterface dialog, int which) {
169+
userWentToSettings = true;
170+
Intent intent = new Intent();
171+
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
172+
startActivity(intent);
173+
}
174+
})
175+
.setNegativeButton("Back", (dialog, which) -> {
176+
redirectAndFinish();
177+
});
178+
;
179+
AlertDialog alert = builder.create();
180+
alert.show();
181+
}
180182
}
181183

182184
@Override
@@ -190,7 +192,18 @@ protected void onResume() {
190192
}
191193

192194
public void redirectAndFinish(){
193-
TpaHelpers.redirectToAugmentOsManagerIfAvailable(this);
194-
finish();
195+
boolean redirected = TpaHelpers.redirectToAugmentOsManagerIfAvailable(this);
196+
if (!redirected) {
197+
AlertDialog.Builder builder = new AlertDialog.Builder(this);
198+
builder.setTitle("Installation Required")
199+
.setMessage("To use AugmentOS, you'll need to install the \"AugmentOS Manager\" app")
200+
.setPositiveButton("OK", (dialog, which) -> {
201+
dialog.dismiss();
202+
finish();
203+
});
204+
builder.show();
205+
} else {
206+
finish();
207+
}
195208
}
196209
}

augmentos_manager/src/components/ConnectedDeviceInfo.tsx

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -55,42 +55,49 @@ const ConnectedDeviceInfo: React.FC<ConnectedDeviceInfoProps> = ({ isDarkTheme }
5555
}
5656

5757
// Request permissions on Android
58-
if (Platform.OS === 'android' && Platform.Version >= 23) {
59-
PermissionsAndroid.requestMultiple([
60-
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
61-
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
62-
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
63-
]).then(async (result) => {
64-
console.log('Permissions granted:', result);
58+
if (Platform.OS === 'android' && Platform.Version >= 23) {
59+
PermissionsAndroid.requestMultiple([
60+
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
61+
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
62+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
63+
]).then(async (result) => {
64+
console.log('Permissions granted:', result);
6565

66-
const allGranted = Object.values(result).every(
67-
(value) => value === PermissionsAndroid.RESULTS.GRANTED
68-
);
66+
const allGranted = Object.values(result).every(
67+
(value) => value === PermissionsAndroid.RESULTS.GRANTED
68+
);
6969

70-
if (allGranted) {
71-
try {
72-
await checkAndRequestNotificationAccessSpecialPermission();
73-
} catch (error) {
74-
console.warn('Notification permission request error:', error);
75-
}
76-
} else {
77-
console.warn('Some permissions were denied:', result);
78-
// Optionally handle partial denial here
79-
}
80-
})
81-
.catch((error) => {
82-
console.error('Error requesting permissions:', error);
83-
});
84-
}
70+
if (allGranted) {
71+
try {
72+
await checkAndRequestNotificationAccessSpecialPermission();
73+
} catch (error) {
74+
console.warn('Notification permission request error:', error);
75+
}
76+
} else {
77+
console.warn('Some permissions were denied:', result);
78+
// Optionally handle partial denial here
79+
Alert.alert(
80+
'Permissions Required',
81+
'Some permissions were denied. Please go to Settings and enable all required permissions for the app to function properly.',
82+
[
83+
{ text: 'OK', style: 'default' }
84+
]
85+
);
86+
}
87+
})
88+
.catch((error) => {
89+
console.error('Error requesting permissions:', error);
90+
});
91+
}
8592

86-
// Cleanup function
87-
return () => {
88-
fadeAnim.stopAnimation();
89-
scaleAnim.stopAnimation();
90-
slideAnim.stopAnimation();
91-
};
92-
}, [status.puck_connected, fadeAnim, scaleAnim, slideAnim])
93-
);
93+
// Cleanup function
94+
return () => {
95+
fadeAnim.stopAnimation();
96+
scaleAnim.stopAnimation();
97+
slideAnim.stopAnimation();
98+
};
99+
}, [status.puck_connected, fadeAnim, scaleAnim, slideAnim])
100+
);
94101

95102
const handleConnectToPuck = async () => {
96103
try {
@@ -173,31 +180,31 @@ const ConnectedDeviceInfo: React.FC<ConnectedDeviceInfoProps> = ({ isDarkTheme }
173180
<>
174181
<Animated.View style={[styles.statusBar, { opacity: fadeAnim }]}>
175182
<View style={styles.statusInfo}>
176-
{status.glasses_info?.battery_life &&
183+
{status.glasses_info?.battery_life != null && status.glasses_info?.battery_life >= 0 &&
177184
<>
178185
<Text style={[styles.statusLabel, { color: themeStyles.statusLabelColor }]}>Battery</Text>
179186
<View style={styles.batteryContainer}>
180187
<Icon name={batteryIcon} size={16} color={batteryColor} style={styles.batteryIcon} />
181188
<Text style={[styles.batteryValue, { color: batteryColor }]}>
182-
{status.glasses_info.battery_life == -1
183-
? "?"
184-
: `${status.glasses_info.battery_life}%`}
189+
{status.glasses_info.battery_life == -1
190+
? "-"
191+
: `${status.glasses_info.battery_life}%`}
185192
</Text>
186193
</View>
187194
</>
188195
}
189196
</View>
190197

191198
<View style={styles.statusInfo}>
192-
{status.glasses_info?.brightness &&
193-
<>
194-
<Text style={[styles.statusLabel, { color: themeStyles.statusLabelColor }]}>Brightness</Text>
195-
<Text style={[styles.statusValue, { color: themeStyles.statusValueColor }]}>
196-
{status.glasses_info
197-
? `${status.glasses_info.brightness}`
198-
: "?"}
199-
</Text>
200-
</>
199+
{status.glasses_info?.brightness != null &&
200+
<>
201+
<Text style={[styles.statusLabel, { color: themeStyles.statusLabelColor }]}>Brightness</Text>
202+
<Text style={[styles.statusValue, { color: themeStyles.statusValueColor }]}>
203+
{status.glasses_info
204+
? `${status.glasses_info.brightness}`
205+
: "-"}
206+
</Text>
207+
</>
201208
}
202209
</View>
203210
<TouchableOpacity
@@ -210,19 +217,19 @@ const ConnectedDeviceInfo: React.FC<ConnectedDeviceInfoProps> = ({ isDarkTheme }
210217
</Animated.View>
211218
</>
212219
) : (
213-
<View style={styles.statusInfoNotConnected}>
214-
{status.glasses_info?.is_searching ? (
215-
<View style={styles.disconnectedContent}>
216-
<ActivityIndicator size="small" color="#2196F3" />
217-
</View>
218-
) : (
219-
<View style={styles.noGlassesContent}>
220-
<TouchableOpacity style={styles.connectButton} onPress={connectGlasses}>
221-
<Text style={styles.buttonText}>Connect</Text>
222-
</TouchableOpacity>
223-
</View>
224-
)}
225-
</View>
220+
<View style={styles.statusInfoNotConnected}>
221+
{status.glasses_info?.is_searching ? (
222+
<View style={styles.disconnectedContent}>
223+
<ActivityIndicator size="small" color="#2196F3" />
224+
</View>
225+
) : (
226+
<View style={styles.noGlassesContent}>
227+
<TouchableOpacity style={styles.connectButton} onPress={connectGlasses}>
228+
<Text style={styles.buttonText}>Connect</Text>
229+
</TouchableOpacity>
230+
</View>
231+
)}
232+
</View>
226233
)}
227234
</View>
228235
) : (
@@ -307,7 +314,7 @@ const styles = StyleSheet.create({
307314
statusInfoNotConnected: {
308315
alignItems: 'center',
309316
flex: 1,
310-
width:'100%'
317+
width: '100%'
311318
},
312319
statusInfo: {
313320
alignItems: 'center',

0 commit comments

Comments
 (0)