Skip to content

Commit 1df1d48

Browse files
committed
fix: UAD crash when interacting with work profiles
On recent Android devices, you can't interact with the user of the work profile. Closes #413, #386, #377
1 parent e372c7c commit 1df1d48

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

src/core/sync.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,15 @@ pub fn apply_pkg_state_commands(
224224
},
225225
_ => vec![],
226226
};
227-
request_builder(commands, &package.name, &[*selected_user])
227+
request_builder(commands, &package.name, &[*selected_user]).iter().map(|(_, command)| command.clone()).collect()
228228
}
229229

230230
pub fn action_handler(
231231
selected_user: &User,
232232
package: &CorePackage,
233233
phone: &Phone,
234234
settings: &DeviceSettings,
235-
) -> Vec<String> {
235+
) -> Vec<(Option<usize>, String)> {
236236
// https://github.com/0x192/universal-android-debloater/wiki/ADB-reference
237237
// ALWAYS PUT THE COMMAND THAT CHANGES THE PACKAGE STATE FIRST!
238238
let commands = match package.state {
@@ -275,20 +275,20 @@ pub fn action_handler(
275275
}
276276
}
277277

278-
pub fn request_builder(commands: Vec<&str>, package: &str, users: &[User]) -> Vec<String> {
278+
pub fn request_builder(commands: Vec<&str>, package: &str, users: &[User]) -> Vec<(Option<usize>, String)> {
279279
if !users.is_empty() {
280280
users
281281
.iter()
282282
.flat_map(|u| {
283283
commands
284284
.iter()
285-
.map(|c| format!("{} --user {} {}", c, u.id, package))
285+
.map(|c| (Some(u.index), format!("{} --user {} {}", c, u.id, package)))
286286
})
287287
.collect()
288288
} else {
289289
commands
290290
.iter()
291-
.map(|c| format!("{} {}", c, package))
291+
.map(|c| (None, format!("{} {}", c, package)))
292292
.collect()
293293
}
294294
}

src/gui/views/list.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Selection {
2525

2626
#[derive(Debug, Default, Clone)]
2727
pub struct PackageInfo {
28+
pub i_user: Option<usize>,
2829
pub index: usize,
2930
pub removal: String,
3031
}
@@ -225,8 +226,9 @@ impl List {
225226
&settings.device,
226227
);
227228

228-
for (i, action) in actions.into_iter().enumerate() {
229+
for (i, (i_user, action)) in actions.into_iter().enumerate() {
229230
let p_info = PackageInfo {
231+
i_user,
230232
index: i_package,
231233
removal: package.removal.to_string(),
232234
};
@@ -277,10 +279,12 @@ impl List {
277279
&settings.device,
278280
);
279281

280-
for (j, action) in actions.into_iter().enumerate() {
282+
let package = &mut self.phone_packages[i_user][i];
283+
for (j, (i_user, action)) in actions.into_iter().enumerate() {
281284
let p_info = PackageInfo {
285+
i_user,
282286
index: i,
283-
removal: self.phone_packages[i_user][i].removal.to_string(),
287+
removal: package.removal.to_string(),
284288
};
285289
// Only the first command can change the package state
286290
commands.push(Command::perform(
@@ -312,17 +316,13 @@ impl List {
312316
let package = &mut self.phone_packages[i_user][p.index];
313317
update_selection_count(&mut self.selection, package.state, false);
314318

315-
if !settings.device.multi_user_mode {
319+
if !settings.device.multi_user_mode || p.i_user.is_none() {
316320
package.state = package.state.opposite(settings.device.disable_mode);
317321
package.selected = false;
318322
} else {
319-
for u in &selected_device.user_list {
320-
self.phone_packages[u.index][p.index].state = self.phone_packages
321-
[u.index][p.index]
322-
.state
323-
.opposite(settings.device.disable_mode);
324-
self.phone_packages[u.index][p.index].selected = false;
325-
}
323+
self.phone_packages[p.i_user.unwrap()][p.index].state = self.phone_packages
324+
[p.i_user.unwrap()][p.index].state.opposite(settings.device.disable_mode);
325+
self.phone_packages[p.i_user.unwrap()][p.index].selected = false;
326326
}
327327
self.selection
328328
.selected_packages

src/gui/views/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ impl Settings {
142142
*nb_running_async_adb_commands = 0;
143143
for p in &r_packages {
144144
let p_info = PackageInfo {
145+
i_user: None,
145146
index: p.index,
146147
removal: "RESTORE".to_string(),
147148
};

0 commit comments

Comments
 (0)