2222import android .preference .Preference ;
2323import android .preference .PreferenceActivity ;
2424import android .preference .PreferenceManager ;
25+ import android .preference .TwoStatePreference ;
26+ import android .provider .Settings ;
2527import android .util .Log ;
2628
2729import androidx .annotation .Nullable ;
@@ -111,6 +113,16 @@ public class WeChatDecoratorSettingsActivity extends PreferenceActivity {
111113 preference_extension .setOnPreferenceClickListener (! android_auto_available ? this ::installExtension
112114 : ! android_auto_unavailable_in_profiles .isEmpty () ? this ::showExtensionInIsland : null );
113115
116+ final TwoStatePreference preference_compat_mode = (TwoStatePreference ) findPreference (getString (R .string .pref_compat_mode ));
117+ if (android_auto_available && Settings .Global .getInt (getContentResolver (), Settings .Global .DEVELOPMENT_SETTINGS_ENABLED , 0 ) != 0 ) {
118+ CompatModeController .query (this , preference_compat_mode ::setChecked );
119+ preference_compat_mode .setOnPreferenceChangeListener ((preference , newValue ) -> {
120+ final boolean enabled = (Boolean ) newValue ;
121+ CompatModeController .request (this , enabled , changed -> { if (changed ) preference_compat_mode .setChecked (enabled ); });
122+ return false ; // Will be updated by the callback in previous line.
123+ });
124+ } else getPreferenceScreen ().removePreference (preference_compat_mode );
125+
114126 final Preference preference_agent = findPreference (getString (R .string .pref_agent ));
115127 int agent_version = getPackageVersion (WeChatDecorator .AGENT_PACKAGE );
116128 if (agent_version < 0 ) agent_version = getPackageVersion (AGENT_LEGACY_PACKAGE );
@@ -160,23 +172,12 @@ private boolean selectAgentLabel() {
160172 return true ;
161173 }
162174
163- private boolean toggleHidingLauncherIcon (@ SuppressWarnings ("unused" ) final Preference unused , final Object value ) {
164- final boolean start_from_launcher = getIntent ().getAction () != null ;
165- if (start_from_launcher && value == Boolean .TRUE ) {
166- new AlertDialog .Builder (this ).setMessage (R .string .prompt_hide_prerequisite ).setPositiveButton (android .R .string .cancel , null ).show ();
167- return false ;
168- }
169- getPackageManager ().setComponentEnabledSetting (new ComponentName (this , getClass ()),
170- value != Boolean .TRUE ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED , DONT_KILL_APP );
171- return true ;
172- }
173-
174175 private boolean isDecoratorRunning () {
175176 final Intent service = new Intent (this , WeChatDecorator .class ).setAction (NevoDecoratorService .ACTION_DECORATOR_SERVICE );
176177 return mDummyReceiver .peekService (this , service ) != null ;
177178 }
178179
179- private boolean installExtension (@ SuppressWarnings ( "unused" ) final Preference unused ) {
180+ private boolean installExtension (final Preference unused ) {
180181 if (isPlayStoreSystemApp ()) {
181182 new AlertDialog .Builder (this ).setMessage (R .string .prompt_extension_install )
182183 .setPositiveButton (R .string .action_install_android_auto , (d , c ) -> showAndroidAutoInPlayStore ())
@@ -185,7 +186,7 @@ private boolean installExtension(@SuppressWarnings("unused") final Preference un
185186 return true ;
186187 }
187188
188- @ SuppressLint ("InlinedApi" ) private boolean showExtensionInIsland (@ SuppressWarnings ( "unused" ) final Preference unused ) {
189+ @ SuppressLint ("InlinedApi" ) private boolean showExtensionInIsland (final Preference unused ) {
189190 try {
190191 startActivity (new Intent (Intent .ACTION_SHOW_APP_INFO ).putExtra (Intent .EXTRA_PACKAGE_NAME , ANDROID_AUTO_PACKAGE ).setPackage (ISLAND_PACKAGE ));
191192 } catch (final Exception ignored ) {}
@@ -230,14 +231,14 @@ private static ApplicationInfo getApplicationInfo(final LauncherApps la, final S
230231 super .onDestroy ();
231232 }
232233
233- private boolean installNevolution (final @ SuppressWarnings ( "unused" ) Preference preference ) {
234+ private boolean installNevolution (final Preference preference ) {
234235 try {
235236 startActivity (new Intent (Intent .ACTION_VIEW , Uri .parse (APP_MARKET_PREFIX + NEVOLUTION_PACKAGE )));
236237 } catch (final ActivityNotFoundException ignored ) {} // TODO: Landing web page
237238 return true ;
238239 }
239240
240- private boolean activate (final @ SuppressWarnings ( "unused" ) Preference preference ) {
241+ private boolean activate (final Preference preference ) {
241242 try {
242243 startActivityForResult (new Intent ("com.oasisfeng.nevo.action.ACTIVATE_DECORATOR" ).setPackage (NEVOLUTION_PACKAGE )
243244 .putExtra ("nevo.decorator" , new ComponentName (this , WeChatDecorator .class ))
0 commit comments