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
8574a14e
Commit
8574a14e
authored
Aug 01, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve locale settings
parent
e90c555c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
111 deletions
+110
-111
MagiskHideFragment.java
...rc/full/java/com/topjohnwu/magisk/MagiskHideFragment.java
+8
-6
MagiskManager.java
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
+7
-2
SettingsActivity.java
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
+1
-1
SplashActivity.java
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
+1
-1
ApplicationAdapter.java
...ava/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
+53
-45
FlavorActivity.java
.../java/com/topjohnwu/magisk/components/FlavorActivity.java
+7
-5
SuReceiver.java
.../full/java/com/topjohnwu/magisk/superuser/SuReceiver.java
+5
-6
LocaleManager.java
...c/full/java/com/topjohnwu/magisk/utils/LocaleManager.java
+28
-45
No files found.
app/src/full/java/com/topjohnwu/magisk/MagiskHideFragment.java
View file @
8574a14e
package
com
.
topjohnwu
.
magisk
;
package
com
.
topjohnwu
.
magisk
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v4.widget.SwipeRefreshLayout
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView
;
...
@@ -24,6 +25,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
...
@@ -24,6 +25,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
private
Unbinder
unbinder
;
private
Unbinder
unbinder
;
@BindView
(
R
.
id
.
swipeRefreshLayout
)
SwipeRefreshLayout
mSwipeRefreshLayout
;
@BindView
(
R
.
id
.
swipeRefreshLayout
)
SwipeRefreshLayout
mSwipeRefreshLayout
;
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
@BindView
(
R
.
id
.
recyclerView
)
RecyclerView
recyclerView
;
SearchView
search
;
private
ApplicationAdapter
appAdapter
;
private
ApplicationAdapter
appAdapter
;
...
@@ -37,14 +39,14 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
...
@@ -37,14 +39,14 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
@Nullable
@Nullable
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
public
View
onCreateView
(
@NonNull
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_magisk_hide
,
container
,
false
);
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_magisk_hide
,
container
,
false
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
unbinder
=
ButterKnife
.
bind
(
this
,
view
);
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setRefreshing
(
true
);
mSwipeRefreshLayout
.
setOnRefreshListener
(
()
->
appAdapter
.
refresh
()
);
mSwipeRefreshLayout
.
setOnRefreshListener
(
appAdapter:
:
refresh
);
appAdapter
=
new
ApplicationAdapter
();
appAdapter
=
new
ApplicationAdapter
(
requireActivity
()
);
recyclerView
.
setAdapter
(
appAdapter
);
recyclerView
.
setAdapter
(
appAdapter
);
searchListener
=
new
SearchView
.
OnQueryTextListener
()
{
searchListener
=
new
SearchView
.
OnQueryTextListener
()
{
...
@@ -61,7 +63,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
...
@@ -61,7 +63,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
}
}
};
};
get
Activity
().
setTitle
(
R
.
string
.
magiskhide
);
require
Activity
().
setTitle
(
R
.
string
.
magiskhide
);
return
view
;
return
view
;
}
}
...
@@ -69,7 +71,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
...
@@ -69,7 +71,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
@Override
@Override
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
public
void
onCreateOptionsMenu
(
Menu
menu
,
MenuInflater
inflater
)
{
inflater
.
inflate
(
R
.
menu
.
menu_magiskhide
,
menu
);
inflater
.
inflate
(
R
.
menu
.
menu_magiskhide
,
menu
);
SearchView
search
=
(
SearchView
)
menu
.
findItem
(
R
.
id
.
app_search
).
getActionView
();
search
=
(
SearchView
)
menu
.
findItem
(
R
.
id
.
app_search
).
getActionView
();
search
.
setOnQueryTextListener
(
searchListener
);
search
.
setOnQueryTextListener
(
searchListener
);
}
}
...
@@ -87,6 +89,6 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
...
@@ -87,6 +89,6 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
@Override
@Override
public
void
onPublish
(
int
topic
,
Object
[]
result
)
{
public
void
onPublish
(
int
topic
,
Object
[]
result
)
{
mSwipeRefreshLayout
.
setRefreshing
(
false
);
mSwipeRefreshLayout
.
setRefreshing
(
false
);
appAdapter
.
filter
(
null
);
appAdapter
.
filter
(
search
.
getQuery
().
toString
()
);
}
}
}
}
app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
View file @
8574a14e
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
...
@@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
import
android.content.SharedPreferences
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.preference.PreferenceManager
;
import
android.preference.PreferenceManager
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
...
@@ -14,7 +15,6 @@ import com.topjohnwu.superuser.ContainerApp;
...
@@ -14,7 +15,6 @@ import com.topjohnwu.superuser.ContainerApp;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.Shell
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.Map
;
public
class
MagiskManager
extends
ContainerApp
{
public
class
MagiskManager
extends
ContainerApp
{
...
@@ -58,8 +58,13 @@ public class MagiskManager extends ContainerApp {
...
@@ -58,8 +58,13 @@ public class MagiskManager extends ContainerApp {
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{}
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{}
}
}
LocaleManager
.
setLocale
();
LocaleManager
.
setLocale
(
this
);
Data
.
loadConfig
();
Data
.
loadConfig
();
}
}
@Override
public
void
onConfigurationChanged
(
Configuration
newConfig
)
{
super
.
onConfigurationChanged
(
newConfig
);
LocaleManager
.
setLocale
(
this
);
}
}
}
app/src/full/java/com/topjohnwu/magisk/SettingsActivity.java
View file @
8574a14e
...
@@ -283,7 +283,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
...
@@ -283,7 +283,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
mm
.
mDB
.
setSettings
(
key
,
Utils
.
getPrefsInt
(
prefs
,
key
));
mm
.
mDB
.
setSettings
(
key
,
Utils
.
getPrefsInt
(
prefs
,
key
));
break
;
break
;
case
Const
.
Key
.
LOCALE
:
case
Const
.
Key
.
LOCALE
:
LocaleManager
.
setLocale
();
LocaleManager
.
setLocale
(
mm
);
Topic
.
publish
(
false
,
Topic
.
RELOAD_ACTIVITY
);
Topic
.
publish
(
false
,
Topic
.
RELOAD_ACTIVITY
);
break
;
break
;
case
Const
.
Key
.
UPDATE_CHANNEL
:
case
Const
.
Key
.
UPDATE_CHANNEL
:
...
...
app/src/full/java/com/topjohnwu/magisk/SplashActivity.java
View file @
8574a14e
...
@@ -31,7 +31,7 @@ public class SplashActivity extends Activity {
...
@@ -31,7 +31,7 @@ public class SplashActivity extends Activity {
Data
.
importPrefs
();
Data
.
importPrefs
();
// Dynamic detect all locales
// Dynamic detect all locales
new
LocaleManager
.
LoadLocale
().
exec
();
LocaleManager
.
loadAvailableLocales
();
// Create notification channel on Android O
// Create notification channel on Android O
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
...
...
app/src/full/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java
View file @
8574a14e
package
com
.
topjohnwu
.
magisk
.
adapters
;
package
com
.
topjohnwu
.
magisk
.
adapters
;
import
android.content.Context
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.ApplicationInfo
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.os.AsyncTask
;
import
android.support.annotation.NonNull
;
import
android.support.v7.widget.RecyclerView
;
import
android.support.v7.widget.RecyclerView
;
import
android.text.TextUtils
;
import
android.text.TextUtils
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -13,9 +18,8 @@ import android.widget.ImageView;
...
@@ -13,9 +18,8 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.
asyncs.ParallelTask
;
import
com.topjohnwu.magisk.
utils.LocaleManager
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.magisk.utils.Topic
;
import
com.topjohnwu.superuser.Shell
;
import
com.topjohnwu.superuser.Shell
;
...
@@ -34,26 +38,63 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
...
@@ -34,26 +38,63 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
private
PackageManager
pm
;
private
PackageManager
pm
;
private
ApplicationFilter
filter
;
private
ApplicationFilter
filter
;
public
ApplicationAdapter
()
{
public
ApplicationAdapter
(
Context
context
)
{
fullList
=
showList
=
Collections
.
emptyList
();
fullList
=
showList
=
Collections
.
emptyList
();
hideList
=
Collections
.
emptyList
();
hideList
=
Collections
.
emptyList
();
filter
=
new
ApplicationFilter
();
filter
=
new
ApplicationFilter
();
pm
=
Data
.
MM
()
.
getPackageManager
();
pm
=
context
.
getPackageManager
();
new
LoadApps
().
exec
(
);
AsyncTask
.
THREAD_POOL_EXECUTOR
.
execute
(
this
::
loadApps
);
}
}
@NonNull
@Override
@Override
public
ViewHolder
onCreateViewHolder
(
ViewGroup
parent
,
int
viewType
)
{
public
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
View
mView
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
list_item_app
,
parent
,
false
);
View
v
=
LayoutInflater
.
from
(
parent
.
getContext
()).
inflate
(
R
.
layout
.
list_item_app
,
parent
,
false
);
return
new
ViewHolder
(
mView
);
return
new
ViewHolder
(
v
);
}
private
String
getLabel
(
ApplicationInfo
info
)
{
if
(
info
.
labelRes
>
0
)
{
try
{
Resources
res
=
pm
.
getResourcesForApplication
(
info
);
Configuration
config
=
new
Configuration
();
config
.
setLocale
(
LocaleManager
.
locale
);
res
.
updateConfiguration
(
config
,
res
.
getDisplayMetrics
());
return
res
.
getString
(
info
.
labelRes
);
}
catch
(
PackageManager
.
NameNotFoundException
ignored
)
{
/* Impossible */
}
}
return
info
.
loadLabel
(
pm
).
toString
();
}
private
void
loadApps
()
{
fullList
=
pm
.
getInstalledApplications
(
0
);
hideList
=
Shell
.
su
(
"magiskhide --ls"
).
exec
().
getOut
();
for
(
Iterator
<
ApplicationInfo
>
i
=
fullList
.
iterator
();
i
.
hasNext
();
)
{
ApplicationInfo
info
=
i
.
next
();
if
(
Const
.
HIDE_BLACKLIST
.
contains
(
info
.
packageName
)
||
!
info
.
enabled
)
{
i
.
remove
();
}
}
Collections
.
sort
(
fullList
,
(
a
,
b
)
->
{
boolean
ah
=
hideList
.
contains
(
a
.
packageName
);
boolean
bh
=
hideList
.
contains
(
b
.
packageName
);
if
(
ah
==
bh
)
{
return
getLabel
(
a
).
toLowerCase
().
compareTo
(
getLabel
(
b
).
toLowerCase
());
}
else
if
(
ah
)
{
return
-
1
;
}
else
{
return
1
;
}
});
Topic
.
publish
(
false
,
Topic
.
MAGISK_HIDE_DONE
);
}
}
@Override
@Override
public
void
onBindViewHolder
(
fina
l
ViewHolder
holder
,
int
position
)
{
public
void
onBindViewHolder
(
@NonNul
l
ViewHolder
holder
,
int
position
)
{
ApplicationInfo
info
=
showList
.
get
(
position
);
ApplicationInfo
info
=
showList
.
get
(
position
);
holder
.
appIcon
.
setImageDrawable
(
info
.
loadIcon
(
pm
));
holder
.
appIcon
.
setImageDrawable
(
info
.
loadIcon
(
pm
));
holder
.
appName
.
setText
(
info
.
loadLabel
(
pm
));
holder
.
appName
.
setText
(
getLabel
(
info
));
holder
.
appPackage
.
setText
(
info
.
packageName
);
holder
.
appPackage
.
setText
(
info
.
packageName
);
holder
.
checkBox
.
setOnCheckedChangeListener
(
null
);
holder
.
checkBox
.
setOnCheckedChangeListener
(
null
);
...
@@ -79,7 +120,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
...
@@ -79,7 +120,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
}
}
public
void
refresh
()
{
public
void
refresh
()
{
new
LoadApps
().
exec
(
);
AsyncTask
.
THREAD_POOL_EXECUTOR
.
execute
(
this
::
loadApps
);
}
}
static
class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
static
class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
...
@@ -109,7 +150,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
...
@@ -109,7 +150,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
showList
=
new
ArrayList
<>();
showList
=
new
ArrayList
<>();
String
filter
=
constraint
.
toString
().
toLowerCase
();
String
filter
=
constraint
.
toString
().
toLowerCase
();
for
(
ApplicationInfo
info
:
fullList
)
{
for
(
ApplicationInfo
info
:
fullList
)
{
if
(
lowercaseContains
(
info
.
loadLabel
(
pm
).
toString
(
),
filter
)
if
(
lowercaseContains
(
getLabel
(
info
),
filter
)
||
lowercaseContains
(
info
.
packageName
,
filter
))
{
||
lowercaseContains
(
info
.
packageName
,
filter
))
{
showList
.
add
(
info
);
showList
.
add
(
info
);
}
}
...
@@ -123,37 +164,4 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
...
@@ -123,37 +164,4 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
notifyDataSetChanged
();
notifyDataSetChanged
();
}
}
}
}
private
class
LoadApps
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
fullList
=
pm
.
getInstalledApplications
(
0
);
hideList
=
Shell
.
su
(
"magiskhide --ls"
).
exec
().
getOut
();
for
(
Iterator
<
ApplicationInfo
>
i
=
fullList
.
iterator
();
i
.
hasNext
();
)
{
ApplicationInfo
info
=
i
.
next
();
if
(
Const
.
HIDE_BLACKLIST
.
contains
(
info
.
packageName
)
||
!
info
.
enabled
)
{
i
.
remove
();
}
}
Collections
.
sort
(
fullList
,
(
a
,
b
)
->
{
boolean
ah
=
hideList
.
contains
(
a
.
packageName
);
boolean
bh
=
hideList
.
contains
(
b
.
packageName
);
if
(
ah
==
bh
)
{
return
a
.
loadLabel
(
pm
).
toString
().
toLowerCase
().
compareTo
(
b
.
loadLabel
(
pm
).
toString
().
toLowerCase
());
}
else
if
(
ah
)
{
return
-
1
;
}
else
{
return
1
;
}
});
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
v
)
{
Topic
.
publish
(
false
,
Topic
.
MAGISK_HIDE_DONE
);
}
}
}
}
app/src/full/java/com/topjohnwu/magisk/components/FlavorActivity.java
View file @
8574a14e
package
com
.
topjohnwu
.
magisk
.
components
;
package
com
.
topjohnwu
.
magisk
.
components
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.res.Configuration
;
import
android.content.res.Configuration
;
import
android.os.Bundle
;
import
android.os.Bundle
;
...
@@ -19,11 +20,12 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
...
@@ -19,11 +20,12 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
private
ActivityResultListener
activityResultListener
;
private
ActivityResultListener
activityResultListener
;
static
int
[]
EMPTY_INT_ARRAY
=
new
int
[
0
];
static
int
[]
EMPTY_INT_ARRAY
=
new
int
[
0
];
public
FlavorActivity
()
{
@Override
super
();
protected
void
attachBaseContext
(
Context
base
)
{
Configuration
configuration
=
new
Configuration
();
super
.
attachBaseContext
(
base
);
configuration
.
setLocale
(
LocaleManager
.
locale
);
Configuration
config
=
base
.
getResources
().
getConfiguration
();
applyOverrideConfiguration
(
configuration
);
config
.
setLocale
(
LocaleManager
.
locale
);
applyOverrideConfiguration
(
config
);
}
}
@Override
@Override
...
...
app/src/full/java/com/topjohnwu/magisk/superuser/SuReceiver.java
View file @
8574a14e
...
@@ -25,7 +25,7 @@ public class SuReceiver extends BroadcastReceiver {
...
@@ -25,7 +25,7 @@ public class SuReceiver extends BroadcastReceiver {
String
command
,
action
;
String
command
,
action
;
Policy
policy
;
Policy
policy
;
MagiskManager
mm
=
Utils
.
getMagiskManager
(
context
);
MagiskManager
mm
=
Data
.
MM
(
);
if
(
intent
==
null
)
return
;
if
(
intent
==
null
)
return
;
...
@@ -47,7 +47,7 @@ public class SuReceiver extends BroadcastReceiver {
...
@@ -47,7 +47,7 @@ public class SuReceiver extends BroadcastReceiver {
policy
=
mm
.
mDB
.
getPolicy
(
fromUid
);
policy
=
mm
.
mDB
.
getPolicy
(
fromUid
);
if
(
policy
==
null
)
{
if
(
policy
==
null
)
{
try
{
try
{
policy
=
new
Policy
(
fromUid
,
context
.
getPackageManager
());
policy
=
new
Policy
(
fromUid
,
mm
.
getPackageManager
());
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
;
return
;
...
@@ -59,20 +59,19 @@ public class SuReceiver extends BroadcastReceiver {
...
@@ -59,20 +59,19 @@ public class SuReceiver extends BroadcastReceiver {
String
message
;
String
message
;
switch
(
action
)
{
switch
(
action
)
{
case
"allow"
:
case
"allow"
:
message
=
context
.
getString
(
R
.
string
.
su_allow_toast
,
policy
.
appName
);
message
=
mm
.
getString
(
R
.
string
.
su_allow_toast
,
policy
.
appName
);
log
.
action
=
true
;
log
.
action
=
true
;
break
;
break
;
case
"deny"
:
case
"deny"
:
message
=
context
.
getString
(
R
.
string
.
su_deny_toast
,
policy
.
appName
);
message
=
mm
.
getString
(
R
.
string
.
su_deny_toast
,
policy
.
appName
);
log
.
action
=
false
;
log
.
action
=
false
;
break
;
break
;
default
:
default
:
return
;
return
;
}
}
if
(
policy
.
notification
&&
Data
.
suNotificationType
==
Const
.
Value
.
NOTIFICATION_TOAST
)
{
if
(
policy
.
notification
&&
Data
.
suNotificationType
==
Const
.
Value
.
NOTIFICATION_TOAST
)
Utils
.
toast
(
message
,
Toast
.
LENGTH_SHORT
);
Utils
.
toast
(
message
,
Toast
.
LENGTH_SHORT
);
}
if
(
mode
==
Const
.
Value
.
NOTIFY_NORMAL_LOG
&&
policy
.
logging
)
{
if
(
mode
==
Const
.
Value
.
NOTIFY_NORMAL_LOG
&&
policy
.
logging
)
{
toUid
=
intent
.
getIntExtra
(
"to.uid"
,
-
1
);
toUid
=
intent
.
getIntExtra
(
"to.uid"
,
-
1
);
...
...
app/src/full/java/com/topjohnwu/magisk/utils/LocaleManager.java
View file @
8574a14e
...
@@ -2,13 +2,13 @@ package com.topjohnwu.magisk.utils;
...
@@ -2,13 +2,13 @@ package com.topjohnwu.magisk.utils;
import
android.content.res.Configuration
;
import
android.content.res.Configuration
;
import
android.content.res.Resources
;
import
android.content.res.Resources
;
import
android.os.AsyncTask
;
import
android.support.annotation.StringRes
;
import
android.support.annotation.StringRes
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Const
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.Data
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.R
;
import
com.topjohnwu.magisk.asyncs.ParallelTask
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
...
@@ -21,14 +21,14 @@ public class LocaleManager {
...
@@ -21,14 +21,14 @@ public class LocaleManager {
public
final
static
Locale
defaultLocale
=
Locale
.
getDefault
();
public
final
static
Locale
defaultLocale
=
Locale
.
getDefault
();
public
static
List
<
Locale
>
locales
;
public
static
List
<
Locale
>
locales
;
public
static
void
setLocale
()
{
public
static
void
setLocale
(
MagiskManager
mm
)
{
MagiskManager
mm
=
Data
.
MM
();
String
localeConfig
=
mm
.
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
String
localeConfig
=
mm
.
prefs
.
getString
(
Const
.
Key
.
LOCALE
,
""
);
if
(
localeConfig
.
isEmpty
())
{
if
(
localeConfig
.
isEmpty
())
{
locale
=
defaultLocale
;
locale
=
defaultLocale
;
}
else
{
}
else
{
locale
=
Locale
.
forLanguageTag
(
localeConfig
);
locale
=
Locale
.
forLanguageTag
(
localeConfig
);
}
}
Locale
.
setDefault
(
locale
);
Resources
res
=
mm
.
getResources
();
Resources
res
=
mm
.
getResources
();
Configuration
config
=
res
.
getConfiguration
();
Configuration
config
=
res
.
getConfiguration
();
config
.
setLocale
(
locale
);
config
.
setLocale
(
locale
);
...
@@ -36,58 +36,41 @@ public class LocaleManager {
...
@@ -36,58 +36,41 @@ public class LocaleManager {
}
}
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
public
static
String
getString
(
Locale
locale
,
@StringRes
int
id
)
{
Configuration
config
=
Data
.
MM
().
getResources
().
get
Configuration
();
Configuration
config
=
new
Configuration
();
config
.
setLocale
(
locale
);
config
.
setLocale
(
locale
);
return
getString
(
config
,
id
);
}
private
static
String
getString
(
Configuration
config
,
@StringRes
int
id
)
{
return
Data
.
MM
().
createConfigurationContext
(
config
).
getString
(
id
);
return
Data
.
MM
().
createConfigurationContext
(
config
).
getString
(
id
);
}
}
private
static
List
<
Locale
>
getAvailableLocale
()
{
public
static
void
loadAvailableLocales
()
{
List
<
Locale
>
locales
=
new
ArrayList
<>();
AsyncTask
.
THREAD_POOL_EXECUTOR
.
execute
(()
->
{
HashSet
<
String
>
set
=
new
HashSet
<>();
locales
=
new
ArrayList
<>();
MagiskManager
mm
=
Data
.
MM
();
HashSet
<
String
>
set
=
new
HashSet
<>();
Locale
locale
;
Resources
res
=
Data
.
MM
().
getResources
();
Locale
locale
;
@StringRes
int
compareId
=
R
.
string
.
download_file_error
;
@StringRes
int
compareId
=
R
.
string
.
download_file_error
;
// Add default locale
// Add default locale
locales
.
add
(
Locale
.
ENGLISH
);
locales
.
add
(
Locale
.
ENGLISH
);
set
.
add
(
getString
(
Locale
.
ENGLISH
,
compareId
));
set
.
add
(
getString
(
Locale
.
ENGLISH
,
compareId
));
// Add some special locales
// Add some special locales
locales
.
add
(
Locale
.
TAIWAN
);
locales
.
add
(
Locale
.
TAIWAN
);
set
.
add
(
getString
(
Locale
.
TAIWAN
,
compareId
));
set
.
add
(
getString
(
Locale
.
TAIWAN
,
compareId
));
locale
=
new
Locale
(
"pt"
,
"BR"
);
locale
=
new
Locale
(
"pt"
,
"BR"
);
locales
.
add
(
locale
);
locales
.
add
(
locale
);
set
.
add
(
getString
(
locale
,
compareId
));
set
.
add
(
getString
(
locale
,
compareId
));
// Other locales
// Other locales
Configuration
config
=
mm
.
getResources
().
getConfiguration
();
for
(
String
s
:
res
.
getAssets
().
getLocales
())
{
for
(
String
s
:
mm
.
getAssets
().
getLocales
())
{
locale
=
Locale
.
forLanguageTag
(
s
);
locale
=
Locale
.
forLanguageTag
(
s
);
if
(
set
.
add
(
getString
(
locale
,
compareId
)))
{
config
.
setLocale
(
locale
);
locales
.
add
(
locale
);
if
(
set
.
add
(
getString
(
config
,
compareId
)))
{
}
locales
.
add
(
locale
);
}
}
}
Collections
.
sort
(
locales
,
(
a
,
b
)
->
a
.
getDisplayName
(
a
).
compareTo
(
b
.
getDisplayName
(
b
)));
return
locales
;
Collections
.
sort
(
locales
,
(
a
,
b
)
->
a
.
getDisplayName
(
a
).
compareTo
(
b
.
getDisplayName
(
b
)));
}
public
static
class
LoadLocale
extends
ParallelTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
voids
)
{
locales
=
getAvailableLocale
();
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
aVoid
)
{
Topic
.
publish
(
Topic
.
LOCAL_FETCH_DONE
);
Topic
.
publish
(
Topic
.
LOCAL_FETCH_DONE
);
}
}
);
}
}
}
}
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