Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
c7e30ac6
Commit
c7e30ac6
authored
Aug 10, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update superuser list
parent
f5e54794
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
203 additions
and
215 deletions
+203
-215
PolicyRvItem.kt
...om/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
+27
-20
SuperuserViewModel.kt
...a/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
+9
-11
DataBindingAdapters.kt
...in/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
+5
-0
fragment_superuser_md2.xml
app/src/main/res/layout/fragment_superuser_md2.xml
+5
-7
item_policy_md2.xml
app/src/main/res/layout/item_policy_md2.xml
+157
-177
No files found.
app/src/main/java/com/topjohnwu/magisk/model/entity/recycler/PolicyRvItem.kt
View file @
c7e30ac6
...
...
@@ -9,53 +9,60 @@ import com.topjohnwu.magisk.databinding.ObservableItem
import
com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
import
com.topjohnwu.magisk.utils.set
class
PolicyItem
(
val
item
:
MagiskPolicy
,
val
icon
:
Drawable
)
:
ObservableItem
<
PolicyItem
>()
{
class
PolicyItem
(
val
item
:
MagiskPolicy
,
val
icon
:
Drawable
,
val
viewModel
:
SuperuserViewModel
)
:
ObservableItem
<
PolicyItem
>()
{
override
val
layoutRes
=
R
.
layout
.
item_policy_md2
@get
:
Bindable
var
isExpanded
=
false
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
expanded
)
@get
:
Bindabl
e
var
isEnabled
=
item
.
policy
==
MagiskPolicy
.
ALLOW
// This property hosts the policy stat
e
var
policyState
=
item
.
policy
==
MagiskPolicy
.
ALLOW
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
enabled
)
// This property binds with the UI state
@get
:
Bindable
var
isEnabled
get
()
=
policyState
set
(
value
)
=
set
(
value
,
policyState
,
{
viewModel
.
togglePolicy
(
this
,
it
)
},
BR
.
enabled
)
@get
:
Bindable
var
shouldNotify
=
item
.
notification
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
shouldNotify
)
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
shouldNotify
)
{
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
false
)
}
@get
:
Bindable
var
shouldLog
=
item
.
logging
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
shouldLog
)
set
(
value
)
=
set
(
value
,
field
,
{
field
=
it
},
BR
.
shouldLog
)
{
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
true
)
}
private
val
updatedPolicy
get
()
=
item
.
copy
(
policy
=
if
(
isEnabled
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
,
policy
=
if
(
policyState
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
,
notification
=
shouldNotify
,
logging
=
shouldLog
)
fun
toggle
(
viewModel
:
SuperuserViewModel
)
{
if
(
isExpanded
)
{
toggle
()
return
}
isEnabled
=
!
isEnabled
viewModel
.
togglePolicy
(
this
,
isEnabled
)
}
fun
toggle
()
{
fun
toggleExpand
()
{
isExpanded
=
!
isExpanded
}
fun
toggleNotify
(
viewModel
:
SuperuserViewModel
)
{
fun
toggleNotify
()
{
shouldNotify
=
!
shouldNotify
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
false
)
}
fun
toggleLog
(
viewModel
:
SuperuserViewModel
)
{
fun
toggleLog
()
{
shouldLog
=
!
shouldLog
viewModel
.
updatePolicy
(
updatedPolicy
,
isLogging
=
true
)
}
fun
revoke
()
{
viewModel
.
deletePressed
(
this
)
}
override
fun
contentSameAs
(
other
:
PolicyItem
)
=
itemSameAs
(
other
)
...
...
app/src/main/java/com/topjohnwu/magisk/ui/superuser/SuperuserViewModel.kt
View file @
c7e30ac6
...
...
@@ -35,9 +35,7 @@ class SuperuserViewModel(
private
val
itemNoData
=
TextItem
(
R
.
string
.
superuser_policy_none
)
private
val
itemsPolicies
=
diffListOf
<
PolicyItem
>()
private
val
itemsHelpers
=
ObservableArrayList
<
TextItem
>().
also
{
it
.
add
(
itemNoData
)
}
private
val
itemsHelpers
=
ObservableArrayList
<
TextItem
>()
val
adapter
=
adapterOf
<
ComparableRvItem
<*>>()
val
items
=
MergeObservableList
<
ComparableRvItem
<*>>()
...
...
@@ -45,7 +43,6 @@ class SuperuserViewModel(
.
insertList
(
itemsHelpers
)
.
insertList
(
itemsPolicies
)
val
itemBinding
=
itemBindingOf
<
ComparableRvItem
<*>>
{
it
.
bindExtra
(
BR
.
viewModel
,
this
)
it
.
bindExtra
(
BR
.
listener
,
this
)
}
...
...
@@ -55,7 +52,7 @@ class SuperuserViewModel(
state
=
State
.
LOADING
val
(
policies
,
diff
)
=
withContext
(
Dispatchers
.
Default
)
{
val
policies
=
db
.
fetchAll
{
PolicyItem
(
it
,
it
.
applicationInfo
.
loadIcon
(
packageManager
))
PolicyItem
(
it
,
it
.
applicationInfo
.
loadIcon
(
packageManager
)
,
this
@SuperuserViewModel
)
}.
sortedWith
(
compareBy
(
{
it
.
item
.
appName
.
toLowerCase
(
currentLocale
)
},
{
it
.
item
.
packageName
}
...
...
@@ -63,15 +60,15 @@ class SuperuserViewModel(
policies
to
itemsPolicies
.
calculateDiff
(
policies
)
}
itemsPolicies
.
update
(
policies
,
diff
)
if
(
itemsPolicies
.
isNotEmpty
())
{
itemsHelpers
.
remove
(
itemNoData
)
}
if
(
itemsPolicies
.
isNotEmpty
())
itemsHelpers
.
clear
()
else
if
(
itemsHelpers
.
isEmpty
())
itemsHelpers
.
add
(
itemNoData
)
state
=
State
.
LOADED
}
// ---
@Suppress
(
"REDUNDANT_ELSE_IN_WHEN"
)
override
fun
onItemPressed
(
item
:
TappableHeadlineItem
)
=
when
(
item
)
{
TappableHeadlineItem
.
Hide
->
hidePressed
()
else
->
Unit
...
...
@@ -120,6 +117,8 @@ class SuperuserViewModel(
fun
togglePolicy
(
item
:
PolicyItem
,
enable
:
Boolean
)
{
fun
updateState
()
{
item
.
policyState
=
enable
val
policy
=
if
(
enable
)
MagiskPolicy
.
ALLOW
else
MagiskPolicy
.
DENY
val
app
=
item
.
item
.
copy
(
policy
=
policy
)
...
...
@@ -127,14 +126,13 @@ class SuperuserViewModel(
db
.
update
(
app
)
val
res
=
if
(
app
.
policy
==
MagiskPolicy
.
ALLOW
)
R
.
string
.
su_snack_grant
else
R
.
string
.
su_snack_deny
SnackbarEvent
(
resources
.
getString
(
res
).
format
(
item
.
item
.
appName
))
SnackbarEvent
(
resources
.
getString
(
res
).
format
(
item
.
item
.
appName
))
.
publish
()
}
}
if
(
BiometricHelper
.
isEnabled
)
{
BiometricDialog
{
onSuccess
{
updateState
()
}
onFailure
{
item
.
isEnabled
=
!
item
.
isEnabled
}
}.
publish
()
}
else
{
updateState
()
...
...
app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt
View file @
c7e30ac6
...
...
@@ -37,6 +37,11 @@ fun setImageResource(view: ImageView, @DrawableRes resId: Int) {
view
.
setImageResource
(
resId
)
}
@BindingAdapter
(
"srcCompat"
)
fun
setImageResource
(
view
:
ImageView
,
drawable
:
Drawable
)
{
view
.
setImageDrawable
(
drawable
)
}
@BindingAdapter
(
"movieBehavior"
,
"movieBehaviorText"
)
fun
setMovieBehavior
(
view
:
TextView
,
isMovieBehavior
:
Boolean
,
text
:
String
)
{
(
view
.
tag
as
?
Job
)
?.
cancel
()
...
...
app/src/main/res/layout/fragment_superuser_md2.xml
View file @
c7e30ac6
...
...
@@ -21,7 +21,7 @@
android:id=
"@+id/superuser_list"
adapter=
"@{viewModel.adapter}"
dividerHorizontal=
"@{@drawable/divider_l1}"
dividerVertical=
"@{@drawable/divider_l
1
}"
dividerVertical=
"@{@drawable/divider_l
_50
}"
goneUnless=
"@{viewModel.loaded || !viewModel.items.empty}"
itemBinding=
"@{viewModel.itemBinding}"
items=
"@{viewModel.items}"
...
...
@@ -33,10 +33,7 @@
android:paddingTop=
"@{viewModel.insets.top + (int) @dimen/internal_action_bar_size + (int) @dimen/l1}"
android:paddingBottom=
"@{viewModel.insets.bottom + (int) @dimen/l2}"
app:layoutManager=
"androidx.recyclerview.widget.LinearLayoutManager"
app:spanCount=
"2"
tools:layout_marginTop=
"24dp"
tools:listitem=
"@layout/item_policy_md2"
tools:paddingTop=
"@dimen/l1"
/>
tools:listitem=
"@layout/item_policy_md2"
/>
<LinearLayout
goneUnless=
"@{viewModel.loading && viewModel.items.empty}"
...
...
@@ -44,9 +41,10 @@
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:gravity=
"center"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
tools:visibility=
"gone"
>
<
androidx.appcompat.widget.AppCompat
TextView
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/safetynet_attest_loading"
...
...
app/src/main/res/layout/item_policy_md2.xml
View file @
c7e30ac6
...
...
@@ -9,22 +9,19 @@
name=
"item"
type=
"com.topjohnwu.magisk.model.entity.recycler.PolicyItem"
/>
<variable
name=
"viewModel"
type=
"com.topjohnwu.magisk.ui.superuser.SuperuserViewModel"
/>
</data>
<FrameLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
>
<com.google.android.material.card.MaterialCardView
style=
"@style/WidgetFoundation.Card.Variant"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:alpha=
"@{item.isEnabled() ? 1f : .5f}"
android:onClick=
"@{() -> item.toggle(viewModel)}"
android:onLongClick=
"@{() -> item.toggle()}"
tools:layout_marginBottom=
"@dimen/l1"
tools:layout_marginEnd=
"@dimen/l1"
>
android:alpha=
"@{item.enabled ? 1f : .5f}"
android:onClick=
"@{() -> item.toggleExpand()}"
>
<LinearLayout
android:layout_width=
"match_parent"
...
...
@@ -35,20 +32,20 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<androidx.appcompat.widget.AppCompat
ImageView
<
ImageView
android:id=
"@+id/policy_app_icon"
style=
"@style/WidgetFoundation.Image"
android:layout_marginStart=
"@dimen/l1"
android:layout_marginTop=
"@dimen/l1"
android:layout_marginBottom=
"@dimen/l1"
android:src
=
"@{item.icon}"
srcCompat
=
"@{item.icon}"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintVertical_bias=
"0"
tools:srcCompat=
"@drawable/ic_logo"
/>
<androidx.appcompat.widget.AppCompat
TextView
<
TextView
android:id=
"@+id/policy_app_name"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
...
...
@@ -66,7 +63,7 @@
app:layout_constraintTop_toTopOf=
"@+id/policy_app_icon"
tools:text=
"@string/app_name"
/>
<androidx.appcompat.widget.AppCompat
TextView
<
TextView
android:id=
"@+id/policy_package_name"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
...
...
@@ -85,10 +82,11 @@
app:layout_constraintVertical_bias=
"0"
tools:text=
"com.topjohnwu.magisk"
/>
<androidx.appcompat.widget.AppCompatImageView
<com.google.android.material.switchmaterial.SwitchMaterial
android:id=
"@+id/policy_indicator"
style=
"@style/WidgetFoundation.Switch"
isSelected=
"@{item.enabled}"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:checked=
"@={item.enabled}"
android:layout_marginEnd=
"@dimen/l1"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
...
...
@@ -96,103 +94,85 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.Constraint
Layout
<Linear
Layout
android:id=
"@+id/policy_expand_container"
android:orientation=
"horizontal"
gone=
"@{!item.isExpanded}"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"?colorSurfaceVariant"
android:visibility=
"gone"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/policy_package_name"
tools:visibility=
"visible"
>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/policy_notify"
style=
"@style/WidgetFoundation.Button.Text"
isSelected=
"@{item.shouldNotify}"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:minHeight=
"24dp"
android:onClick=
"@{() -> item.toggleNotify(viewModel
)}"
android:onClick=
"@{() -> item.toggleNotify(
)}"
android:text=
"@string/superuser_toggle_notification"
android:textAllCaps=
"false"
android:textAppearance=
"@style/AppearanceFoundation.Tiny"
android:textColor=
"@color/color_state_primary_transient"
app:icon=
"@drawable/ic_notifications_md2"
app:iconTint=
"@color/color_state_primary_transient"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/policy_log"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
app:tint=
"@color/color_state_primary_transient"
/>
<View
android:layout_width=
"1dp"
android:layout_height=
"0dp
"
android:layout_height=
"match_parent
"
android:layout_marginTop=
"@dimen/l_50"
android:layout_marginBottom=
"@dimen/l_50"
android:background=
"?colorSurface"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/policy_notify"
app:layout_constraintTop_toTopOf=
"parent"
/>
android:background=
"?colorSurfaceSurfaceVariant"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/policy_log"
style=
"@style/WidgetFoundation.Button.Text"
isSelected=
"@{item.shouldLog}"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:minHeight=
"24dp"
android:onClick=
"@{() -> item.toggleLog(viewModel
)}"
android:onClick=
"@{() -> item.toggleLog(
)}"
android:text=
"@string/logs"
android:textAllCaps=
"false"
android:textAppearance=
"@style/AppearanceFoundation.Tiny"
android:textColor=
"@color/color_state_primary_transient"
app:icon=
"@drawable/ic_bug_md2"
app:iconTint=
"@color/color_state_primary_transient"
app:layout_constrainedWidth=
"true"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toStartOf=
"@+id/policy_delete"
app:layout_constraintStart_toEndOf=
"@+id/policy_notify"
app:layout_constraintTop_toTopOf=
"parent"
app:tint=
"@color/color_state_primary_transient"
/>
<View
android:layout_width=
"1dp"
android:layout_height=
"0dp
"
android:layout_height=
"match_parent
"
android:layout_marginTop=
"@dimen/l_50"
android:layout_marginBottom=
"@dimen/l_50"
android:background=
"?colorSurface"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/policy_log"
app:layout_constraintTop_toTopOf=
"parent"
/>
android:background=
"?colorSurfaceSurfaceVariant"
/>
<com.google.android.material.button.MaterialButton
android:id=
"@+id/policy_delete"
style=
"@style/WidgetFoundation.Button.Text"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:minHeight=
"24dp"
android:onClick=
"@{() -> viewModel.deletePressed(item
)}"
android:onClick=
"@{() -> item.revoke(
)}"
android:text=
"@string/superuser_toggle_revoke"
android:textAllCaps=
"false"
android:textColor=
"?colorError"
android:textSize=
"12sp"
app:icon=
"@drawable/ic_delete_md2"
app:iconTint=
"?colorError"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@+id/policy_log"
app:layout_constraintTop_toTopOf=
"parent"
app:rippleColor=
"?colorError"
/>
</androidx.constraintlayout.widget.Constraint
Layout>
</Linear
Layout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</FrameLayout>
</layout>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment