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
8ac3aaf3
Commit
8ac3aaf3
authored
Mar 24, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Topic -> Event
parent
a199b0ac
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
183 additions
and
178 deletions
+183
-178
MainActivity.java
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
+1
-7
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+2
-2
BaseActivity.java
...in/java/com/topjohnwu/magisk/components/BaseActivity.java
+6
-6
BaseFragment.java
...in/java/com/topjohnwu/magisk/components/BaseFragment.java
+6
-6
BasePreferenceFragment.java
...m/topjohnwu/magisk/components/BasePreferenceFragment.java
+5
-5
MagiskFragment.java
...n/java/com/topjohnwu/magisk/fragments/MagiskFragment.java
+6
-7
MagiskHideFragment.java
...va/com/topjohnwu/magisk/fragments/MagiskHideFragment.java
+5
-5
ModulesFragment.java
.../java/com/topjohnwu/magisk/fragments/ModulesFragment.java
+6
-6
ReposFragment.java
...in/java/com/topjohnwu/magisk/fragments/ReposFragment.java
+10
-13
SettingsFragment.java
...java/com/topjohnwu/magisk/fragments/SettingsFragment.java
+5
-5
CheckUpdates.java
...rc/main/java/com/topjohnwu/magisk/tasks/CheckUpdates.java
+2
-2
UpdateRepos.java
...src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java
+3
-3
Event.java
app/src/main/java/com/topjohnwu/magisk/utils/Event.java
+123
-0
LocaleManager.java
...c/main/java/com/topjohnwu/magisk/utils/LocaleManager.java
+1
-1
Topic.java
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
+0
-108
Utils.java
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
+2
-2
No files found.
app/src/main/java/com/topjohnwu/magisk/MainActivity.java
View file @
8ac3aaf3
...
...
@@ -24,7 +24,6 @@ import com.topjohnwu.magisk.fragments.ModulesFragment;
import
com.topjohnwu.magisk.fragments.ReposFragment
;
import
com.topjohnwu.magisk.fragments.SettingsFragment
;
import
com.topjohnwu.magisk.fragments.SuperuserFragment
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -32,7 +31,7 @@ import com.topjohnwu.superuser.Shell;
import
butterknife.BindView
;
public
class
MainActivity
extends
BaseActivity
implements
NavigationView
.
OnNavigationItemSelectedListener
,
Topic
.
Subscriber
{
implements
NavigationView
.
OnNavigationItemSelectedListener
{
private
final
Handler
mDrawerHandler
=
new
Handler
();
private
int
mDrawerItem
;
...
...
@@ -116,11 +115,6 @@ public class MainActivity extends BaseActivity
return
true
;
}
@Override
public
void
onPublish
(
int
topic
,
Object
[]
result
)
{
recreate
();
}
public
void
checkHideSection
()
{
Menu
menu
=
navigationView
.
getMenu
();
menu
.
findItem
(
R
.
id
.
magiskhide
).
setVisible
(
Shell
.
rootAccess
()
&&
...
...
app/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
8ac3aaf3
...
...
@@ -25,7 +25,7 @@ import com.topjohnwu.magisk.Config;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.uicomponents.ArrowExpandable
;
import
com.topjohnwu.magisk.uicomponents.Expandable
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.internal.UiThreadHandler
;
...
...
@@ -257,7 +257,7 @@ public class ApplicationAdapter extends SectionedAdapter
}).
filter
(
Objects:
:
nonNull
).
sorted
()
.
collect
(
Collectors
.
toList
());
Topic
.
publish
(
false
,
Topic
.
MAGISK_HIDE_DONE
);
Event
.
trigger
(
false
,
Event
.
MAGISK_HIDE_DONE
);
}
// True if not system app or user already hidden it
...
...
app/src/main/java/com/topjohnwu/magisk/components/BaseActivity.java
View file @
8ac3aaf3
...
...
@@ -22,10 +22,10 @@ import com.topjohnwu.magisk.App;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.Event
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Topic
;
public
abstract
class
BaseActivity
extends
AppCompatActivity
implements
Topic
.
AutoSubscrib
er
{
public
abstract
class
BaseActivity
extends
AppCompatActivity
implements
Event
.
AutoListen
er
{
public
static
final
String
INTENT_PERM
=
"perm_dialog"
;
private
static
Runnable
grantCallback
;
...
...
@@ -40,12 +40,12 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
public
int
[]
get
ListeningEvent
s
()
{
return
EMPTY_INT_ARRAY
;
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{}
public
void
on
Event
(
int
even
t
)
{}
@StyleRes
public
int
getDarkTheme
()
{
...
...
@@ -59,7 +59,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
Topic
.
subscribe
(
this
);
Event
.
register
(
this
);
if
(
getDarkTheme
()
!=
-
1
&&
(
boolean
)
Config
.
get
(
Config
.
Key
.
DARK_THEME
))
{
setTheme
(
getDarkTheme
());
}
...
...
@@ -71,7 +71,7 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au
@Override
protected
void
onDestroy
()
{
Topic
.
unsubscribe
(
this
);
Event
.
unregister
(
this
);
super
.
onDestroy
();
}
...
...
app/src/main/java/com/topjohnwu/magisk/components/BaseFragment.java
View file @
8ac3aaf3
...
...
@@ -5,11 +5,11 @@ import android.content.Intent;
import
androidx.fragment.app.Fragment
;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
butterknife.Unbinder
;
public
abstract
class
BaseFragment
extends
Fragment
implements
Topic
.
AutoSubscrib
er
{
public
abstract
class
BaseFragment
extends
Fragment
implements
Event
.
AutoListen
er
{
public
App
app
=
App
.
self
;
protected
Unbinder
unbinder
=
null
;
...
...
@@ -17,12 +17,12 @@ public abstract class BaseFragment extends Fragment implements Topic.AutoSubscri
@Override
public
void
onResume
()
{
super
.
onResume
();
Topic
.
subscribe
(
this
);
Event
.
register
(
this
);
}
@Override
public
void
onPause
()
{
Topic
.
unsubscribe
(
this
);
Event
.
unregister
(
this
);
super
.
onPause
();
}
...
...
@@ -47,10 +47,10 @@ public abstract class BaseFragment extends Fragment implements Topic.AutoSubscri
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
public
int
[]
get
ListeningEvent
s
()
{
return
BaseActivity
.
EMPTY_INT_ARRAY
;
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{}
public
void
on
Event
(
int
even
t
)
{}
}
app/src/main/java/com/topjohnwu/magisk/components/BasePreferenceFragment.java
View file @
8ac3aaf3
...
...
@@ -18,10 +18,10 @@ import androidx.recyclerview.widget.RecyclerView;
import
com.topjohnwu.magisk.App
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
public
abstract
class
BasePreferenceFragment
extends
PreferenceFragmentCompat
implements
SharedPreferences
.
OnSharedPreferenceChangeListener
,
Topic
.
AutoSubscrib
er
{
implements
SharedPreferences
.
OnSharedPreferenceChangeListener
,
Event
.
AutoListen
er
{
public
App
app
=
App
.
self
;
...
...
@@ -29,19 +29,19 @@ public abstract class BasePreferenceFragment extends PreferenceFragmentCompat
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
View
v
=
super
.
onCreateView
(
inflater
,
container
,
savedInstanceState
);
app
.
prefs
.
registerOnSharedPreferenceChangeListener
(
this
);
Topic
.
subscribe
(
this
);
Event
.
register
(
this
);
return
v
;
}
@Override
public
void
onDestroyView
()
{
app
.
prefs
.
unregisterOnSharedPreferenceChangeListener
(
this
);
Topic
.
unsubscribe
(
this
);
Event
.
unregister
(
this
);
super
.
onDestroyView
();
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
public
int
[]
get
ListeningEvent
s
()
{
return
BaseActivity
.
EMPTY_INT_ARRAY
;
}
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/MagiskFragment.java
View file @
8ac3aaf3
...
...
@@ -38,7 +38,7 @@ import com.topjohnwu.magisk.uicomponents.MarkDownWindow;
import
com.topjohnwu.magisk.uicomponents.SafetyNet
;
import
com.topjohnwu.magisk.uicomponents.UpdateCardHolder
;
import
com.topjohnwu.magisk.utils.AppUtils
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -48,8 +48,7 @@ import butterknife.BindColor;
import
butterknife.BindView
;
import
butterknife.OnClick
;
public
class
MagiskFragment
extends
BaseFragment
implements
SwipeRefreshLayout
.
OnRefreshListener
,
Topic
.
Subscriber
{
public
class
MagiskFragment
extends
BaseFragment
implements
SwipeRefreshLayout
.
OnRefreshListener
{
private
static
boolean
shownDialog
=
false
;
...
...
@@ -195,7 +194,7 @@ public class MagiskFragment extends BaseFragment
Config
.
loadMagiskInfo
();
updateUI
();
Topic
.
reset
(
getSubscribedTopics
()
);
Event
.
reset
(
this
);
Config
.
remoteMagiskVersionString
=
null
;
Config
.
remoteMagiskVersionCode
=
-
1
;
...
...
@@ -208,12 +207,12 @@ public class MagiskFragment extends BaseFragment
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
return
new
int
[]
{
Topic
.
UPDATE_CHECK_DONE
};
public
int
[]
get
ListeningEvent
s
()
{
return
new
int
[]
{
Event
.
UPDATE_CHECK_DONE
};
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{
public
void
on
Event
(
int
even
t
)
{
updateCheckUI
();
}
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/MagiskHideFragment.java
View file @
8ac3aaf3
...
...
@@ -18,11 +18,11 @@ import com.topjohnwu.magisk.Config;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.adapters.ApplicationAdapter
;
import
com.topjohnwu.magisk.components.BaseFragment
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
butterknife.BindView
;
public
class
MagiskHideFragment
extends
BaseFragment
implements
Topic
.
Subscriber
{
public
class
MagiskHideFragment
extends
BaseFragment
{
@BindView
(
R
.
id
.
swipeRefreshLayout
)
SwipeRefreshLayout
mSwipeRefreshLayout
;
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
...
...
@@ -89,12 +89,12 @@ public class MagiskHideFragment extends BaseFragment implements Topic.Subscriber
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
return
new
int
[]
{
Topic
.
MAGISK_HIDE_DONE
};
public
int
[]
get
ListeningEvent
s
()
{
return
new
int
[]
{
Event
.
MAGISK_HIDE_DONE
};
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{
public
void
on
Event
(
int
even
t
)
{
mSwipeRefreshLayout
.
setRefreshing
(
false
);
adapter
.
filter
(
search
.
getQuery
().
toString
());
}
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/ModulesFragment.java
View file @
8ac3aaf3
...
...
@@ -24,7 +24,7 @@ import com.topjohnwu.magisk.R;
import
com.topjohnwu.magisk.adapters.ModulesAdapter
;
import
com.topjohnwu.magisk.components.BaseFragment
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -35,7 +35,7 @@ import java.util.Map;
import
butterknife.BindView
;
import
butterknife.OnClick
;
public
class
ModulesFragment
extends
BaseFragment
implements
Topic
.
Subscriber
{
public
class
ModulesFragment
extends
BaseFragment
{
@BindView
(
R
.
id
.
swipeRefreshLayout
)
SwipeRefreshLayout
mSwipeRefreshLayout
;
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
...
...
@@ -82,13 +82,13 @@ public class ModulesFragment extends BaseFragment implements Topic.Subscriber {
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
return
new
int
[]
{
Topic
.
MODULE_LOAD_DONE
};
public
int
[]
get
ListeningEvent
s
()
{
return
new
int
[]
{
Event
.
MODULE_LOAD_DONE
};
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{
updateUI
(
(
Map
<
String
,
Module
>)
result
[
0
]
);
public
void
on
Event
(
int
even
t
)
{
updateUI
(
Event
.
getResult
(
event
)
);
}
@Override
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/ReposFragment.java
View file @
8ac3aaf3
...
...
@@ -20,15 +20,12 @@ import com.topjohnwu.magisk.Config;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.adapters.ReposAdapter
;
import
com.topjohnwu.magisk.components.BaseFragment
;
import
com.topjohnwu.magisk.container.Module
;
import
com.topjohnwu.magisk.tasks.UpdateRepos
;
import
com.topjohnwu.magisk.utils.Topic
;
import
java.util.Map
;
import
com.topjohnwu.magisk.utils.Event
;
import
butterknife.BindView
;
public
class
ReposFragment
extends
BaseFragment
implements
Topic
.
Subscriber
{
public
class
ReposFragment
extends
BaseFragment
{
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
@BindView
(
R
.
id
.
empty_rv
)
TextView
emptyRv
;
...
...
@@ -59,23 +56,23 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber {
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
return
new
int
[]
{
Topic
.
MODULE_LOAD_DONE
,
Topic
.
REPO_LOAD_DONE
};
public
int
[]
get
ListeningEvent
s
()
{
return
new
int
[]
{
Event
.
MODULE_LOAD_DONE
,
Event
.
REPO_LOAD_DONE
};
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{
switch
(
topic
)
{
case
Topic
.
MODULE_LOAD_DONE
:
adapter
=
new
ReposAdapter
(
app
.
repoDB
,
(
Map
<
String
,
Module
>)
result
[
0
]
);
public
void
on
Event
(
int
even
t
)
{
switch
(
event
)
{
case
Event
.
MODULE_LOAD_DONE
:
adapter
=
new
ReposAdapter
(
app
.
repoDB
,
Event
.
getResult
(
event
)
);
recyclerView
.
setAdapter
(
adapter
);
break
;
case
Topic
.
REPO_LOAD_DONE
:
case
Event
.
REPO_LOAD_DONE
:
if
(
adapter
!=
null
)
adapter
.
notifyDBChanged
();
break
;
}
if
(
Topic
.
isPublish
ed
(
this
))
{
if
(
Event
.
isTrigger
ed
(
this
))
{
mSwipeRefreshLayout
.
setRefreshing
(
false
);
boolean
empty
=
adapter
.
getItemCount
()
==
0
;
recyclerView
.
setVisibility
(
empty
?
View
.
GONE
:
View
.
VISIBLE
);
...
...
app/src/main/java/com/topjohnwu/magisk/fragments/SettingsFragment.java
View file @
8ac3aaf3
...
...
@@ -24,10 +24,10 @@ import com.topjohnwu.magisk.dialogs.FingerprintAuthDialog;
import
com.topjohnwu.magisk.tasks.CheckUpdates
;
import
com.topjohnwu.magisk.utils.AppUtils
;
import
com.topjohnwu.magisk.utils.DownloadApp
;
import
com.topjohnwu.magisk.utils.Event
;
import
com.topjohnwu.magisk.utils.FingerprintHelper
;
import
com.topjohnwu.magisk.utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.PatchAPK
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.superuser.Shell
;
...
...
@@ -36,7 +36,7 @@ import java.io.IOException;
import
java.util.Arrays
;
import
java.util.Locale
;
public
class
SettingsFragment
extends
BasePreferenceFragment
implements
Topic
.
Subscriber
{
public
class
SettingsFragment
extends
BasePreferenceFragment
{
private
ListPreference
updateChannel
,
autoRes
,
suNotification
,
requestTimeout
,
rootConfig
,
multiuserConfig
,
nsConfig
;
...
...
@@ -288,12 +288,12 @@ public class SettingsFragment extends BasePreferenceFragment implements Topic.Su
}
@Override
public
void
on
Publish
(
int
topic
,
Object
[]
resul
t
)
{
public
void
on
Event
(
int
even
t
)
{
setLocalePreference
((
ListPreference
)
findPreference
(
Config
.
Key
.
LOCALE
));
}
@Override
public
int
[]
get
SubscribedTopic
s
()
{
return
new
int
[]
{
Topic
.
LOCALE_FETCH_DONE
};
public
int
[]
get
ListeningEvent
s
()
{
return
new
int
[]
{
Event
.
LOCALE_FETCH_DONE
};
}
}
app/src/main/java/com/topjohnwu/magisk/tasks/CheckUpdates.java
View file @
8ac3aaf3
...
...
@@ -4,7 +4,7 @@ import android.os.SystemClock;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.utils.
Topic
;
import
com.topjohnwu.magisk.utils.
Event
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.Request
;
import
com.topjohnwu.net.ResponseListener
;
...
...
@@ -104,7 +104,7 @@ public class CheckUpdates {
JSONObject
uninstaller
=
getJson
(
json
,
"uninstaller"
);
Config
.
uninstallerLink
=
getString
(
uninstaller
,
"link"
,
null
);
UiThreadHandler
.
handler
.
postAtTime
(()
->
Topic
.
publish
(
Topic
.
UPDATE_CHECK_DONE
),
UiThreadHandler
.
handler
.
postAtTime
(()
->
Event
.
trigger
(
Event
.
UPDATE_CHECK_DONE
),
start
+
1000
/* Add artificial delay to let UI behave correctly */
);
if
(
cb
!=
null
)
...
...
app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java
View file @
8ac3aaf3
...
...
@@ -7,8 +7,8 @@ import com.topjohnwu.magisk.App;
import
com.topjohnwu.magisk.Config
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.container.Repo
;
import
com.topjohnwu.magisk.utils.Event
;
import
com.topjohnwu.magisk.utils.Logger
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Utils
;
import
com.topjohnwu.net.Networking
;
import
com.topjohnwu.net.Request
;
...
...
@@ -155,7 +155,7 @@ public class UpdateRepos {
}
public
void
exec
(
boolean
force
)
{
Topic
.
reset
(
Topic
.
REPO_LOAD_DONE
);
Event
.
reset
(
Event
.
REPO_LOAD_DONE
);
App
.
THREAD_POOL
.
execute
(()
->
{
cached
=
Collections
.
synchronizedSet
(
app
.
repoDB
.
getRepoIDSet
());
moduleQueue
=
new
ConcurrentLinkedQueue
<>();
...
...
@@ -166,7 +166,7 @@ public class UpdateRepos {
}
else
if
(
force
)
{
fullReload
();
}
Topic
.
publish
(
Topic
.
REPO_LOAD_DONE
);
Event
.
trigger
(
Event
.
REPO_LOAD_DONE
);
});
}
...
...
app/src/main/java/com/topjohnwu/magisk/utils/Event.java
0 → 100644
View file @
8ac3aaf3
package
com
.
topjohnwu
.
magisk
.
utils
;
import
androidx.annotation.IntDef
;
import
androidx.collection.ArraySet
;
import
com.topjohnwu.superuser.internal.UiThreadHandler
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.util.Set
;
public
class
Event
{
public
static
final
int
MAGISK_HIDE_DONE
=
0
;
public
static
final
int
MODULE_LOAD_DONE
=
1
;
public
static
final
int
REPO_LOAD_DONE
=
2
;
public
static
final
int
UPDATE_CHECK_DONE
=
3
;
public
static
final
int
LOCALE_FETCH_DONE
=
4
;
@IntDef
({
MAGISK_HIDE_DONE
,
MODULE_LOAD_DONE
,
REPO_LOAD_DONE
,
UPDATE_CHECK_DONE
,
LOCALE_FETCH_DONE
})
@Retention
(
RetentionPolicy
.
SOURCE
)
public
@interface
EventID
{}
// We will not dynamically add topics, so use arrays instead of hash tables
private
static
Store
[]
eventList
=
new
Store
[
5
];
public
static
void
register
(
Listener
listener
,
@EventID
int
...
events
)
{
for
(
int
event
:
events
)
{
if
(
eventList
[
event
]
==
null
)
eventList
[
event
]
=
new
Store
();
eventList
[
event
].
listeners
.
add
(
listener
);
if
(
eventList
[
event
].
triggered
)
{
listener
.
onEvent
(
event
);
}
}
}
public
static
void
register
(
AutoListener
listener
)
{
register
(
listener
,
listener
.
getListeningEvents
());
}
public
static
void
unregister
(
Listener
listener
,
@EventID
int
...
events
)
{
for
(
int
event
:
events
)
{
if
(
eventList
[
event
]
==
null
)
continue
;
eventList
[
event
].
listeners
.
remove
(
listener
);
}
}
public
static
void
unregister
(
AutoListener
listener
)
{
unregister
(
listener
,
listener
.
getListeningEvents
());
}
public
static
void
trigger
(
@EventID
int
event
)
{
trigger
(
true
,
event
,
null
);
}
public
static
void
trigger
(
@EventID
int
event
,
Object
result
)
{
trigger
(
true
,
event
,
result
);
}
public
static
void
trigger
(
boolean
perm
,
@EventID
int
event
)
{
trigger
(
perm
,
event
,
null
);
}
public
static
void
trigger
(
boolean
perm
,
@EventID
int
event
,
Object
result
)
{
if
(
eventList
[
event
]
==
null
)
eventList
[
event
]
=
new
Store
();
if
(
perm
)
{
eventList
[
event
].
result
=
result
;
eventList
[
event
].
triggered
=
true
;
}
for
(
Listener
sub
:
eventList
[
event
].
listeners
)
{
UiThreadHandler
.
run
(()
->
sub
.
onEvent
(
event
));
}
}
public
static
void
reset
(
@EventID
int
event
)
{
if
(
eventList
[
event
]
==
null
)
return
;
eventList
[
event
].
triggered
=
false
;
eventList
[
event
].
result
=
null
;
}
public
static
void
reset
(
AutoListener
listener
)
{
for
(
int
event
:
listener
.
getListeningEvents
())
reset
(
event
);
}
public
static
boolean
isTriggered
(
@EventID
int
event
)
{
if
(
eventList
[
event
]
==
null
)
return
false
;
return
eventList
[
event
].
triggered
;
}
public
static
boolean
isTriggered
(
AutoListener
listener
)
{
for
(
int
event
:
listener
.
getListeningEvents
())
{
if
(!
isTriggered
(
event
))
return
false
;
}
return
true
;
}
public
static
<
T
>
T
getResult
(
@EventID
int
event
)
{
return
(
T
)
eventList
[
event
].
result
;
}
private
static
class
Store
{
boolean
triggered
=
false
;
Set
<
Listener
>
listeners
=
new
ArraySet
<>();
Object
result
;
}
public
interface
Listener
{
void
onEvent
(
int
event
);
}
public
interface
AutoListener
extends
Listener
{
@EventID
int
[]
getListeningEvents
();
}
}
app/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java
View file @
8ac3aaf3
...
...
@@ -141,7 +141,7 @@ public class LocaleManager {
}
Collections
.
sort
(
locales
,
(
a
,
b
)
->
a
.
getDisplayName
(
a
).
compareTo
(
b
.
getDisplayName
(
b
)));
Topic
.
publish
(
Topic
.
LOCALE_FETCH_DONE
);
Event
.
trigger
(
Event
.
LOCALE_FETCH_DONE
);
});
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
deleted
100644 → 0
View file @
a199b0ac
package
com
.
topjohnwu
.
magisk
.
utils
;
import
androidx.annotation.IntDef
;
import
com.topjohnwu.superuser.internal.UiThreadHandler
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
Topic
{
public
static
final
int
MAGISK_HIDE_DONE
=
0
;
public
static
final
int
MODULE_LOAD_DONE
=
1
;
public
static
final
int
REPO_LOAD_DONE
=
2
;
public
static
final
int
UPDATE_CHECK_DONE
=
3
;
public
static
final
int
LOCALE_FETCH_DONE
=
4
;
@IntDef
({
MAGISK_HIDE_DONE
,
MODULE_LOAD_DONE
,
REPO_LOAD_DONE
,
UPDATE_CHECK_DONE
,
LOCALE_FETCH_DONE
})
@Retention
(
RetentionPolicy
.
SOURCE
)
public
@interface
TopicID
{}
// We will not dynamically add topics, so use arrays instead of hash tables
private
static
Store
[]
topicList
=
new
Store
[
5
];
public
static
void
subscribe
(
Subscriber
sub
,
@TopicID
int
...
topics
)
{
for
(
int
topic
:
topics
)
{
if
(
topicList
[
topic
]
==
null
)
topicList
[
topic
]
=
new
Store
();
topicList
[
topic
].
subscribers
.
add
(
sub
);
if
(
topicList
[
topic
].
published
)
{
sub
.
onPublish
(
topic
,
topicList
[
topic
].
results
);
}
}
}
public
static
void
subscribe
(
AutoSubscriber
sub
)
{
subscribe
(
sub
,
sub
.
getSubscribedTopics
());
}
public
static
void
unsubscribe
(
Subscriber
sub
,
@TopicID
int
...
topics
)
{
for
(
int
topic
:
topics
)
{
if
(
topicList
[
topic
]
==
null
)
continue
;
topicList
[
topic
].
subscribers
.
remove
(
sub
);
}
}
public
static
void
unsubscribe
(
AutoSubscriber
sub
)
{
unsubscribe
(
sub
,
sub
.
getSubscribedTopics
());
}
public
static
void
publish
(
@TopicID
int
topic
,
Object
...
results
)
{
publish
(
true
,
topic
,
results
);
}
public
static
void
publish
(
boolean
persist
,
@TopicID
int
topic
,
Object
...
results
)
{
if
(
topicList
[
topic
]
==
null
)
topicList
[
topic
]
=
new
Store
();
if
(
persist
)
{
topicList
[
topic
].
results
=
results
;
topicList
[
topic
].
published
=
true
;
}
for
(
Subscriber
sub
:
topicList
[
topic
].
subscribers
)
{
UiThreadHandler
.
run
(()
->
sub
.
onPublish
(
topic
,
results
));
}
}
public
static
void
reset
(
@TopicID
int
...
topics
)
{
for
(
int
topic
:
topics
)
{
if
(
topicList
[
topic
]
==
null
)
continue
;
topicList
[
topic
].
published
=
false
;
topicList
[
topic
].
results
=
null
;
}
}
public
static
boolean
isPublished
(
@TopicID
int
...
topics
)
{
for
(
int
topic
:
topics
)
{
if
(
topicList
[
topic
]
==
null
)
return
false
;
if
(!
topicList
[
topic
].
published
)
return
false
;
}
return
true
;
}
public
static
boolean
isPublished
(
AutoSubscriber
sub
)
{
return
isPublished
(
sub
.
getSubscribedTopics
());
}
private
static
class
Store
{
boolean
published
=
false
;
Set
<
Subscriber
>
subscribers
=
new
HashSet
<>();
Object
[]
results
;
}
public
interface
Subscriber
{
void
onPublish
(
int
topic
,
Object
[]
result
);
}
public
interface
AutoSubscriber
extends
Subscriber
{
@TopicID
int
[]
getSubscribedTopics
();
}
}
app/src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
8ac3aaf3
...
...
@@ -95,7 +95,7 @@ public class Utils {
}
public
static
void
loadModules
()
{
Topic
.
reset
(
Topic
.
MODULE_LOAD_DONE
);
Event
.
reset
(
Event
.
MODULE_LOAD_DONE
);
App
.
THREAD_POOL
.
execute
(()
->
{
Map
<
String
,
Module
>
moduleMap
=
new
ValueSortedMap
<>();
SuFile
path
=
new
SuFile
(
Const
.
MAGISK_PATH
);
...
...
@@ -106,7 +106,7 @@ public class Utils {
Module
module
=
new
Module
(
Const
.
MAGISK_PATH
+
"/"
+
file
.
getName
());
moduleMap
.
put
(
module
.
getId
(),
module
);
}
Topic
.
publish
(
Topic
.
MODULE_LOAD_DONE
,
moduleMap
);
Event
.
trigger
(
Event
.
MODULE_LOAD_DONE
,
moduleMap
);
});
}
...
...
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