Skip to content

Commit 646b8bc

Browse files
committed
ADD: Compatibility mode to bring back functionality of extension pack.
1 parent 2fd11a7 commit 646b8bc

File tree

6 files changed

+59
-15
lines changed

6 files changed

+59
-15
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ android {
3535
noCompress "apk"
3636
}
3737

38+
kotlinOptions.jvmTarget = "1.8"
39+
3840
compileOptions {
3941
sourceCompatibility JavaVersion.VERSION_1_8
4042
targetCompatibility JavaVersion.VERSION_1_8
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.oasisfeng.nevo.decorators.wechat
2+
3+
import android.app.Activity
4+
import android.content.BroadcastReceiver
5+
import android.content.Context
6+
import android.content.Intent
7+
import android.net.Uri
8+
import android.os.Handler
9+
import android.os.Looper
10+
import android.util.Log
11+
import androidx.core.util.Consumer
12+
13+
object CompatModeController {
14+
15+
@JvmStatic fun query(context: Context, result_callback: (Consumer<Boolean>)?) {
16+
sendRequest(context, null, result_callback)
17+
}
18+
19+
@JvmStatic fun request(context: Context, enabled: Boolean, result_callback: (Consumer<Boolean>)?) {
20+
sendRequest(context, enabled, result_callback)
21+
}
22+
23+
private fun sendRequest(context: Context, enabled: Boolean?, callback: (Consumer<Boolean>)?) {
24+
val uri = Uri.fromParts("nevo", "compat", if (enabled == null) null else if (enabled) "1" else "0")
25+
context.sendOrderedBroadcast(Intent("", uri), null, object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) {
26+
when (resultCode) {
27+
Activity.RESULT_FIRST_USER -> callback?.accept(true) // Changed (for request) or enabled (for query)
28+
Activity.RESULT_OK -> callback?.accept(false) // Unchanged
29+
else -> Log.e(WeChatDecorator.TAG, "Unexpected result code: $resultCode") }
30+
}}, Handler(Looper.getMainLooper()), Activity.RESULT_CANCELED, null, null)
31+
}
32+
}

src/main/java/com/oasisfeng/nevo/decorators/wechat/WeChatDecoratorSettingsActivity.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import android.preference.Preference;
2323
import android.preference.PreferenceActivity;
2424
import android.preference.PreferenceManager;
25+
import android.preference.TwoStatePreference;
26+
import android.provider.Settings;
2527
import android.util.Log;
2628

2729
import 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))

src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
<string name="prompt_extension_install">你有两个选项:安装完整版的 Android Auto(消耗较多空间),或者“极简包”。如果你不需要使用 Android Auto 或者不清楚它是什么,建议选择“极简包”。</string>
4545
<string name="action_install_android_auto">安装 Android Auto</string>
4646
<string name="action_install_dummy_auto">安装极简包</string>
47+
<string name="pref_compat_mode_title">兼容模式 (试验性)</string>
48+
<string name="pref_compat_mode_summary">强制设备全局进入兼容模式,其影响与具体设备有关。(例如 “息屏显示” 或 “双击唤醒” 无法工作)\n最新版本微信需要这个模式才能启用特性扩展包。</string>
4749
<string name="pref_agent_title">体验增强包</string>
4850
<string name="pref_agent_summary">通过安装一个微信的替身,可消除女娲石在外源模式下的微信通知前缀,支持通知圆点(需启动器支持),并提供“扫码”的快捷方式。</string>
4951
<string name="pref_agent_summary_prefix_enabled">已启用</string>

src/main/res/values/values.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<string name="pref_activate" translatable="false">activate</string>
1313
<string name="pref_extension" translatable="false">extension</string>
14+
<string name="pref_compat_mode" translatable="false">compat</string>
1415
<string name="pref_agent" translatable="false">agent</string>
1516
<string name="pref_wear" translatable="false">wear</string>
1617
</resources>

src/main/res/xml/decorators_wechat_settings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
android:title="@string/pref_extension_title"
1313
tools:summary="@string/pref_extension_summary" />
1414

15+
<SwitchPreference
16+
android:key="@string/pref_compat_mode"
17+
android:title="@string/pref_compat_mode_title"
18+
android:summary="@string/pref_compat_mode_summary"
19+
android:persistent="false" />
20+
1521
<Preference
1622
android:key="@string/pref_agent"
1723
android:title="@string/pref_agent_title"

0 commit comments

Comments
 (0)