Commit bbf52c4f authored by Mygod's avatar Mygod

Add support for notification channels for O preview

parent 0acfaa12
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
<string name="udp_dns_summary">Forward all DNS requests to remote</string> <string name="udp_dns_summary">Forward all DNS requests to remote</string>
<!-- notification category --> <!-- notification category -->
<string name="service">Service</string>
<string name="forward_success">Shadowsocks started.</string> <string name="forward_success">Shadowsocks started.</string>
<string name="invalid_server">Invalid server name</string> <string name="invalid_server">Invalid server name</string>
<string name="service_failed">Failed to connect the remote server</string> <string name="service_failed">Failed to connect the remote server</string>
......
...@@ -24,11 +24,12 @@ import java.io.{File, FileOutputStream, IOException} ...@@ -24,11 +24,12 @@ import java.io.{File, FileOutputStream, IOException}
import java.util.Locale import java.util.Locale
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application import android.app.{Application, NotificationChannel, NotificationManager}
import android.content._ import android.content._
import android.content.res.Configuration import android.content.res.Configuration
import android.os.{Build, LocaleList} import android.os.{Build, LocaleList}
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v4.os.BuildCompat
import android.support.v7.app.AppCompatDelegate import android.support.v7.app.AppCompatDelegate
import android.util.Log import android.util.Log
import com.evernote.android.job.JobManager import com.evernote.android.job.JobManager
...@@ -154,6 +155,9 @@ class ShadowsocksApplication extends Application { ...@@ -154,6 +155,9 @@ class ShadowsocksApplication extends Application {
JobManager.create(this).addJobCreator(DonaldTrump) JobManager.create(this).addJobCreator(DonaldTrump)
TcpFastOpen.enabled(settings.getBoolean(Key.tfo, TcpFastOpen.sendEnabled)) TcpFastOpen.enabled(settings.getBoolean(Key.tfo, TcpFastOpen.sendEnabled))
if (BuildCompat.isAtLeastO) getSystemService(classOf[NotificationManager]).createNotificationChannel(
new NotificationChannel("service", getText(R.string.service), NotificationManager.IMPORTANCE_MIN))
} }
def crashRecovery() { def crashRecovery() {
......
...@@ -28,6 +28,7 @@ import android.os.{Build, PowerManager} ...@@ -28,6 +28,7 @@ import android.os.{Build, PowerManager}
import android.support.v4.app.NotificationCompat import android.support.v4.app.NotificationCompat
import android.support.v4.app.NotificationCompat.BigTextStyle import android.support.v4.app.NotificationCompat.BigTextStyle
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.support.v4.os.BuildCompat
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub import com.github.shadowsocks.aidl.IShadowsocksServiceCallback.Stub
import com.github.shadowsocks.utils.{Action, State, TrafficMonitor, Utils} import com.github.shadowsocks.utils.{Action, State, TrafficMonitor, Utils}
...@@ -60,6 +61,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str ...@@ -60,6 +61,7 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
.setContentIntent(PendingIntent.getActivity(service, 0, new Intent(service, classOf[MainActivity]) .setContentIntent(PendingIntent.getActivity(service, 0, new Intent(service, classOf[MainActivity])
.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0)) .setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0))
.setSmallIcon(R.drawable.ic_stat_shadowsocks) .setSmallIcon(R.drawable.ic_stat_shadowsocks)
.setChannel("service")
if (Build.VERSION.SDK_INT < 24) builder.addAction(R.drawable.ic_navigation_close, if (Build.VERSION.SDK_INT < 24) builder.addAction(R.drawable.ic_navigation_close,
service.getString(R.string.stop), PendingIntent.getBroadcast(service, 0, new Intent(Action.CLOSE), 0)) service.getString(R.string.stop), PendingIntent.getBroadcast(service, 0, new Intent(Action.CLOSE), 0))
private lazy val style = new BigTextStyle(builder) private lazy val style = new BigTextStyle(builder)
...@@ -97,7 +99,9 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str ...@@ -97,7 +99,9 @@ class ShadowsocksNotification(private val service: BaseService, profileName: Str
show() show()
} else if (forceShow) show() } else if (forceShow) show()
def show(): Unit = service.startForeground(1, builder.build) def show(): Unit =
if (BuildCompat.isAtLeastO) nm.startServiceInForeground(new Intent(service, service.getClass), 1, builder.build())
else service.startForeground(1, builder.build)
def destroy() { def destroy() {
if (lockReceiver != null) { if (lockReceiver != null) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment