Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Network
KDE Connect Android
Commits
6250b679
Commit
6250b679
authored
Feb 12, 2019
by
Albert Vaca Cintora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notifications plugin now shows as "without permission" instead of "failed"
Removed the concept of "failed" plugins
parent
b1904a69
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
41 additions
and
67 deletions
+41
-67
res/values/strings.xml
res/values/strings.xml
+0
-1
src/org/kde/kdeconnect/Device.java
src/org/kde/kdeconnect/Device.java
+8
-39
src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java
...nect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java
+8
-2
src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java
...nect/Plugins/NotificationsPlugin/NotificationsPlugin.java
+8
-2
src/org/kde/kdeconnect/Plugins/Plugin.java
src/org/kde/kdeconnect/Plugins/Plugin.java
+0
-4
src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java
...g/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java
+2
-1
src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
+2
-10
src/org/kde/kdeconnect/UserInterface/DeviceSettingsActivity.java
.../kde/kdeconnect/UserInterface/DeviceSettingsActivity.java
+1
-1
src/org/kde/kdeconnect/UserInterface/MainActivity.java
src/org/kde/kdeconnect/UserInterface/MainActivity.java
+10
-5
src/org/kde/kdeconnect/UserInterface/PluginPreference.java
src/org/kde/kdeconnect/UserInterface/PluginPreference.java
+2
-2
No files found.
res/values/strings.xml
View file @
6250b679
...
...
@@ -105,7 +105,6 @@
<string
name=
"category_connected_devices"
>
Connected devices
</string>
<string
name=
"category_not_paired_devices"
>
Available devices
</string>
<string
name=
"category_remembered_devices"
>
Remembered devices
</string>
<string
name=
"plugins_failed_to_load"
>
Plugins failed to load (tap for more info):
</string>
<string
name=
"device_menu_plugins"
>
Plugin settings
</string>
<string
name=
"device_menu_unpair"
>
Unpair
</string>
<string
name=
"device_not_reachable"
>
Paired device not reachable
</string>
...
...
src/org/kde/kdeconnect/Device.java
View file @
6250b679
...
...
@@ -83,7 +83,6 @@ public class Device implements BaseLink.PacketReceiver {
private
List
<
String
>
m_supportedPlugins
=
new
ArrayList
<>();
private
final
ConcurrentHashMap
<
String
,
Plugin
>
plugins
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentHashMap
<
String
,
Plugin
>
failedPlugins
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentHashMap
<
String
,
Plugin
>
pluginsWithoutPermissions
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentHashMap
<
String
,
Plugin
>
pluginsWithoutOptionalPermissions
=
new
ConcurrentHashMap
<>();
private
Map
<
String
,
ArrayList
<
String
>>
pluginsByIncomingInterface
=
new
HashMap
<>();
...
...
@@ -686,23 +685,12 @@ public class Device implements BaseLink.PacketReceiver {
//
public
<
T
extends
Plugin
>
T
getPlugin
(
Class
<
T
>
pluginClass
)
{
return
(
T
)
getPlugin
(
Plugin
.
getPluginKey
(
pluginClass
));
Plugin
plugin
=
getPlugin
(
Plugin
.
getPluginKey
(
pluginClass
));
return
(
T
)
plugin
;
}
public
<
T
extends
Plugin
>
T
getPlugin
(
Class
<
T
>
pluginClass
,
boolean
includeFailed
)
{
return
(
T
)
getPlugin
(
Plugin
.
getPluginKey
(
pluginClass
),
includeFailed
);
}
private
Plugin
getPlugin
(
String
pluginKey
)
{
return
getPlugin
(
pluginKey
,
false
);
}
public
Plugin
getPlugin
(
String
pluginKey
,
boolean
includeFailed
)
{
Plugin
plugin
=
plugins
.
get
(
pluginKey
);
if
(
includeFailed
&&
plugin
==
null
)
{
plugin
=
failedPlugins
.
get
(
pluginKey
);
}
return
plugin
;
public
Plugin
getPlugin
(
String
pluginKey
)
{
return
plugins
.
get
(
pluginKey
);
}
private
synchronized
boolean
addPlugin
(
final
String
pluginKey
)
{
...
...
@@ -728,8 +716,6 @@ public class Device implements BaseLink.PacketReceiver {
final
Plugin
plugin
=
PluginFactory
.
instantiatePluginForDevice
(
context
,
pluginKey
,
this
);
if
(
plugin
==
null
)
{
Log
.
e
(
"KDE/addPlugin"
,
"could not instantiate plugin: "
+
pluginKey
);
//Can't put a null
//failedPlugins.put(pluginKey, null);
return
false
;
}
...
...
@@ -744,19 +730,13 @@ public class Device implements BaseLink.PacketReceiver {
}
catch
(
Exception
e
)
{
success
=
false
;
e
.
printStackTrace
();
Log
.
e
(
"KDE/addPlugin"
,
"Exception loading plugin "
+
pluginKey
);
}
if
(
success
)
{
//Log.e("addPlugin","added " + pluginKey);
failedPlugins
.
remove
(
pluginKey
);
plugins
.
put
(
pluginKey
,
plugin
);
}
else
{
if
(!
success
)
{
Log
.
e
(
"KDE/addPlugin"
,
"plugin failed to load "
+
pluginKey
);
plugins
.
remove
(
pluginKey
);
failedPlugins
.
put
(
pluginKey
,
plugin
);
}
plugins
.
put
(
pluginKey
,
plugin
);
if
(!
plugin
.
checkRequiredPermissions
())
{
Log
.
e
(
"KDE/addPlugin"
,
"No permission "
+
pluginKey
);
plugins
.
remove
(
pluginKey
);
...
...
@@ -781,14 +761,9 @@ public class Device implements BaseLink.PacketReceiver {
private
synchronized
boolean
removePlugin
(
String
pluginKey
)
{
Plugin
plugin
=
plugins
.
remove
(
pluginKey
);
Plugin
failedPlugin
=
failedPlugins
.
remove
(
pluginKey
);
if
(
plugin
==
null
)
{
if
(
failedPlugin
==
null
)
{
//Not found
return
false
;
}
plugin
=
failedPlugin
;
return
false
;
}
try
{
...
...
@@ -814,8 +789,6 @@ public class Device implements BaseLink.PacketReceiver {
public
void
reloadPluginsFromSettings
()
{
failedPlugins
.
clear
();
HashMap
<
String
,
ArrayList
<
String
>>
newPluginsByIncomingInterface
=
new
HashMap
<>();
for
(
String
pluginKey
:
m_supportedPlugins
)
{
...
...
@@ -860,10 +833,6 @@ public class Device implements BaseLink.PacketReceiver {
return
plugins
;
}
public
ConcurrentHashMap
<
String
,
Plugin
>
getFailedPlugins
()
{
return
failedPlugins
;
}
public
ConcurrentHashMap
<
String
,
Plugin
>
getPluginsWithoutPermissions
()
{
return
pluginsWithoutPermissions
;
}
...
...
src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java
View file @
6250b679
...
...
@@ -208,7 +208,13 @@ public class MprisReceiverPlugin extends Plugin implements MediaSessionManager.O
}
@Override
public
AlertDialogFragment
getErrorDialog
()
{
public
boolean
checkRequiredPermissions
()
{
//Notifications use a different kind of permission, because it was added before the current runtime permissions model
return
hasPermission
();
}
@Override
public
AlertDialogFragment
getPermissionExplanationDialog
(
int
requestCode
)
{
return
new
StartActivityAlertDialogFragment
.
Builder
()
.
setTitle
(
R
.
string
.
pref_plugin_mpris
)
.
setMessage
(
R
.
string
.
no_permission_mprisreceiver
)
...
...
@@ -216,7 +222,7 @@ public class MprisReceiverPlugin extends Plugin implements MediaSessionManager.O
.
setNegativeButton
(
R
.
string
.
cancel
)
.
setIntentAction
(
"android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"
)
.
setStartForResult
(
true
)
.
setRequestCode
(
MainActivity
.
RESULT_NEEDS_RELOAD
)
.
setRequestCode
(
requestCode
)
.
create
();
}
...
...
src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java
View file @
6250b679
...
...
@@ -101,6 +101,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return
null
;
}
@Override
public
boolean
checkRequiredPermissions
()
{
//Notifications use a different kind of permission, because it was added before the current runtime permissions model
return
hasPermission
();
}
private
boolean
hasPermission
()
{
String
notificationListenerList
=
Settings
.
Secure
.
getString
(
context
.
getContentResolver
(),
"enabled_notification_listeners"
);
return
(
notificationListenerList
!=
null
&&
notificationListenerList
.
contains
(
context
.
getPackageName
()));
...
...
@@ -492,7 +498,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
@Override
public
AlertDialogFragment
get
ErrorDialog
(
)
{
public
AlertDialogFragment
get
PermissionExplanationDialog
(
int
requestCode
)
{
return
new
StartActivityAlertDialogFragment
.
Builder
()
.
setTitle
(
R
.
string
.
pref_plugin_notifications
)
.
setMessage
(
R
.
string
.
no_permissions
)
...
...
@@ -500,7 +506,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
.
setNegativeButton
(
R
.
string
.
cancel
)
.
setIntentAction
(
"android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"
)
.
setStartForResult
(
true
)
.
setRequestCode
(
MainActivity
.
RESULT_NEEDS_RELOAD
)
.
setRequestCode
(
requestCode
)
.
create
();
}
...
...
src/org/kde/kdeconnect/Plugins/Plugin.java
View file @
6250b679
...
...
@@ -239,10 +239,6 @@ public abstract class Plugin {
* the problem (and how to fix it, if possible) to the user.
*/
public
AlertDialogFragment
getErrorDialog
()
{
return
null
;
}
public
AlertDialogFragment
getPermissionExplanationDialog
(
int
requestCode
)
{
return
requestPermissionDialog
(
getRequiredPermissions
(),
permissionExplanation
,
requestCode
);
}
...
...
src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java
View file @
6250b679
...
...
@@ -54,6 +54,7 @@ import java.net.Inet4Address;
import
java.net.InetAddress
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.security.GeneralSecurityException
;
import
java.security.KeyPair
;
import
java.security.PrivateKey
;
import
java.security.PublicKey
;
...
...
@@ -81,7 +82,7 @@ class SimpleSftpServer {
private
final
SshServer
sshd
=
SshServer
.
setUpDefaultServer
();
void
init
(
Context
context
,
Device
device
)
throws
Exception
{
void
init
(
Context
context
,
Device
device
)
throws
GeneralSecurity
Exception
{
sshd
.
setKeyExchangeFactories
(
Arrays
.
asList
(
new
DHG14
.
Factory
(),
...
...
src/org/kde/kdeconnect/UserInterface/DeviceFragment.java
View file @
6250b679
...
...
@@ -330,22 +330,14 @@ public class DeviceFragment extends Fragment {
pluginListItems
.
add
(
new
PluginItem
(
p
,
v
->
p
.
startMainActivity
(
mActivity
)));
}
DeviceFragment
.
this
.
createPluginsList
(
device
.
getFailedPlugins
(),
R
.
string
.
plugins_failed_to_load
,
(
plugin
)
->
{
AlertDialogFragment
dialog
=
plugin
.
getErrorDialog
();
if
(
dialog
!=
null
)
{
dialog
.
show
(
getChildFragmentManager
(),
null
);
}
});
DeviceFragment
.
this
.
createPluginsList
(
device
.
getPluginsWithoutPermissions
(),
R
.
string
.
plugins_need_permission
,
(
plugin
)
->
{
AlertDialogFragment
dialog
=
plugin
.
getPermissionExplanationDialog
(
0
);
AlertDialogFragment
dialog
=
plugin
.
getPermissionExplanationDialog
(
MainActivity
.
RESULT_NEEDS_RELOAD
);
if
(
dialog
!=
null
)
{
dialog
.
show
(
getChildFragmentManager
(),
null
);
}
});
DeviceFragment
.
this
.
createPluginsList
(
device
.
getPluginsWithoutOptionalPermissions
(),
R
.
string
.
plugins_need_optional_permission
,
(
plugin
)
->
{
AlertDialogFragment
dialog
=
plugin
.
getOptionalPermissionExplanationDialog
(
0
);
AlertDialogFragment
dialog
=
plugin
.
getOptionalPermissionExplanationDialog
(
MainActivity
.
RESULT_NEEDS_RELOAD
);
if
(
dialog
!=
null
)
{
dialog
.
show
(
getChildFragmentManager
(),
null
);
...
...
src/org/kde/kdeconnect/UserInterface/DeviceSettingsActivity.java
View file @
6250b679
...
...
@@ -71,7 +71,7 @@ public class DeviceSettingsActivity
fragment
=
DeviceSettingsFragment
.
newInstance
(
deviceId
);
}
else
{
Device
device
=
BackgroundService
.
getInstance
().
getDevice
(
deviceId
);
Plugin
plugin
=
device
.
getPlugin
(
pluginKey
,
true
);
Plugin
plugin
=
device
.
getPlugin
(
pluginKey
);
fragment
=
plugin
.
getSettingsFragment
();
}
...
...
src/org/kde/kdeconnect/UserInterface/MainActivity.java
View file @
6250b679
...
...
@@ -360,15 +360,20 @@ public class MainActivity extends AppCompatActivity implements SharedPreferences
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
String
[]
permissions
,
int
[]
grantResults
)
{
boolean
grantedPermission
=
false
;
for
(
int
result
:
grantResults
)
{
if
(
result
==
PackageManager
.
PERMISSION_GRANTED
)
{
//New permission granted, reload plugins
BackgroundService
.
RunCommand
(
this
,
service
->
{
Device
device
=
service
.
getDevice
(
mCurrentDevice
);
device
.
reloadPluginsFromSettings
();
});
grantedPermission
=
true
;
break
;
}
}
if
(
grantedPermission
)
{
//New permission granted, reload plugins
BackgroundService
.
RunCommand
(
this
,
service
->
{
Device
device
=
service
.
getDevice
(
mCurrentDevice
);
device
.
reloadPluginsFromSettings
();
});
}
}
@Override
...
...
src/org/kde/kdeconnect/UserInterface/PluginPreference.java
View file @
6250b679
...
...
@@ -32,10 +32,10 @@ class PluginPreference extends CheckBoxPreference {
setIcon
(
android
.
R
.
color
.
transparent
);
setChecked
(
device
.
isPluginEnabled
(
pluginKey
));
Plugin
plugin
=
device
.
getPlugin
(
pluginKey
,
true
);
Plugin
plugin
=
device
.
getPlugin
(
pluginKey
);
if
(
info
.
hasSettings
()
&&
plugin
!=
null
)
{
this
.
listener
=
v
->
{
Plugin
plugin1
=
device
.
getPlugin
(
pluginKey
,
true
);
Plugin
plugin1
=
device
.
getPlugin
(
pluginKey
);
if
(
plugin1
!=
null
)
{
callback
.
onStartPluginSettingsFragment
(
plugin1
);
}
else
{
//Could happen if the device is not connected anymore
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment