refactor(permission-manager): deduplicate kind mapping into CapabilityKind::index/from_index
This commit is contained in:
@@ -16,20 +16,6 @@ impl PermissionManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn kind_index(kind: CapabilityKind) -> usize {
|
||||
match kind {
|
||||
CapabilityKind::Display => 0,
|
||||
CapabilityKind::Input => 1,
|
||||
CapabilityKind::AudioPlayback => 2,
|
||||
CapabilityKind::AudioCapture => 3,
|
||||
CapabilityKind::Camera => 4,
|
||||
CapabilityKind::Storage => 5,
|
||||
CapabilityKind::Network => 6,
|
||||
CapabilityKind::Gps => 7,
|
||||
CapabilityKind::Bluetooth => 8,
|
||||
}
|
||||
}
|
||||
|
||||
fn granted_bits(&self, process: u16) -> u16 {
|
||||
let idx = process as usize;
|
||||
if idx >= MAX_PROCESSES {
|
||||
@@ -56,7 +42,7 @@ impl Server for PermissionManager {
|
||||
if idx >= MAX_PROCESSES {
|
||||
return PermissionResponse::Denied;
|
||||
}
|
||||
self.grants[idx][Self::kind_index(kind)] = true;
|
||||
self.grants[idx][kind.index()] = true;
|
||||
PermissionResponse::Granted
|
||||
}
|
||||
PermissionRequest::RevokeCapability { process, kind } => {
|
||||
@@ -64,7 +50,7 @@ impl Server for PermissionManager {
|
||||
if idx >= MAX_PROCESSES {
|
||||
return PermissionResponse::Denied;
|
||||
}
|
||||
self.grants[idx][Self::kind_index(kind)] = false;
|
||||
self.grants[idx][kind.index()] = false;
|
||||
PermissionResponse::Revoked
|
||||
}
|
||||
PermissionRequest::CheckCapability { process, kind } => {
|
||||
@@ -72,7 +58,7 @@ impl Server for PermissionManager {
|
||||
if idx >= MAX_PROCESSES {
|
||||
return PermissionResponse::HasCapability(false);
|
||||
}
|
||||
PermissionResponse::HasCapability(self.grants[idx][Self::kind_index(kind)])
|
||||
PermissionResponse::HasCapability(self.grants[idx][kind.index()])
|
||||
}
|
||||
PermissionRequest::ListGranted { process } => {
|
||||
PermissionResponse::GrantedList(self.granted_bits(process))
|
||||
|
||||
Reference in New Issue
Block a user