Skip to content

Commit

Permalink
Explicitly specify package name in Intents related to FtpService
Browse files Browse the repository at this point in the history
Fixes FTP service related problems in Android 8.0 (possibly others too):
 * Unable to start at all, since implicit Intent broadcasts are forbidden from 8.0
 * FtpNotification stop button did not stop the FtpService

Related to TeamAmaze#1337, but may not fix it at all.
  • Loading branch information
TranceLove committed Sep 24, 2018
1 parent b28b97f commit 1320e08
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public void run() {
try {
server = serverFactory.createServer();
server.start();
sendBroadcast(new Intent(FtpService.ACTION_STARTED).putExtra(TAG_STARTED_BY_TILE, isStartedByTile));
sendBroadcast(new Intent(FtpService.ACTION_STARTED).setPackage(getPackageName()).putExtra(TAG_STARTED_BY_TILE, isStartedByTile));
} catch (Exception e) {
sendBroadcast(new Intent(FtpService.ACTION_FAILEDTOSTART));
sendBroadcast(new Intent(FtpService.ACTION_FAILEDTOSTART).setPackage(getPackageName()));
}
}

Expand All @@ -234,7 +234,7 @@ public void onDestroy() {
}
if (server != null) {
server.stop();
sendBroadcast(new Intent(FtpService.ACTION_STOPPED));
sendBroadcast(new Intent(FtpService.ACTION_STOPPED).setPackage(getPackageName()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public void onClick() {
super.onClick();

if (getQsTile().getState() == Tile.STATE_ACTIVE) {
getApplicationContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER));
getApplicationContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER).setPackage(getPackageName()));
} else {
if (FtpService.isConnectedToWifi(getApplicationContext())
|| FtpService.isConnectedToLocalNetwork(getApplicationContext())
|| FtpService.isEnabledWifiHotspot(getApplicationContext())) {
Intent i = new Intent(FtpService.ACTION_START_FTPSERVER);
Intent i = new Intent(FtpService.ACTION_START_FTPSERVER).setPackage(getPackageName());
i.putExtra(FtpService.TAG_STARTED_BY_TILE, true);
getApplicationContext().sendBroadcast(i);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ public void onReceive(Context context, Intent intent) {
* Sends a broadcast to start ftp server
*/
private void startServer() {
getContext().sendBroadcast(new Intent(FtpService.ACTION_START_FTPSERVER));
getContext().sendBroadcast(new Intent(FtpService.ACTION_START_FTPSERVER).setPackage(getContext().getPackageName()));
}

/**
* Sends a broadcast to stop ftp server
*/
private void stopServer() {
getContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER));
getContext().sendBroadcast(new Intent(FtpService.ACTION_STOP_FTPSERVER).setPackage(getContext().getPackageName()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void createNotification(Context context, boolean noStopButton) {
if (!noStopButton && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
int stopIcon = android.R.drawable.ic_menu_close_clear_cancel;
CharSequence stopText = context.getString(R.string.ftp_notif_stop_server);
Intent stopIntent = new Intent(FtpService.ACTION_STOP_FTPSERVER);
Intent stopIntent = new Intent(FtpService.ACTION_STOP_FTPSERVER).setPackage(context.getPackageName());
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0,
stopIntent, PendingIntent.FLAG_ONE_SHOT);

Expand Down

0 comments on commit 1320e08

Please sign in to comment.