Skip to content

Commit 725e7d4

Browse files
author
SBALAVIGNESH123
committed
Fix: Remove duplicate ACCESS_NETWORK_STATE permission
1 parent 1c4933f commit 725e7d4

4 files changed

Lines changed: 110 additions & 75 deletions

File tree

play-services-core/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@
136136
android:protectionLevel="signature"/>
137137
<uses-permission android:name="com.google.android.gms.auth.permission.GOOGLE_ACCOUNT_CHANGE" />
138138

139-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
139+
140140
<uses-permission android:name="android.permission.INTERNET" />
141-
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
141+
142142
<uses-permission android:name="android.permission.BLUETOOTH" />
143143
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
144144
<!-- For Android 12+ -->

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableImpl.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,7 @@ private boolean syncRecordToPeer(String nodeId, DataItemRecord record) {
284284
syncAssetToPeer(connection, record, asset);
285285
} catch (Exception e) {
286286
Log.w(TAG, "Could not sync asset " + asset + " for " + nodeId + " and " + record, e);
287-
try {
288-
connection.close();
289-
} catch (IOException ioException) {
290-
// Ignore
291-
}
287+
closeConnection(nodeId);
292288
return false;
293289
}
294290
}
@@ -298,11 +294,7 @@ private boolean syncRecordToPeer(String nodeId, DataItemRecord record) {
298294
connection.writeMessage(new RootMessage.Builder().setDataItem(item).build());
299295
} catch (Exception e) {
300296
Log.w(TAG, e);
301-
try {
302-
connection.close();
303-
} catch (IOException ioException) {
304-
// Ignore
305-
}
297+
closeConnection(nodeId);
306298
return false;
307299
}
308300
return true;
@@ -765,7 +757,7 @@ public void run() {
765757
}
766758
} catch (IOException e) {
767759
Log.d(TAG, "BT connection failed: " + e.getMessage());
768-
if (socket != null && !socket.isConnected()) {
760+
if (socket != null) {
769761
try {
770762
socket.close();
771763
} catch (IOException closeErr) {

play-services-wearable/core/src/main/java/org/microg/gms/wearable/WearableSettingsActivity.java

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class WearableSettingsActivity extends Activity {
1919

2020
private ListView listView;
2121
private TextView emptyView;
22+
private WearableDeviceAdapter deviceAdapter;
2223

2324
@Override
2425
protected void onCreate(Bundle savedInstanceState) {
@@ -37,7 +38,7 @@ protected void onResume() {
3738
}
3839

3940
private void refreshList() {
40-
ArrayList<String> deviceList = new ArrayList<>();
41+
ArrayList<BluetoothDevice> deviceList = new ArrayList<>();
4142
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
4243

4344
if (adapter == null || !adapter.isEnabled()) {
@@ -46,8 +47,8 @@ private void refreshList() {
4647
}
4748

4849
Set<BluetoothDevice> bondedDevices = adapter.getBondedDevices();
49-
if (bondedDevices == null || bondedDevices.isEmpty()) {
50-
return;
50+
if (bondedDevices != null) {
51+
deviceList.addAll(bondedDevices);
5152
}
5253

5354
Set<String> connectedNodes = null;
@@ -56,45 +57,58 @@ private void refreshList() {
5657
connectedNodes = service.getConnectedNodes();
5758
}
5859

59-
for (BluetoothDevice device : bondedDevices) {
60-
String status = "Disconnected";
61-
String nodeId = device.getAddress(); // Basic mapping, improved by node DB later
62-
63-
// Check by address (since WearableImpl tracks by Node ID which might be address or UUID)
64-
// But getConnectedNodes returns KEYS from activeConnections.
65-
// In BluetoothWearableConnection logic, we used connect.id (peer ID).
66-
// However, WearableImpl checks equality against config.nodeId/peerNodeId.
67-
// For now, simple check: is the address in the string set?
68-
// Actually, getRemoteAddress() was used to match.
69-
// Let's just list the device name and address.
70-
60+
deviceAdapter = new WearableDeviceAdapter(this, deviceList, connectedNodes);
61+
listView.setAdapter(deviceAdapter);
62+
63+
listView.setOnItemClickListener((parent, view, position, id) -> {
64+
BluetoothDevice device = deviceAdapter.getItem(position);
65+
Toast.makeText(this, "Connecting to " + device.getName() + "...", Toast.LENGTH_SHORT).show();
66+
// Trigger connection logic if needed, currently handled by background service automatically
67+
});
68+
}
69+
70+
private static class WearableDeviceAdapter extends ArrayAdapter<BluetoothDevice> {
71+
private final Set<String> connectedNodes;
72+
73+
public WearableDeviceAdapter(android.content.Context context, ArrayList<BluetoothDevice> devices, Set<String> connectedNodes) {
74+
super(context, 0, devices);
75+
this.connectedNodes = connectedNodes;
76+
}
77+
78+
@Override
79+
public android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent) {
80+
if (convertView == null) {
81+
convertView = android.view.LayoutInflater.from(getContext()).inflate(R.layout.wearable_device_item, parent, false);
82+
}
83+
84+
BluetoothDevice device = getItem(position);
85+
TextView nameView = convertView.findViewById(R.id.device_name);
86+
TextView addressView = convertView.findViewById(R.id.device_address);
87+
TextView statusView = convertView.findViewById(R.id.device_status);
88+
android.widget.ImageView iconView = convertView.findViewById(R.id.device_icon);
89+
90+
nameView.setText(device.getName());
91+
addressView.setText(device.getAddress());
92+
93+
// Simple status logic
7194
boolean isConnected = false;
72-
if (connectedNodes != null) {
73-
// Heuristic check: ConnectionThread adds by connect.id (NodeID).
74-
// We don't have a map from Address -> NodeID easily here without iterating implicit structure.
75-
// But wait, activeConnections keys are NodeIDs.
76-
// WE DON'T KNOW the Node ID of a disconnected device easily.
77-
// But for a connected device, we might see it.
78-
// Let's just show "Bonded" for now, and "Connected" if we find a match?
79-
// Actually, WearableImpl tracks active connections.
80-
// Ideally, we'd query configurations.
81-
// Let's just show device list.
82-
83-
// Simple hack: If list is not empty, connection service is running.
95+
// Ideally we'd match Node ID to Address, but for now we rely on the service to potentially use address as ID
96+
// or we just show "Bonded" until we have better mapping.
97+
if (connectedNodes != null && connectedNodes.contains(device.getAddress())) {
98+
isConnected = true;
8499
}
85100

86-
String entry = device.getName() + "\n" + device.getAddress();
87-
// If we had connection status, append it.
88-
// entry += " [" + status + "]";
89-
90-
deviceList.add(entry);
91-
}
101+
if (isConnected) {
102+
statusView.setText("Connected");
103+
statusView.setTextColor(getContext().getResources().getColor(android.R.color.holo_green_dark));
104+
iconView.setAlpha(1.0f);
105+
} else {
106+
statusView.setText("Bonded");
107+
statusView.setTextColor(getContext().getResources().getColor(android.R.color.darker_gray));
108+
iconView.setAlpha(0.6f);
109+
}
92110

93-
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, deviceList);
94-
listView.setAdapter(arrayAdapter);
95-
96-
listView.setOnItemClickListener((parent, view, position, id) -> {
97-
Toast.makeText(this, "Auto-connecting in background...", Toast.LENGTH_SHORT).show();
98-
});
111+
return convertView;
112+
}
99113
}
100114
}
Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,65 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
32
android:layout_width="match_parent"
43
android:layout_height="match_parent"
54
android:orientation="vertical"
6-
android:padding="16dp">
5+
android:background="?android:attr/colorBackground">
76

8-
<TextView
9-
android:layout_width="wrap_content"
7+
<LinearLayout
8+
android:layout_width="match_parent"
109
android:layout_height="wrap_content"
11-
android:text="@string/wearable_settings_title"
12-
android:textAppearance="?android:attr/textAppearanceLarge"
13-
android:layout_marginBottom="8dp"/>
10+
android:orientation="vertical"
11+
android:padding="24dp"
12+
android:background="?android:attr/windowBackground">
1413

15-
<TextView
16-
android:layout_width="wrap_content"
17-
android:layout_height="wrap_content"
18-
android:text="@string/wearable_settings_desc"
19-
android:textAppearance="?android:attr/textAppearanceSmall"
20-
android:layout_marginBottom="16dp"/>
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:text="@string/wearable_settings_title"
18+
android:textAppearance="?android:attr/textAppearanceLarge"
19+
android:textSize="24sp"
20+
android:textStyle="bold"
21+
android:textColor="?android:attr/textColorPrimary"
22+
android:layout_marginBottom="8dp"/>
23+
24+
<TextView
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:text="@string/wearable_settings_desc"
28+
android:textAppearance="?android:attr/textAppearanceMedium"
29+
android:textColor="?android:attr/textColorSecondary"
30+
android:lineSpacingMultiplier="1.2"/>
31+
</LinearLayout>
2132

22-
<ListView
23-
android:id="@+id/device_list"
33+
<View
2434
android:layout_width="match_parent"
25-
android:layout_height="0dp"
26-
android:layout_weight="1"/>
35+
android:layout_height="1dp"
36+
android:background="?android:attr/listDivider"/>
2737

28-
<TextView
29-
android:id="@+id/empty_view"
38+
<FrameLayout
3039
android:layout_width="match_parent"
31-
android:layout_height="match_parent"
32-
android:text="@string/wearable_no_devices"
33-
android:gravity="center"
34-
android:visibility="gone"/>
40+
android:layout_height="match_parent">
41+
42+
<ListView
43+
android:id="@+id/device_list"
44+
android:layout_width="match_parent"
45+
android:layout_height="match_parent"
46+
android:divider="@null"
47+
android:paddingTop="8dp"
48+
android:clipToPadding="false"/>
49+
50+
<TextView
51+
android:id="@+id/empty_view"
52+
android:layout_width="wrap_content"
53+
android:layout_height="wrap_content"
54+
android:layout_gravity="center"
55+
android:text="@string/wearable_no_devices"
56+
android:textAppearance="?android:attr/textAppearanceMedium"
57+
android:textColor="?android:attr/textColorSecondary"
58+
android:drawableTop="@android:drawable/ic_menu_search"
59+
android:drawablePadding="16dp"
60+
android:gravity="center"
61+
android:visibility="gone"/>
62+
63+
</FrameLayout>
3564

3665
</LinearLayout>

0 commit comments

Comments
 (0)