Skip to content

Commit 14c807a

Browse files
committed
REMOVE: The embedded agent APK in assets, with web link used instead.
1 parent fdddeaa commit 14c807a

File tree

5 files changed

+6
-102
lines changed

5 files changed

+6
-102
lines changed

src/main/AndroidManifest.xml

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
1919
package="com.oasisfeng.nevo.decorators.wechat" android:versionCode="30000" android:versionName="3.0">
2020

21-
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
22-
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" /> <!-- WeChatDecoratorSettingsActivity (ACTION_UNINSTALL_PACKAGE) -->
23-
2421
<queries>
2522
<package android:name="com.tencent.mm" />
2623
<package android:name="com.oasisfeng.nevo" />

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

+6-85
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818

1919
package com.oasisfeng.nevo.decorators.wechat
2020

21-
import android.annotation.SuppressLint
2221
import android.app.AlertDialog
2322
import android.content.*
2423
import android.content.Intent.*
25-
import android.content.pm.ApplicationInfo
26-
import android.content.pm.LauncherApps
2724
import android.content.pm.PackageManager.*
2825
import android.net.Uri
2926
import android.os.Bundle
30-
import android.os.Process
31-
import android.os.UserHandle
32-
import android.os.UserManager
3327
import android.preference.Preference
3428
import android.preference.Preference.OnPreferenceClickListener
3529
import android.preference.PreferenceActivity
@@ -44,7 +38,7 @@ import com.oasisfeng.nevo.sdk.NevoDecoratorService
4438
*/
4539
class WeChatDecoratorSettingsActivity : PreferenceActivity() {
4640

47-
override fun onCreate(savedInstanceState: Bundle?) {
41+
@Deprecated("Deprecated in Java") override fun onCreate(savedInstanceState: Bundle?) {
4842
super.onCreate(savedInstanceState)
4943
val manager = preferenceManager
5044
manager.sharedPreferencesName = WeChatDecorator.PREFERENCES_NAME
@@ -77,32 +71,9 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
7771
}
7872
}
7973

80-
val isAndroidAutoAvailable = getPackageVersion(ANDROID_AUTO_PACKAGE) >= 0
81-
findPreference(getString(R.string.pref_extension)).apply {
82-
val profilesWithoutAndroidAuto = ArrayList<Int>()
83-
val profiles = getSystemService(UserManager::class.java)?.userProfiles ?: emptyList()
84-
val la = getSystemService(LauncherApps::class.java)
85-
if (la != null) for (profile in profiles) {
86-
if (profile == Process.myUserHandle()) continue
87-
if (la.getApplicationInfo(WECHAT_PACKAGE, profile) == null) continue
88-
if (la.getApplicationInfo(ANDROID_AUTO_PACKAGE, profile) == null)
89-
profilesWithoutAndroidAuto.add(profile.hashCode())
90-
}
91-
isEnabled = isWechatInstalled
92-
isSelectable = ! isAndroidAutoAvailable || profilesWithoutAndroidAuto.isNotEmpty()
93-
summary = when {
94-
! isAndroidAutoAvailable -> getText(R.string.pref_extension_summary)
95-
profilesWithoutAndroidAuto.isEmpty() -> getText(R.string.pref_extension_summary_installed)
96-
else -> getString(R.string.pref_extension_summary_not_cloned_in_island,
97-
if (profiles.size <= 2 /* Just one Island space */) "" else profilesWithoutAndroidAuto.toString()) }
98-
onPreferenceClickListener = when {
99-
! isAndroidAutoAvailable -> OnPreferenceClickListener { installExtension() }
100-
profilesWithoutAndroidAuto.isNotEmpty() -> OnPreferenceClickListener { showExtensionInIsland() }
101-
else -> null }
102-
}
103-
10474
val context = this
10575
(findPreference(getString(R.string.pref_compat_mode)) as android.preference.TwoStatePreference).apply {
76+
val isAndroidAutoAvailable = getPackageVersion(ANDROID_AUTO_PACKAGE) >= 0
10677
if (isAndroidAutoAvailable && Settings.Global.getInt(contentResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0) {
10778
CompatModeController.query(context) { checked: Boolean? -> isChecked = checked!! }
10879
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
@@ -114,8 +85,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
11485
}
11586

11687
findPreference(getString(R.string.pref_agent))?.apply {
117-
var agentVersion = getPackageVersion(AGENT_PACKAGE)
118-
if (agentVersion < 0) agentVersion = getPackageVersion(AGENT_LEGACY_PACKAGE)
88+
val agentVersion = getPackageVersion(AGENT_PACKAGE)
11989
isEnabled = isWechatInstalled
12090
if (agentVersion >= CURRENT_AGENT_VERSION) {
12191
val launcherIntent = Intent(ACTION_MAIN).addCategory(CATEGORY_LAUNCHER)
@@ -130,17 +100,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
130100
} else {
131101
setSummary(if (agentVersion < 0) R.string.pref_agent_summary else R.string.pref_agent_summary_update)
132102
onPreferenceClickListener = OnPreferenceClickListener {
133-
try {
134-
pm.getApplicationInfo(AGENT_LEGACY_PACKAGE, 0)
135-
} catch (ignored: NameNotFoundException) {
136-
installAssetApk("agent.apk")
137-
return@OnPreferenceClickListener true
138-
}
139-
AlertDialog.Builder(context).setMessage(R.string.prompt_uninstall_agent_first)
140-
.setPositiveButton(R.string.action_continue) { _: DialogInterface?, _: Int ->
141-
startActivity(Intent(ACTION_UNINSTALL_PACKAGE, Uri.fromParts("package", AGENT_LEGACY_PACKAGE, null))
142-
.putExtra("android.intent.extra.UNINSTALL_ALL_USERS", true))
143-
}.show()
103+
startActivity(Intent(ACTION_VIEW, Uri.parse(AGENT_URL)).addFlags(FLAG_ACTIVITY_NEW_TASK))
144104
true
145105
}
146106
}
@@ -169,41 +129,11 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
169129
return null != mDummyReceiver.peekService(this, service)
170130
}
171131

172-
private fun installExtension() = true.also {
173-
if (isPlayStoreSystemApp()) {
174-
AlertDialog.Builder(this).setMessage(R.string.prompt_extension_install)
175-
.setPositiveButton(R.string.action_install_android_auto) { _: DialogInterface, _: Int -> showAndroidAutoInPlayStore() }
176-
.setNeutralButton(R.string.action_install_dummy_auto) { _: DialogInterface, _: Int -> installDummyAuto() }
177-
.show()
178-
} else installDummyAuto()
179-
}
180-
181-
@SuppressLint("InlinedApi") private fun showExtensionInIsland() = true.also { try {
182-
startActivity(Intent(ACTION_SHOW_APP_INFO).putExtra(EXTRA_PACKAGE_NAME, ANDROID_AUTO_PACKAGE).setPackage(ISLAND_PACKAGE))
183-
} catch (e: Exception) {}}
184-
185-
private fun showAndroidAutoInPlayStore() {
186-
val uri = Uri.parse("https://play.google.com/store/apps/details?id=$ANDROID_AUTO_PACKAGE")
187-
try { startActivity(Intent(ACTION_VIEW, uri).setPackage(PLAY_STORE_PACKAGE).addFlags(FLAG_ACTIVITY_NEW_TASK)) }
188-
catch (e: ActivityNotFoundException) { /* In case of Google Play malfunction */ }
189-
}
190-
191-
private fun installDummyAuto() {
192-
installAssetApk("dummy-auto.apk")
193-
}
194-
195-
private fun installAssetApk(asset_name: String) {
196-
val authority = packageManager.getProviderInfo(ComponentName(this, AssetFileProvider::class.java), 0).authority
197-
val uri = Uri.parse("content://$authority/$asset_name")
198-
try { startActivity(Intent(ACTION_INSTALL_PACKAGE, uri).addFlags(FLAG_GRANT_READ_URI_PERMISSION)) }
199-
catch (e: ActivityNotFoundException) {}
200-
}
201-
202132
private fun getPackageVersion(pkg: String): Int {
203133
return try { packageManager.getPackageInfo(pkg, 0).versionCode } catch (e: NameNotFoundException) { -1 }
204134
}
205135

206-
override fun onDestroy() {
136+
@Deprecated("Deprecated in Java") override fun onDestroy() {
207137
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(mPreferencesChangeListener)
208138
super.onDestroy()
209139
}
@@ -225,10 +155,6 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
225155
return true
226156
}
227157

228-
private fun isPlayStoreSystemApp(): Boolean =
229-
try { packageManager.getApplicationInfo(PLAY_STORE_PACKAGE, 0).flags and ApplicationInfo.FLAG_SYSTEM != 0 }
230-
catch (e: NameNotFoundException) { false }
231-
232158
private val mPreferencesChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { prefs: SharedPreferences, key: String? ->
233159
Log.d(TAG, "Settings changed, notify decorator now.")
234160
sendBroadcast(Intent(ACTION_SETTINGS_CHANGED).setPackage(packageName).putExtra(key, prefs.getBoolean(key, false)))
@@ -240,12 +166,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
240166
private const val CURRENT_AGENT_VERSION = 1700
241167
private const val NEVOLUTION_PACKAGE = "com.oasisfeng.nevo"
242168
private const val ANDROID_AUTO_PACKAGE = "com.google.android.projection.gearhead"
243-
private const val PLAY_STORE_PACKAGE = "com.android.vending"
244-
private const val ISLAND_PACKAGE = "com.oasisfeng.island"
245169
private const val APP_MARKET_PREFIX = "market://details?id="
246-
private const val AGENT_LEGACY_PACKAGE = "com.oasisfeng.nevo.agents.wechat"
247-
248-
@SuppressLint("NewApi") private fun LauncherApps.getApplicationInfo(pkg: String, profile: UserHandle) =
249-
try { getApplicationInfo(pkg, 0, profile) } catch (e: NameNotFoundException) { null }
170+
private const val AGENT_URL = "https://github.com/Nevolution/decorator-wechat/releases"
250171
}
251172
}

src/main/res/values/strings.xml

-8
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@
3636
<string name="pref_activate_summary_wechat_not_installed">“微信”未安装</string>
3737
<string name="pref_activate_summary_nevo_not_installed">“女娲石”尚未安装</string>
3838
<string name="pref_activate_summary_already_activated">已启用</string>
39-
<string name="pref_extension_title">特性扩展包</string>
40-
<string name="pref_extension_summary">添加更多特性(快捷回复、划掉标记已读 等)</string>
41-
<string name="pref_extension_summary_installed">已安装</string>
42-
<string name="pref_extension_summary_not_cloned_in_island">壶中界%s 内未克隆</string>
43-
<string name="prompt_extension_install">你有两个选项:安装完整版的 Android Auto(消耗较多空间),或者“极简包”。如果你不需要使用 Android Auto 或者不清楚它是什么,建议选择“极简包”。</string>
44-
<string name="action_install_android_auto">安装 Android Auto</string>
45-
<string name="action_install_dummy_auto">安装极简包</string>
4639
<string name="pref_compat_mode_title">兼容模式 (试验性)</string>
4740
<string name="pref_compat_mode_summary">强制设备全局进入兼容模式,其影响与具体设备有关。(例如 “息屏显示” 或 “双击唤醒” 无法工作)\n最新版本微信需要这个模式才能启用特性扩展包。</string>
4841
<string name="pref_agent_title">体验增强包</string>
@@ -60,6 +53,5 @@
6053
<string name="pref_wear_summary">同步通知至 Wear OS 设备。(如果设备上安装有微信 Wear 版,请勿开启)</string>
6154
<string name="pref_open_source_title">开源项目</string>
6255
<string name="pref_open_source_summary">欢迎来 GitHub 上访问我们</string>
63-
<string name="prompt_uninstall_agent_first">安装新版本前,须先卸载当前安装的微信替身版本。(尽管将提示卸载“微信”,实际卸载的只是微信替身,您的微信应用及数据不会受到任何影响)</string>
6456
<string name="action_continue">继续</string>
6557
</resources>

src/main/res/values/values.xml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<integer name="repacked_asset_offset">0</integer>
1111

1212
<string name="pref_activate" translatable="false">activate</string>
13-
<string name="pref_extension" translatable="false">extension</string>
1413
<string name="pref_compat_mode" translatable="false">compat</string>
1514
<string name="pref_agent" translatable="false">agent</string>
1615
<string name="pref_wear" translatable="false">wear</string>

src/main/res/xml/decorators_wechat_settings.xml

-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
android:title="@string/pref_activate_title"
88
tools:summary="@string/pref_activate_summary_already_activated" />
99

10-
<Preference
11-
android:key="@string/pref_extension"
12-
android:title="@string/pref_extension_title"
13-
tools:summary="@string/pref_extension_summary" />
14-
1510
<SwitchPreference
1611
android:key="@string/pref_compat_mode"
1712
android:title="@string/pref_compat_mode_title"

0 commit comments

Comments
 (0)