18
18
19
19
package com.oasisfeng.nevo.decorators.wechat
20
20
21
- import android.annotation.SuppressLint
22
21
import android.app.AlertDialog
23
22
import android.content.*
24
23
import android.content.Intent.*
25
- import android.content.pm.ApplicationInfo
26
- import android.content.pm.LauncherApps
27
24
import android.content.pm.PackageManager.*
28
25
import android.net.Uri
29
26
import android.os.Bundle
30
- import android.os.Process
31
- import android.os.UserHandle
32
- import android.os.UserManager
33
27
import android.preference.Preference
34
28
import android.preference.Preference.OnPreferenceClickListener
35
29
import android.preference.PreferenceActivity
@@ -44,7 +38,7 @@ import com.oasisfeng.nevo.sdk.NevoDecoratorService
44
38
*/
45
39
class WeChatDecoratorSettingsActivity : PreferenceActivity () {
46
40
47
- override fun onCreate (savedInstanceState : Bundle ? ) {
41
+ @Deprecated( " Deprecated in Java " ) override fun onCreate (savedInstanceState : Bundle ? ) {
48
42
super .onCreate(savedInstanceState)
49
43
val manager = preferenceManager
50
44
manager.sharedPreferencesName = WeChatDecorator .PREFERENCES_NAME
@@ -77,32 +71,9 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
77
71
}
78
72
}
79
73
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
-
104
74
val context = this
105
75
(findPreference(getString(R .string.pref_compat_mode)) as android.preference.TwoStatePreference ).apply {
76
+ val isAndroidAutoAvailable = getPackageVersion(ANDROID_AUTO_PACKAGE ) >= 0
106
77
if (isAndroidAutoAvailable && Settings .Global .getInt(contentResolver, Settings .Global .DEVELOPMENT_SETTINGS_ENABLED , 0 ) != 0 ) {
107
78
CompatModeController .query(context) { checked: Boolean? -> isChecked = checked!! }
108
79
onPreferenceChangeListener = Preference .OnPreferenceChangeListener { _: Preference ? , newValue: Any ->
@@ -114,8 +85,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
114
85
}
115
86
116
87
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 )
119
89
isEnabled = isWechatInstalled
120
90
if (agentVersion >= CURRENT_AGENT_VERSION ) {
121
91
val launcherIntent = Intent (ACTION_MAIN ).addCategory(CATEGORY_LAUNCHER )
@@ -130,17 +100,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
130
100
} else {
131
101
setSummary(if (agentVersion < 0 ) R .string.pref_agent_summary else R .string.pref_agent_summary_update)
132
102
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 ))
144
104
true
145
105
}
146
106
}
@@ -169,41 +129,11 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
169
129
return null != mDummyReceiver.peekService(this , service)
170
130
}
171
131
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
-
202
132
private fun getPackageVersion (pkg : String ): Int {
203
133
return try { packageManager.getPackageInfo(pkg, 0 ).versionCode } catch (e: NameNotFoundException ) { - 1 }
204
134
}
205
135
206
- override fun onDestroy () {
136
+ @Deprecated( " Deprecated in Java " ) override fun onDestroy () {
207
137
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(mPreferencesChangeListener)
208
138
super .onDestroy()
209
139
}
@@ -225,10 +155,6 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
225
155
return true
226
156
}
227
157
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
-
232
158
private val mPreferencesChangeListener = SharedPreferences .OnSharedPreferenceChangeListener { prefs: SharedPreferences , key: String? ->
233
159
Log .d(TAG , " Settings changed, notify decorator now." )
234
160
sendBroadcast(Intent (ACTION_SETTINGS_CHANGED ).setPackage(packageName).putExtra(key, prefs.getBoolean(key, false )))
@@ -240,12 +166,7 @@ class WeChatDecoratorSettingsActivity : PreferenceActivity() {
240
166
private const val CURRENT_AGENT_VERSION = 1700
241
167
private const val NEVOLUTION_PACKAGE = " com.oasisfeng.nevo"
242
168
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"
245
169
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"
250
171
}
251
172
}
0 commit comments