Fix content provider
This commit is contained in:
@@ -93,7 +93,7 @@ class ProfileConfigFragment extends PreferenceFragment with OnMenuItemClickListe
|
||||
false
|
||||
})
|
||||
initPlugins()
|
||||
app.listenForPackageChanges(getView.post(initPlugins))
|
||||
app.listenForPackageChanges(if (getView != null) getView.post(initPlugins))
|
||||
app.settings.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.github.shadowsocks.plugin
|
||||
|
||||
import android.content.pm.{PackageManager, ResolveInfo}
|
||||
import android.content.pm.{PackageManager, ProviderInfo}
|
||||
|
||||
/**
|
||||
* @author Mygod
|
||||
*/
|
||||
class NativePlugin(resolveInfo: ResolveInfo, packageManager: PackageManager)
|
||||
extends ResolvedPlugin(resolveInfo, packageManager) {
|
||||
assert(resolveInfo.providerInfo != null)
|
||||
assert(resolveInfo.providerInfo.authority.startsWith(PluginInterface.AUTHORITY_BASE))
|
||||
class NativePlugin(providerInfo: ProviderInfo, packageManager: PackageManager)
|
||||
extends ResolvedPlugin(providerInfo, packageManager) {
|
||||
assert(providerInfo != null)
|
||||
assert(providerInfo.authority.startsWith(PluginInterface.AUTHORITY_BASE))
|
||||
override final lazy val id: String =
|
||||
resolveInfo.providerInfo.authority.substring(PluginInterface.AUTHORITY_BASE.length)
|
||||
providerInfo.authority.substring(PluginInterface.AUTHORITY_BASE.length)
|
||||
override final lazy val defaultConfig: String =
|
||||
resolveInfo.providerInfo.metaData.getString(PluginInterface.METADATA_KEY_DEFAULT_CONFIG)
|
||||
providerInfo.metaData.getString(PluginInterface.METADATA_KEY_DEFAULT_CONFIG)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.{File, FileNotFoundException, FileOutputStream, IOException}
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.{BroadcastReceiver, ContentResolver, Intent}
|
||||
import android.net.Uri
|
||||
import android.text.TextUtils
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.utils.CloseUtils.autoClose
|
||||
import com.github.shadowsocks.utils.IOUtils
|
||||
@@ -22,8 +23,10 @@ object PluginManager {
|
||||
synchronized(if (cachedPlugins == null) {
|
||||
val pm = app.getPackageManager
|
||||
cachedPlugins = (NoPlugin +:
|
||||
pm.queryIntentContentProviders(new Intent().addCategory(PluginInterface.CATEGORY_NATIVE_PLUGIN),
|
||||
PackageManager.GET_META_DATA).asScala.map(new NativePlugin(_, pm))).toArray
|
||||
pm.queryContentProviders(null, 0, PackageManager.GET_META_DATA).asScala
|
||||
.filter(_ != null)
|
||||
.filter(_.authority.startsWith(PluginInterface.AUTHORITY_BASE))
|
||||
.map(new NativePlugin(_, pm))).toArray
|
||||
})
|
||||
cachedPlugins
|
||||
}
|
||||
@@ -31,7 +34,7 @@ object PluginManager {
|
||||
// the following parts are meant to be used by :bg
|
||||
@throws[Throwable]
|
||||
def initPlugin(id: String): String = {
|
||||
if (id.isEmpty) return null
|
||||
if (TextUtils.isEmpty(id)) return null
|
||||
var throwable: Throwable = null
|
||||
|
||||
try initNativePlugin(id) match {
|
||||
@@ -62,7 +65,11 @@ object PluginManager {
|
||||
var initialized = false
|
||||
val pluginDir = new File(app.getFilesDir, "plugin")
|
||||
if (cursor.moveToFirst()) {
|
||||
IOUtils.deleteRecursively(pluginDir)
|
||||
try {
|
||||
IOUtils.deleteRecursively(pluginDir)
|
||||
} catch {
|
||||
case ex: IOException => // Ignore
|
||||
}
|
||||
if (!pluginDir.mkdirs()) throw new FileNotFoundException("Unable to create plugin directory")
|
||||
val pluginDirPath = pluginDir.getAbsolutePath + '/'
|
||||
do {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.github.shadowsocks.plugin
|
||||
|
||||
import android.content.pm.{PackageManager, ProviderInfo}
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
|
||||
/**
|
||||
* Base class for any kind of plugin that can be used.
|
||||
*
|
||||
* @author Mygod
|
||||
*/
|
||||
abstract class ResolvedPlugin(providerInfo: ProviderInfo, packageManager: PackageManager = app.getPackageManager)
|
||||
extends Plugin {
|
||||
override final lazy val label: CharSequence = packageManager.getApplicationLabel(providerInfo.applicationInfo)
|
||||
override final lazy val icon: Drawable = packageManager.getApplicationIcon(providerInfo.applicationInfo)
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.github.shadowsocks.plugin
|
||||
|
||||
import android.content.pm.{PackageManager, ResolveInfo}
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
|
||||
/**
|
||||
* Base class for any kind of plugin that can be used.
|
||||
*
|
||||
* @author Mygod
|
||||
*/
|
||||
abstract class ResolvedPlugin(resolveInfo: ResolveInfo, packageManager: PackageManager = app.getPackageManager)
|
||||
extends Plugin {
|
||||
override final lazy val label: CharSequence = resolveInfo.loadLabel(packageManager)
|
||||
override final lazy val icon: Drawable = resolveInfo.loadIcon(packageManager)
|
||||
}
|
||||
+1
-1
@@ -39,7 +39,7 @@ class PluginConfigurationDialogFragment extends EditTextPreferenceDialogFragment
|
||||
override def onPrepareDialogBuilder(builder: AlertDialog.Builder) {
|
||||
super.onPrepareDialogBuilder(builder)
|
||||
val intent = new Intent(PluginInterface.ACTION_HELP(getArguments.getString(PLUGIN_ID_FRAGMENT_TAG)))
|
||||
if (intent.resolveActivity(getContext.getPackageManager) != null) builder.setNeutralButton("?", ((_, _) =>
|
||||
if (intent.resolveActivity(getActivity.getPackageManager) != null) builder.setNeutralButton("?", ((_, _) =>
|
||||
startActivityForResult(intent.putExtra(PluginInterface.EXTRA_OPTIONS, editText.getText.toString),
|
||||
REQUEST_CODE_HELP)): DialogInterface.OnClickListener)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user